Hi,
I'd like to add SFML as a git submodule to an existing CMake project. Let's take this CMakeLists.txt as the starting point:
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project("Test")
set(SOURCE_FILES
src/main.cpp
)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
To add SFML as a submodule in the directory ./libs/sfml/, I do:
git submodule add https://github.com/SFML/SFML.git libs/sfml
And then I adjust my CMakeLists.txt to:
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project("Test")
set(SOURCE_FILES
src/main.cpp
)
set(BUILD_SHARED_LIBS FALSE)
add_subdirectory(libs/sfml)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} sfml-graphics)
target_link_libraries(${PROJECT_NAME} sfml-audio)
It works, but is this the proper way to integrate SFML as a git submodule (statically linked)? I'm not sure if it's bad practice or if it's the way to go as I bypass the existing SFMLConfig.cmake script / the find_package(SFML ...) macro.
Hi Nexus,
thank you for your reply. I've already tried this before starting this thread, the CMakeLists.txt looks like the following:
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project("Test")
set(SOURCE_FILES
src/main.cpp
)
set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR "libs/sfml/")
find_package(SFML 2.5 COMPONENTS audio graphics window system REQUIRED)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} sfml-graphics)
target_link_libraries(${PROJECT_NAME} sfml-audio)
But the problem is (at least I think so) that find_package does not trigger any build process, so the SFMLConfig.cmake is not created from the SFMLConfig.cmake.in.
I should clarify that I want to integrate the SFML build process into my project. I don't like to build SFML manually in it's subfolder before I can start building my main project. I'd like to clone my project's repository, including SFML as a submodule, hit the 'build' button once and everything should be build automatically (First SFML, then my project).
As far as I understand, find_package only works if SFML was build beforehand (or at least the SFMLConfig.cmake has to be created). But I could also be absolutely wrong, unfortunately I didn't do that much with CMake yet.
To make this post complete, here's the CMake error message using the above posted CMakeLists.txt:
CMake Error at CMakeLists.txt:12 (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.