From d5e6cea6e5b17dd15b56b6862f20561fbb3504ef Mon Sep 17 00:00:00 2001 From: Honeybunch Date: Sat, 19 Oct 2024 16:15:07 -0700 Subject: [PATCH] Making some tweaks that would make me happy as a vcpkg maintainer --- core/CMakeLists.txt | 32 ++++++++++---- core/src/core/CMakeLists.txt | 54 +++++++++++++++++------ core/src/core/steam-audio-config.cmake.in | 7 +++ 3 files changed, 71 insertions(+), 22 deletions(-) create mode 100644 core/src/core/steam-audio-config.cmake.in diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index ab494615..aa5bdb68 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -82,6 +82,8 @@ option(BUILD_SHARED_LIBS "Build shared libraries instead of static." ON) option(STEAMAUDIO_BUILD_TESTS "Build unit tests." ON) option(STEAMAUDIO_BUILD_BENCHMARKS "Build benchmarks." ON) option(STEAMAUDIO_BUILD_SAMPLES "Build samples." ON) +option(STEAMAUDIO_EXPORT "Export the project for use by downstream. Requires that required dependencies are found via Config mode." OFF) +option(STEAMAUDIO_CLOSED_SOURCE_DEPS "Use closed source libraries. Otherwise attempt to skip" ON) if (IPL_OS_WINDOWS AND IPL_CPU_X64) option(STEAMAUDIO_BUILD_ITESTS "Build interactive tests." ON) @@ -192,8 +194,13 @@ endif() # macOS flags if (IPL_OS_MACOS) - set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64") - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13") + # Allow project invoker to override OSX settings + if(NOT CMAKE_OSX_ARCHITECTURES) + set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64") + endif() + if(NOT CMAKE_OSX_DEPLOYMENT_TARGET) + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13") + endif() add_compile_options(-Wno-extern-c-compat) # Suppress warning about empty API structs. add_compile_options(-Wno-unknown-attributes) # Suppress warning in FlatBuffers. endif() @@ -240,7 +247,11 @@ if (STEAMAUDIO_ENABLE_FFTS) endif() if (NOT FFT_LIBRARY) - find_package(PFFFT REQUIRED) + if(STEAMAUDIO_EXPORT) + find_package(PFFFT CONFIG REQUIRED) + else() + find_package(PFFFT REQUIRED) + endif() set(FFT_LIBRARY PFFFT) endif() @@ -252,10 +263,15 @@ if (STEAMAUDIO_ENABLE_MKL) endif() endif() -find_package(MySOFA REQUIRED) -find_package(FlatBuffers REQUIRED) +if(STEAMAUDIO_EXPORT) + find_package(MySOFA CONFIG REQUIRED) + find_package(FlatBuffers CONFIG REQUIRED) +else() + find_package(MySOFA REQUIRED) + find_package(FlatBuffers REQUIRED) +endif() -if (STEAMAUDIO_ENABLE_EMBREE) +if (STEAMAUDIO_ENABLE_EMBREE AND STEAMAUDIO_CLOSED_SOURCE_DEPS) find_package(ISPC 1.12 EXACT) find_package(Embree 2.17 EXACT) if (NOT ISPC_FOUND OR NOT Embree_FOUND) @@ -264,7 +280,7 @@ if (STEAMAUDIO_ENABLE_EMBREE) endif() endif() -if (STEAMAUDIO_ENABLE_RADEONRAYS) +if (STEAMAUDIO_ENABLE_RADEONRAYS AND STEAMAUDIO_CLOSED_SOURCE_DEPS) find_package(Python COMPONENTS Interpreter) find_package(RadeonRays) if (NOT Python_FOUND OR NOT RadeonRays_FOUND) @@ -273,7 +289,7 @@ if (STEAMAUDIO_ENABLE_RADEONRAYS) endif() endif() -if (STEAMAUDIO_ENABLE_TRUEAUDIONEXT) +if (STEAMAUDIO_ENABLE_TRUEAUDIONEXT AND STEAMAUDIO_CLOSED_SOURCE_DEPS) find_package(TrueAudioNext) if (NOT TrueAudioNext_FOUND) message(STATUS "Disabling TrueAudioNext") diff --git a/core/src/core/CMakeLists.txt b/core/src/core/CMakeLists.txt index 7c9226fc..474814b5 100644 --- a/core/src/core/CMakeLists.txt +++ b/core/src/core/CMakeLists.txt @@ -176,7 +176,7 @@ endif() # add_library(hrtf OBJECT hrtf.cpp) -target_include_directories(hrtf PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(hrtf PUBLIC "$") # @@ -582,7 +582,7 @@ if (STEAMAUDIO_BUILD_CSHARP_BINDINGS) endif() # This is needed so we can include generated headers -target_include_directories(core PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories(core PUBLIC "$") if (IPL_OS_WINDOWS) target_link_libraries(core PUBLIC delayimp) @@ -639,7 +639,7 @@ source_group("OpenCL Files" FILES ${CL_SOURCE}) target_compile_definitions(core PRIVATE STEAMAUDIO_BUILDING_CORE) -target_precompile_headers(core PUBLIC pch.h) +target_precompile_headers(core PRIVATE pch.h) # @@ -670,7 +670,7 @@ if (IPL_OS_LINUX) target_link_options(phonon PRIVATE -Wl,--exclude-libs,ALL) endif() -if (IPL_OS_WINDOWS AND IPL_CPU_X64 AND BUILD_SHARED_LIBS) +if (IPL_OS_WINDOWS AND IPL_CPU_X64 AND BUILD_SHARED_LIBS AND STEAMAUDIO_DEPS_CLOSED_SOURCE) set_target_properties(phonon PROPERTIES LINK_FLAGS "/DELAYLOAD:opencl.dll /DELAYLOAD:gpuutilities.dll /DELAYLOAD:trueaudionext.dll") endif() @@ -967,16 +967,18 @@ if (IPL_OS_MACOS) ) endif() -if (IPL_OS_WINDOWS) - install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/$/phonon.pdb - DESTINATION symbols/${IPL_BIN_SUBDIR} - ) -elseif (IPL_OS_LINUX AND NOT IPL_CPU_ARMV8) - install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/libphonon.so.dbg - DESTINATION symbols/${IPL_BIN_SUBDIR} - ) +if(BUILD_SHARED_LIBS) + if (IPL_OS_WINDOWS) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/phonon.pdb + DESTINATION bin + ) + elseif (IPL_OS_LINUX AND NOT IPL_CPU_ARMV8) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/libphonon.so.dbg + DESTINATION bin + ) + endif() endif() install( @@ -994,4 +996,28 @@ if (IPL_OS_WINDOWS AND IPL_CPU_X64) ) endif() +if(STEAMAUDIO_EXPORT) + export(EXPORT steam-audio_exports + NAMESPACE steam-audio:: + FILE ${CMAKE_CURRENT_BINARY_DIR}/steam-audioTargets.cmake + ) + + # required to resolve object libraries on import + install(TARGETS core hrtf EXPORT steam-audio_exports) + + install(EXPORT steam-audio_exports + NAMESPACE steam-audio:: + FILE steam-audioTargets.cmake + DESTINATION share/steam-audio + ) + + include(CMakePackageConfigHelpers) + configure_package_config_file(steam-audio-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/steam-audio-config.cmake + INSTALL_DESTINATION share/steam-audio) + + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/steam-audio-config.cmake + DESTINATION share/steam-audio ) +endif() + include(CMakeListsInternal.txt OPTIONAL) diff --git a/core/src/core/steam-audio-config.cmake.in b/core/src/core/steam-audio-config.cmake.in new file mode 100644 index 00000000..776f7aa6 --- /dev/null +++ b/core/src/core/steam-audio-config.cmake.in @@ -0,0 +1,7 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +include(${CMAKE_CURRENT_LIST_DIR}/steam-audioTargets.cmake) + +check_required_components(steam-audio) \ No newline at end of file