1
General / Re: [CMAKE][FetchContent](TARGET_RUNTIME_DLLS) openal32.dll alongside executable
« on: June 13, 2022, 05:03:30 pm »
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.
Guess the best approch would be to to use ${FETCHCONTENT_BASE_DIR} and navigate to the dll from here :
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.
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 dll
set(BUILD_SHARED_LIBS ON)
# sfml
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)
# !sfml
FetchContent_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()
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 dll
set(BUILD_SHARED_LIBS ON)
# sfml
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)
# !sfml
FetchContent_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()
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.