1
General / SFML 2.5 CMake configuration
« on: January 04, 2020, 09:30:38 pm »
Hi, I am new to both SFML and CMake and have been struggling for some time to build SFML with CMake for version 2.50+, even after reading several tutorials as well as this forum post. I want to be able to build SFML with CLion (which just uses CMake).
I tried following the tutorial provided at https://www.sfml-dev.org/tutorials/2.5/compile-with-cmake.php, but it wasn't clear what I would download if I wanted to use pure CMake. Would I download one of the MinGW versions or the source code itself?
Ideally, I would like to just place the SFML source code directly in my project and build it alongside my project, but I don't know if that's possible and haven't been able to get it to work. Am I forced to build SFML outside my project and then link (either statically or dynamically) the resulting object files?
Right now I have a root directory with main.cpp (containing some barebones code to open a window using SFML), as well as my CMakeLists.txt file with the following code:
I have attached a screenshot of my directory structure, if it helps.
CMake is able to run without encountering errors, but my project itself can't run, and fails with the following errors:
If I try to build the way that this forum post specifies (assume, once again, that I've downloaded the SFML source code and that it's in the SFML directory), then I get the following error:
In the SFML source code download, there wasn't a file anywhere called SFMLConfig.cmake or sfml-config.cmake. Then again, I'm not sure if I should be using the source code if I want to build with pure CMake.
What do I have to do to build from scratch with CMake?
EDIT 1: I have made some progress. In the CMake I posted above, I had to replace target_link_libraries(sfmltest3 SFML) with target_link_libraries(sfmltest3 sfml-main sfml-system sfml-window sfml-graphics sfml-audio). Everything now works except that when I try to run the program, I get a message that says "Process finished with exit code -1073741515". In other words, I get a runtime error. When attempting to run the executable from commandline rather than an IDE, I get the message "The code execution cannot proceed because sfml-window-d-2.dll was not found."
EDIT 2: Everything is now working. I had to add set(BUILD_SHARED_LIBS FALSE) to my CMakeLists.txt file.
I tried following the tutorial provided at https://www.sfml-dev.org/tutorials/2.5/compile-with-cmake.php, but it wasn't clear what I would download if I wanted to use pure CMake. Would I download one of the MinGW versions or the source code itself?
Ideally, I would like to just place the SFML source code directly in my project and build it alongside my project, but I don't know if that's possible and haven't been able to get it to work. Am I forced to build SFML outside my project and then link (either statically or dynamically) the resulting object files?
Right now I have a root directory with main.cpp (containing some barebones code to open a window using SFML), as well as my CMakeLists.txt file with the following code:
Code: [Select]
cmake_minimum_required(VERSION 3.15)
project(sfmltest3)
set(CMAKE_CXX_STANDARD 17)
add_executable(sfmltest3 main.cpp)
add_subdirectory(SFML)
include_directories(SFML/include)
target_link_libraries(sfmltest3 SFML)
I have attached a screenshot of my directory structure, if it helps.
CMake is able to run without encountering errors, but my project itself can't run, and fails with the following errors:
Code: [Select]
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lSFML
collect2.exe: error: ld returned 1 exit status
If I try to build the way that this forum post specifies (assume, once again, that I've downloaded the SFML source code and that it's in the SFML directory), then I get the following error:
Code: [Select]
CMake Error at CMakeLists.txt:22 (find_package):
By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SFML", but
CMake did not find one.
Could not find a package configuration file provided by "SFML" (requested
version 2.5) with any of the following names:
SFMLConfig.cmake
sfml-config.cmake
Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
"SFML_DIR" to a directory containing one of the above files. If "SFML"
provides a separate development package or SDK, be sure it has been
installed.
In the SFML source code download, there wasn't a file anywhere called SFMLConfig.cmake or sfml-config.cmake. Then again, I'm not sure if I should be using the source code if I want to build with pure CMake.
What do I have to do to build from scratch with CMake?
EDIT 1: I have made some progress. In the CMake I posted above, I had to replace target_link_libraries(sfmltest3 SFML) with target_link_libraries(sfmltest3 sfml-main sfml-system sfml-window sfml-graphics sfml-audio). Everything now works except that when I try to run the program, I get a message that says "Process finished with exit code -1073741515". In other words, I get a runtime error. When attempting to run the executable from commandline rather than an IDE, I get the message "The code execution cannot proceed because sfml-window-d-2.dll was not found."
EDIT 2: Everything is now working. I had to add set(BUILD_SHARED_LIBS FALSE) to my CMakeLists.txt file.