Hi !
I am not sure if it is a more about SFML or about cmake but :
(Windows 10 x64 / SFML 2.6.x / CMake 3.21.0)
I am using FetchContent to automatically fecth sfml and build it alongside my project statically.
Problem is I cant run my project because it needs openal32.dll to be next to the executable to run, but openal32.dll is in build\_deps\sfml-src\extlibs\bin\x64\openal32.dll and my executable at project root.
I can simply move the dll next to my project manualy but I would like cmake to do it automatically, I tried to use a custom command and $<TARGET_RUNTIME_DLLS:exe> from cmake 3.21 but it cant find any dll.
So, is there a simple way to do what I described ?
It feels like an obvious thing but I cant quite find the way to do it ...
Thanks !
CMake :
cmake_minimum_required(VERSION 3.21.0
)include(FetchContent
)project(exe
VERSION 0.1.0
)### CMake config ###set(CMAKE_EXPORT_COMPILE_COMMANDS
ON)set(CMAKE_CXX_STANDARD 20
)set(CMAKE_CXX_EXTENSIONS
OFF)set(CMAKE_CXX_STANDARD_REQUIRED
TRUE)set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
"${PROJECT_SOURCE_DIR}")### Dependency declaration ###FetchContent_Declare
( sfml
GIT_REPOSITORY
"https://github.com/SFML/SFML.git" GIT_TAG 2.6.x
)### Dependency population #### sfmlset(BUILD_SHARED_LIBS
OFF)set(SFML_BUILD_EXAMPLES
OFF)set(SFML_BUILD_DOC
OFF)set(SFML_BUILD_NETWORK
OFF)set(SFML_BUILD_AUDIO
ON)set(SFML_BUILD_GRAPHICS
ON)set(SFML_BUILD_WINDOW
ON)FetchContent_GetProperties
(sfml
)if(NOT sfml_POPULATED
) FetchContent_Populate
(sfml
) add_subdirectory(${sfml_SOURCE_DIR})endif()# !sfml# sfml audio cannot build since c++17 due to removed auto_ptr (fixed in sfml 2.6.x)# set_target_properties(sfml-audio PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)### Project headers ###include_directories(include
)### Project sources ###file(GLOB_RECURSE SRCS ./src/*
)add_executable(exe
${SRCS})target_link_libraries( exe
sfml-graphics
sfml-window
sfml-system
sfml-audio
)## Fail since $<TARGET_RUNTIME_DLLS:exe> resolves to empty stringadd_custom_command(TARGET exe
POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:exe> $<TARGET_FILE_DIR:exe>
COMMAND_EXPAND_LISTS
)
I gave it a try, if I turn BUILD_SHARED_LIBS ON sfml is built as an external dependency and SFML's dlls are indeed copied next to the executable. BUT still not openal32.dll ... this feels even "weirdier" since now some dlls are copied but this one is not...
Obvious reason is sfml's dlls are generated by the build thus cmake "knows" them but openal is provided in the sources of sfml thus cmake "dont know" it exists.
cmake_minimum_required(VERSION 3.21.0
)include(FetchContent
)project(exe
VERSION 0.1.0
)### CMake config ###set(CMAKE_EXPORT_COMPILE_COMMANDS
ON)set(CMAKE_CXX_STANDARD 20
)set(CMAKE_CXX_EXTENSIONS
OFF)set(CMAKE_CXX_STANDARD_REQUIRED
TRUE)set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
"${PROJECT_SOURCE_DIR}")### Dependency declaration ###FetchContent_Declare
( sfml
GIT_REPOSITORY
"https://github.com/SFML/SFML.git" GIT_TAG 2.6.x
)### Dependency population ##### Switched ON to build sfml as dllset(BUILD_SHARED_LIBS
ON)# sfmlset(SFML_BUILD_EXAMPLES
OFF)set(SFML_BUILD_DOC
OFF)set(SFML_BUILD_NETWORK
OFF)set(SFML_BUILD_AUDIO
ON)set(SFML_BUILD_GRAPHICS
ON)set(SFML_BUILD_WINDOW
ON)# !sfmlFetchContent_MakeAvailable
(sfml
)# sfml audio cannot build since c++17 due to removed auto_ptr (fixed in sfml 2.6.x)# set_target_properties(sfml-audio PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)### Project headers ###include_directories(include
)### Project sources ###file(GLOB_RECURSE SRCS ./src/*
)add_executable(exe
${SRCS})target_link_libraries( exe
sfml-graphics
sfml-window
sfml-system
sfml-audio
)## Copies sfml's dll but not openal32.dll if (WIN32
AND BUILD_SHARED_LIBS
) add_custom_command(TARGET exe
POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:exe> $<TARGET_FILE_DIR:exe>
COMMAND_EXPAND_LISTS
)endif()
Guess the best approch would be to to use ${FETCHCONTENT_BASE_DIR} and navigate to the dll from here :
if (WIN32
AND SFML_BUILD_AUDIO
) add_custom_command(TARGET FNES_emulator
POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
${FETCHCONTENT_BASE_DIR}/sfml-src/extlibs/bin/x64/openal32.dll $<TARGET_FILE_DIR:exe>
)endif()
Just need to add a branch for x64 or x86, not sure what cmake constant exist to detect if build is x64 or x86 but this is a cmake question and have nothing to do with sfml.