Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [CMAKE] getting access to the .dlls  (Read 2457 times)

0 Members and 1 Guest are viewing this topic.

nietaki

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • http://almost-done.net
[CMAKE] getting access to the .dlls
« 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 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:
Code: [Select]

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
Code: [Select]
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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[CMAKE] getting access to the .dlls
« Reply #1 on: December 18, 2011, 10:48:00 am »
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.
Laurent Gomila - SFML developer

nietaki

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • http://almost-done.net
[CMAKE] getting access to the .dlls
« Reply #2 on: December 18, 2011, 02:59:19 pm »
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

Code: [Select]
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!

 

anything