Bonbin
Bonbin

Reputation: 305

configure SFML for clion (windows)

i am setting up a work environment for a school project on my windows computer. We are going to make a basic game using c++ and CLion. To make a game i need to use the SFML library. I have followed a few tutorials but i cant seem to get it to work anyway.

I have:

cmake_minimum_required(VERSION 3.6)
project(testet)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)

add_executable(testet ${SOURCE_FILES})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(testet ${SFML_LIBRARIES})
endif()

These are the three steps that i see on every tutorial / answer. But I get the following error anyway:

"C:\Program Files (x86)\JetBrains\CLion 2016.3\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Benjamin\ClionProjects\testet
CMake Error at cmake_modules/FindSFML.cmake:355 (message):
Could NOT find SFML (missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY
SFML_GRAPHICS_LIBRARY SFML_NETWORK_LIBRARY SFML_AUDIO_LIBRARY)
Call Stack (most recent call first):
CMakeLists.txt:10 (find_package)

So it cant find the SFML? But should'nt the "findSFML.cmake" solve this? Any help is appretiated... Thanks! :D

Upvotes: 3

Views: 14631

Answers (3)

pumelkopf
pumelkopf

Reputation: 1

my fix was, that I had to change the root path of SFML in the FindSFML.cmake

so just set(SFML_ROOT Z://your_project) after the block of comments and you are ready to go

Upvotes: 0

Mr. Suryaa Jha
Mr. Suryaa Jha

Reputation: 1582

I have successfully configured SFML with CLion on Ubuntu 16.04 and I think it will be same for Window user also.

My project name is SFML_TEST so change every occurrence of SFML_TEST with your project name.

  1. Create a new Clion C++ Project.
  2. Navigate to /path/to/CLionProjects/[Project_Name]/CMakeLists.txt
  3. After the following statement

    add_executable(SFML_TEST ${SOURCE_FILES})
    

    Add following lines of code

    set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
    find_package(SFML REQUIRED system window graphics network audio)
    if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(SFML_TEST ${SFML_LIBRARIES})
    endif()
    
  4. Create a new directory /path/to/CLionProjects/[project_name]/cmake_modules/FindSFML.cmake

  5. In FindSFML.cmake file paste the following line of code from the given file https://github.com/SFML/SFML/blob/master/cmake/Modules/FindSFML.cmake
  6. Done!!!.. Happy Coding

Upvotes: 1

CodeLikeBeaker
CodeLikeBeaker

Reputation: 21312

I believe you are missing the link_directories() call. You can use it like this:

link_directories("C:/Path_To_Library")

This should help solve your issue.

Upvotes: 2

Related Questions