In an attempt to learn how to use CMake to generate projects, I'm writing a simple project that uses CMake and trying to implement features I'm interested in. I was able to configure a project that has both an executable and another library file as well as including the version of Boost I have installed.
Versions of things I am using, in case it is relevant:
- CMake 3.3.0
- Visual Studio 2015 Community Edition
- SFML 2.3.2 (built with CMake & VS above)
- Boost 1.54.0
I've run into some trouble trying to configure the project to include SFML as well.
The first thing I did was copy the
FindSFML.cmake file into my project's
/cmake/Modules directory then including a line to make sure it is in the CMake module path:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
Since I was using Windows, I wanted to specify where SFML was and then use the
find_package() command. I was hoping to try to link statically, so I also defined the option for that. This is what I wrote:
if(NOT DEFINED SFML_ROOT AND
NOT DEFINED ENV{SFML_ROOT})
if(WIN32)
set(SFML_ROOT "C:/Program Files (x86)/SFML")
endif()
endif()
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML 2 REQUIRED COMPONENTS system window graphics network audio)
include_directories(SYSTEM ${SFML_INCLUDE_DIR})
The SFML folder in Program Files is where I installed SFML to after building it with CMake.
Finally, I added this command to the properties for my main executable target:
target_link_libraries(Game ${Boost_LIBRARIES}
${SFML_LIBRARIES}
Utilities)
Where Utilities is another target I was building as part of this project.
When I run CMake through the GUI, I get the following error message when it tries to find SFML:
CMake Error at cmake/Modules/FindSFML.cmake:358 (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:39 (find_package)I looked at the properties CMake lists (checking Advanced so I can see all of them) and note something that seems strange to me: All of the
SFML_X
_LIBRARY_DYNAMIC_X properties are set to lib files, rather than DLLs as I would have expected. All of the properties for
STATIC libraries are shown as not found.
If I manually copy over the lib file paths into the
STATIC properties and reconfigure, the project generates correctly and I am able to compile and link. However, when I run the executable, it reports an error saying it cannot find
sfml-system-d-2.dll, which I didn't think would be necessary since I was trying to link statically.
First, I'd like to know what I need to do in order to allow SFML's static libs to be found through CMake so I don't have to manually fix the properties. Assuming this doesn't also somehow fix the other issue, I'd like to know what I else I need to do if I want the generated project to link SFML statically rather than requiring DLLs.