From b8fd7748249dd40fca976d18f7802f5e73f8deac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trung=20L=C3=AA?= <8@tle.id.au> Date: Wed, 27 Mar 2024 19:38:02 +1100 Subject: [PATCH] Add option to compile against shared OpenAL lib --- CMakeLists.txt | 1 + extern/CMakeLists.txt | 36 ++++++++++++++++++++---------------- src/CMakeLists.txt | 8 ++++++-- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5306f2825..a0998b27b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ ENDIF() OPTION(CONFIG_BUILD_GLSLANG "Build glslangValidator from source instead of using the SDK" ${DEFAULT_BUILD_GLSLANG}) OPTION(CONFIG_BUILD_IPO "Enable interprocedural optimizations" OFF) OPTION(CONFIG_BUILD_SHADER_DEBUG_INFO "Build shaders with debug info" OFF) +OPTION(USE_SYSTEM_OPENAL "Prefer system OpenAL Soft instead of the bundled one" OFF) set_property(GLOBAL PROPERTY USE_FOLDERS ON) include(CheckIPOSupported) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 9f188b3d3..c99f7db02 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -96,19 +96,23 @@ target_include_directories(tinyobjloader INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/t # if (IS_64_BIT) - set(LIBTYPE STATIC) - option(FORCE_STATIC_VCRT "" ON) - option(ALSOFT_UTILS "" OFF) - option(ALSOFT_EXAMPLES "" OFF) - option(ALSOFT_UPDATE_BUILD_VERSION "" OFF) - option(ALSOFT_INSTALL "" OFF) - option(ALSOFT_INSTALL_CONFIG "" OFF) - option(ALSOFT_INSTALL_HRTF_DATA "" OFF) - option(ALSOFT_INSTALL_AMBDEC_PRESETS "" OFF) - option(ALSOFT_INSTALL_EXAMPLES "" OFF) - option(ALSOFT_INSTALL_UTILS "" OFF) - add_subdirectory(openal-soft) - set_target_properties(OpenAL PROPERTIES FOLDER extern/openal-soft) - set_target_properties(common PROPERTIES FOLDER extern/openal-soft) - set_target_properties(ex-common PROPERTIES FOLDER extern/openal-soft) -endif() \ No newline at end of file + if (USE_SYSTEM_OPENAL) + find_package(OpenAL REQUIRED) + else() + set(LIBTYPE STATIC) + option(FORCE_STATIC_VCRT "" ON) + option(ALSOFT_UTILS "" OFF) + option(ALSOFT_EXAMPLES "" OFF) + option(ALSOFT_UPDATE_BUILD_VERSION "" OFF) + option(ALSOFT_INSTALL "" OFF) + option(ALSOFT_INSTALL_CONFIG "" OFF) + option(ALSOFT_INSTALL_HRTF_DATA "" OFF) + option(ALSOFT_INSTALL_AMBDEC_PRESETS "" OFF) + option(ALSOFT_INSTALL_EXAMPLES "" OFF) + option(ALSOFT_INSTALL_UTILS "" OFF) + add_subdirectory(openal-soft) + set_target_properties(OpenAL PROPERTIES FOLDER extern/openal-soft) + set_target_properties(common PROPERTIES FOLDER extern/openal-soft) + set_target_properties(ex-common PROPERTIES FOLDER extern/openal-soft) + endif() +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f6908ca5b..26f336cc8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -379,7 +379,11 @@ ADD_DEFINITIONS(-DVERSION_POINT=${Q2RTX_VERSION_POINT}) ADD_DEFINITIONS(-DVERSION_SHA=${Q2RTX_VERSION_SHA}) ADD_DEFINITIONS(-DVERSION_BRANCH=${Q2RTX_VERSION_BRANCH}) -ADD_DEFINITIONS(-DHAVE_CONFIG_H=1 -DCURL_STATICLIB -DAL_LIBTYPE_STATIC) +ADD_DEFINITIONS(-DHAVE_CONFIG_H=1 -DCURL_STATICLIB) + +IF (NOT USE_SYSTEM_OPENAL) + ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC) +ENDIF() IF(WIN32) ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) @@ -505,7 +509,7 @@ IF (TARGET client) TARGET_LINK_LIBRARIES(client stb) TARGET_LINK_LIBRARIES(client tinyobjloader) - TARGET_LINK_LIBRARIES(client OpenAL) + TARGET_LINK_LIBRARIES(client OpenAL) ENDIF() SOURCE_GROUP("game\\sources" FILES ${SRC_GAME})