SFML community forums
Help => General => Topic started by: nietaki on December 18, 2011, 12:23:36 am
-
I recently moved on to try if SFML would work on Windows too ;), and along the way I went to rewrite the CMakeLists.txt for my project.
I was following this (https://github.com/SFML/SFML/wiki/TutorialCMake) tutorial, slightly modifying it for my needs and everything went just as planned, it all works great with VS 2010, but I have one question.
The important part of my CMakeLists.txt:
find_package(SFML 2.0 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()
# Install
install(TARGETS ${EXECUTABLE_NAME} DESTINATION ${PROJECT_BINARY_DIR}/bin)
install(FILES ${SFML_LIBRARIES} DESTINATION ${PROJECT_BINARY_DIR}/bin)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/resources DESTINATION ${PROJECT_BINARY_DIR}/bin/resources)
As you can see I wanted to create a directory with the standalone program (executable, resources and the shared libraries) in the "install" target. But as you might also suspect, the install(FILES ${SFML_LIBRARIES} DESTINATION ${PROJECT_BINARY_DIR}/bin)
copies the .lib files, not the .dll files, when used under Windows with VS. Is there a better way of doing it?
I know I could
a) install SFML to somewhere inside the PATH, like a normal person would
b) modify the PATH (at least before launching the executable)
c) do a windows if (if(CMAKE_HOST_WIN32)) and rework the ${SFML_LIBRARIES} and change lib -> bin and .lib -> .dll and install those files that way
...but I would like to have a universal, one-step solution that would work on any system (even if I can't install SFML to the system directories) without any needless tinkering with the paths and the makefile. Plus I guess having such a "ready to go" directory would be nice if at any time I wanted to make a simple installer ;)
Am I missing something? How should I go about doing it?
-
I don't think that there's a clean way of doing this. You should rather link statically to SFML.
By the way, you don't need to test SFML_FOUND since you used the REQUIRED keyword in find_package -- you'll get a fatal error if SFML is not found.
-
Thanks for your quick reply. Your suggestion helped (of course), so just for future reference:
I reconfigured and rebuilt SFML to create static libs (BUILD_SHARED_LIBS unchecked) and modified my CMakeLists.txt
set(CMAKE_MODULE_PATH "${MY_SFML_SOURCE}/cmake/Modules" ${CMAKE_MODULE_PATH})
if(CMAKE_HOST_WIN32)
set(SFML_STATIC_LIBRARIES TRUE)
endif()
find_package(SFML 2.0 REQUIRED system window graphics network audio)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
# Install
install(TARGETS ${EXECUTABLE_NAME} DESTINATION ${PROJECT_BINARY_DIR}/bin)
if(NOT CMAKE_HOST_WIN32) #nothing to copy if we're using static libs
install(FILES ${SFML_LIBRARIES} DESTINATION ${PROJECT_BINARY_DIR}/bin)
endif()
install(DIRECTORY ${PROJECT_SOURCE_DIR}/resources DESTINATION ${PROJECT_BINARY_DIR}/bin)
Works just as planned under Win7 + VS, and i suppose it also will under my Debian
thanks again!