With SFML 2.5.0 we have modernized our CMake build system largely thanks for Ceylo!
![Smiley :)](https://www.sfml-dev.org/forums/Smileys/default/smiley.gif)
In the last weeks however we've noticed a considered amount of people not realizing the changes and thus wondering what to do with their "broken" build system. This thread should help clarify the required changes to utilize the new SFMLConfig.cmake file.
FindSFML.cmake has been removedYou can look for it as long as you want, it doesn't exist anymore, regardless of guide XYZ said, if you use SFML 2.5.0 there's no FindSFML.cmake anymore.
This also means, you no longer have to make sure that FindSFML.cmake can be found in CMAKE_MODULE_PATH. As such if you have some code like
SET(CMAKE_MODULE_PATH ...) you can remove that from your CMake file.
SFML_ROOT is no moreWindows users (and maybe others) have gotten used to setting SFML_ROOT in order to tell the FindSFML.cmake where to look for SFML. This isn't true anymore and instead the error message with suggestion CMake throws at you, can finally be implemented.
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.
Meaning, if the SFMLConfig.cmake file can't be automatically located, you can provide the directory containing said file by setting SFML_DIR.
${SFML_LIBRARIES}, ${SFML_DEPENDENCIES} and ${SFML_INCLUDE_DIR} don't exist anymoreThis is now mostly automated. The include directory no longer needs to be manually set, so this step can be completely removed. As for the libraries, all you need to specify is the dependencies on the highest level in a dependency tree. Meaning, if you want sfml-graphics, you only need to search for the graphics module and link the sfml-graphics library, CMake will take care of resolving the additionally dependencies like sfml-window or sfml-system. Even for static libraries, you don't need to specify the dependencies as CMake will do it for your.
Example CMake scriptUpdate: Thrasher and I have put together a CMake-SFML project template, which also features quite a few useful links in the ReadMe:
https://github.com/eXpl0it3r/cmake-sfml-projectHere's an example script that links sfml-graphics and sfml-audio and their dependencies.
cmake_minimum_required(VERSION 3.1)
project(SFMLTest)
## If you want to link SFML statically
# set(SFML_STATIC_LIBRARIES TRUE)
## In most cases better set in the CMake cache
# set(SFML_DIR "<sfml root prefix>/lib/cmake/SFML")
find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)
add_executable(SFMLTest main.cpp)
target_link_libraries(SFMLTest sfml-graphics sfml-audio)
DocumentationA more detailed usage documentation can be found directly inside the
SFMLConfig.cmake file.
While you're here, you might as well try to get your project updated to modern CMake.
This article might be useful for you.
![Wink ;)](https://www.sfml-dev.org/forums/Smileys/default/wink.gif)