Skip to content

Commit

Permalink
modules: find the OpenAL DLL also with the imported target.
Browse files Browse the repository at this point in the history
And update the DLL copying to handle Debug as well.
  • Loading branch information
mosra committed Jun 10, 2020
1 parent 7f88ae5 commit 1b1347f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
20 changes: 13 additions & 7 deletions modules/FindOpenAL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#
# OPENAL_LIBRARY - OpenAL library
# OPENAL_DLL_RELEASE - OpenAL release DLL on Windows, if found. Note that
# (at least in case of the binary OpenAL Soft distribution) it's named
# soft_oal.dll and you need to rename it to OpenAL32.dll to make it work.
# in case of the binary OpenAL Soft distribution it's named soft_oal.dll and
# you need to rename it to OpenAL32.dll to make it work.
# OPENAL_INCLUDE_DIR - Include dir
#

Expand Down Expand Up @@ -69,6 +69,17 @@ if(TARGET OpenAL OR TARGET OpenAL::OpenAL)
# that ourselves.
get_target_property(_OPENAL_SOURCE_DIR OpenAL SOURCE_DIR)
set_target_properties(OpenAL::OpenAL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${_OPENAL_SOURCE_DIR}/include/AL)

# For the imported target get the DLL location
else()
if(CORRADE_TARGET_WINDOWS)
get_target_property(OPENAL_DLL_DEBUG OpenAL::OpenAL IMPORTED_LOCATION_DEBUG)
get_target_property(OPENAL_DLL_RELEASE OpenAL::OpenAL IMPORTED_LOCATION_RELEASE)
# Release not found, fall back to RelWithDebInfo
if(NOT OPENAL_DLL_RELEASE)
get_target_property(OPENAL_DLL_RELEASE OpenAL::OpenAL IMPORTED_LOCATION_RELWITHDEBINFO)
endif()
endif()
endif()

# Just to make FPHSA print some meaningful location, nothing else.
Expand All @@ -81,11 +92,6 @@ if(TARGET OpenAL OR TARGET OpenAL::OpenAL)
find_package_handle_standard_args("OpenAL" DEFAULT_MSG
_OPENAL_INTERFACE_INCLUDE_DIRECTORIES)

if(CORRADE_TARGET_WINDOWS)
# TODO: investigate if OpenAL Soft has IMPORTED_LOCATION_ / IMPLIB like
# GLFW does so we can provide OPENAL_DLL
endif()

return()
endif()

Expand Down
18 changes: 13 additions & 5 deletions src/Magnum/Audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,21 @@ install(TARGETS MagnumAudio
install(FILES ${MagnumAudio_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Audio)

# Copy the OpenAL DLL next to the place where all executables are stored to
# help people running the apps. TODO: update if we ever have a debug DLL
if(CMAKE_RUNTIME_OUTPUT_DIRECTORY AND CORRADE_TARGET_WINDOWS AND OPENAL_DLL_RELEASE)
# help people running the apps.
if(CMAKE_RUNTIME_OUTPUT_DIRECTORY AND CORRADE_TARGET_WINDOWS AND (OPENAL_DLL_DEBUG OR OPENAL_DLL_RELEASE))
# Not exactly sure why, but in the OpenAL Soft binary distribution it's
# named soft_oal.dll and needs to be renamed to OpenAL32.dll to work
# correctly
add_custom_command(TARGET MagnumAudio POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OPENAL_DLL_RELEASE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/OpenAL32.dll)
# correctly. Not the case with OpenAL Soft built by hand.
if(OPENAL_DLL_DEBUG AND OPENAL_DLL_RELEASE)
add_custom_command(TARGET MagnumAudio POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<$<CONFIG:Debug>:${OPENAL_DLL_DEBUG}>$<$<NOT:$<CONFIG:Debug>>:${OPENAL_DLL_RELEASE}> ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/OpenAL32.dll)
elseif(OPENAL_DLL_DEBUG)
add_custom_command(TARGET MagnumAudio POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OPENAL_DLL_DEBUG} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/OpenAL32.dll)
else()
add_custom_command(TARGET MagnumAudio POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OPENAL_DLL_RELEASE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/OpenAL32.dll)
endif()
endif()

# Magnum Audio target alias for superprojects
Expand Down

0 comments on commit 1b1347f

Please sign in to comment.