31
General discussions / Re: having trouble adding a SFML to my project using CMake
« on: March 06, 2024, 11:22:59 am »
I highly recommend to use the SFML CMake Template: https://www.sfml-dev.org/tutorials/2.6/start-cmake.php
Not only will you not have to build SFML separately anymore, but it also provides a valid and ready to use CMake file.
One of the strength of CMake is that you can provide configuration files for your library, so that any users don't have to manually specify include directories or library file names, instead they can work with targets and have the config do all the heavy lifting, which additionally makes it platform unspecific CMake code.
If you don't want to use the CMake template, you should really be calling find_package and set the SFML_DIR to point to the lib/cmake/SFML directory or SFML_ROOT to point to the SFML root directory.
Then you don't have specify an include directory and you can just have target_link_libraries(MyProject sfml-graphics sfml-audio)
Not only will you not have to build SFML separately anymore, but it also provides a valid and ready to use CMake file.
One of the strength of CMake is that you can provide configuration files for your library, so that any users don't have to manually specify include directories or library file names, instead they can work with targets and have the config do all the heavy lifting, which additionally makes it platform unspecific CMake code.
If you don't want to use the CMake template, you should really be calling find_package and set the SFML_DIR to point to the lib/cmake/SFML directory or SFML_ROOT to point to the SFML root directory.
Then you don't have specify an include directory and you can just have target_link_libraries(MyProject sfml-graphics sfml-audio)