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

Author Topic: [CMAKE][FetchContent](TARGET_RUNTIME_DLLS) openal32.dll alongside executable  (Read 1935 times)

0 Members and 1 Guest are viewing this topic.

frayien

  • Newbie
  • *
  • Posts: 2
    • View Profile
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 ###

# sfml
set(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 string
add_custom_command(TARGET exe POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:exe> $<TARGET_FILE_DIR:exe>
  COMMAND_EXPAND_LISTS
)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
I think there isn't anything really as simple.

Thrasher has considered a similar approach in the SFML CMake template that I've started, see his draft PR: https://github.com/eXpl0it3r/cmake-sfml-project/pull/4/files
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

frayien

  • Newbie
  • *
  • Posts: 2
    • View Profile
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 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()

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.
« Last Edit: June 13, 2022, 05:05:28 pm by frayien »

 

anything