From 241625811731c44497ea1d1447dc6f5aa65757cd Mon Sep 17 00:00:00 2001 From: Castor215 <132155746+Castor215@users.noreply.github.com> Date: Sat, 21 Oct 2023 01:02:20 +0100 Subject: [PATCH] externals: add overarching USE_SYSTEM_LIBS variable (#7078) --- CMakeLists.txt | 19 +---- externals/CMakeLists.txt | 4 + .../cmake-modules/CitraHandleSystemLibs.cmake | 76 +++++++++++++++++++ 3 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 externals/cmake-modules/CitraHandleSystemLibs.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f1fbee32..0c6342dfe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,24 +92,7 @@ option(ENABLE_LTO "Enable link time optimization" ${DEFAULT_ENABLE_LTO}) option(CITRA_USE_PRECOMPILED_HEADERS "Use precompiled headers" ON) option(CITRA_WARNINGS_AS_ERRORS "Enable warnings as errors" ON) -# System library options -CMAKE_DEPENDENT_OPTION(USE_SYSTEM_QT "Use the system Qt lib (instead of the bundled one)" OFF "ENABLE_QT;MSVC OR APPLE" ON) -CMAKE_DEPENDENT_OPTION(USE_SYSTEM_MOLTENVK "Use the system MoltenVK lib (instead of the bundled one)" OFF "APPLE" OFF) -option(USE_SYSTEM_SDL2 "Use the system SDL2 lib (instead of the bundled one)" OFF) -option(USE_SYSTEM_BOOST "Use the system Boost libs (instead of the bundled ones)" OFF) -option(USE_SYSTEM_OPENSSL "Use the system OpenSSL libs (instead of the bundled LibreSSL)" OFF) -option(USE_SYSTEM_LIBUSB "Use the system libusb (instead of the bundled libusb)" OFF) -option(USE_SYSTEM_CPP_JWT "Use the system cpp-jwt (instead of the bundled one)" OFF) -option(USE_SYSTEM_SOUNDTOUCH "Use the system SoundTouch (instead of the bundled one)" OFF) -option(USE_SYSTEM_CPP_HTTPLIB "Use the system cpp-httplib (instead of the bundled one)" OFF) -option(USE_SYSTEM_JSON "Use the system JSON (nlohmann-json3) package (instead of the bundled one)" OFF) -option(USE_SYSTEM_DYNARMIC "Use the system dynarmic (instead of the bundled one)" OFF) -option(USE_SYSTEM_FMT "Use the system fmt (instead of the bundled one)" OFF) -option(USE_SYSTEM_XBYAK "Use the system xbyak (instead of the bundled one)" OFF) -option(USE_SYSTEM_INIH "Use the system inih (instead of the bundled one)" OFF) -option(USE_SYSTEM_FDK_AAC_HEADERS "Use the system fdk-aac headers (instead of the bundled one)" OFF) -option(USE_SYSTEM_FFMPEG_HEADERS "Use the system FFmpeg headers (instead of the bundled one)" OFF) -option(USE_SYSTEM_GLSLANG "Use the system glslang and SPIR-V libraries (instead of the bundled ones)" OFF) +include(CitraHandleSystemLibs) if (CITRA_USE_PRECOMPILED_HEADERS) message(STATUS "Using Precompiled Headers.") diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 649f1c2f8..c86981f03 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -34,6 +34,10 @@ if (NOT USE_SYSTEM_BOOST) ) target_link_libraries(boost_iostreams PUBLIC boost) # Add additional boost libs here; remember to ALIAS them in the root CMakeLists! +else() + unset(BOOST_ROOT CACHE) + unset(Boost_INCLUDE_DIR CACHE) + set(Boost_NO_SYSTEM_PATHS OFF CACHE BOOL "" FORCE) endif() # Catch2 diff --git a/externals/cmake-modules/CitraHandleSystemLibs.cmake b/externals/cmake-modules/CitraHandleSystemLibs.cmake new file mode 100644 index 000000000..4166e201b --- /dev/null +++ b/externals/cmake-modules/CitraHandleSystemLibs.cmake @@ -0,0 +1,76 @@ +option(USE_SYSTEM_LIBS "Use system libraries over bundled ones" OFF) + +# System library options +CMAKE_DEPENDENT_OPTION(USE_SYSTEM_QT "Use the system Qt lib (instead of the bundled one)" OFF "ENABLE_QT;MSVC OR APPLE" ON) +CMAKE_DEPENDENT_OPTION(USE_SYSTEM_MOLTENVK "Use the system MoltenVK lib (instead of the bundled one)" OFF "APPLE" OFF) +option(USE_SYSTEM_SDL2 "Use the system SDL2 lib (instead of the bundled one)" OFF) +option(USE_SYSTEM_BOOST "Use the system Boost libs (instead of the bundled ones)" OFF) +option(USE_SYSTEM_OPENSSL "Use the system OpenSSL libs (instead of the bundled LibreSSL)" OFF) +option(USE_SYSTEM_LIBUSB "Use the system libusb (instead of the bundled libusb)" OFF) +option(USE_SYSTEM_CPP_JWT "Use the system cpp-jwt (instead of the bundled one)" OFF) +option(USE_SYSTEM_SOUNDTOUCH "Use the system SoundTouch (instead of the bundled one)" OFF) +option(USE_SYSTEM_CPP_HTTPLIB "Use the system cpp-httplib (instead of the bundled one)" OFF) +option(USE_SYSTEM_JSON "Use the system JSON (nlohmann-json3) package (instead of the bundled one)" OFF) +option(USE_SYSTEM_DYNARMIC "Use the system dynarmic (instead of the bundled one)" OFF) +option(USE_SYSTEM_FMT "Use the system fmt (instead of the bundled one)" OFF) +option(USE_SYSTEM_XBYAK "Use the system xbyak (instead of the bundled one)" OFF) +option(USE_SYSTEM_INIH "Use the system inih (instead of the bundled one)" OFF) +option(USE_SYSTEM_FDK_AAC_HEADERS "Use the system fdk-aac headers (instead of the bundled one)" OFF) +option(USE_SYSTEM_FFMPEG_HEADERS "Use the system FFmpeg headers (instead of the bundled one)" OFF) +option(USE_SYSTEM_GLSLANG "Use the system glslang and SPIR-V libraries (instead of the bundled ones)" OFF) + +# Qt and MoltenVK are handled separately +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_SDL2 "Disable system SDL2" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_BOOST "Disable system Boost" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_OPENSSL "Disable system OpenSSL" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_LIBUSB "Disable system LibUSB" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_CPP_JWT "Disable system cpp-jwt" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_SOUNDTOUCH "Disable system SoundTouch" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_CPP_HTTPLIB "Disable system cpp-httplib" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_JSON "Disable system JSON" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_DYNARMIC "Disable system Dynarmic" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_FMT "Disable system fmt" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_XBYAK "Disable system xbyak" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_INIH "Disable system inih" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_FDK_AAC_HEADERS "Disable system fdk_aac" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_FFMPEG_HEADERS "Disable system ffmpeg" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_GLSLANG "Disable system glslang" OFF "USE_SYSTEM_LIBS" OFF) + +set(LIB_VAR_LIST + SDL2 + BOOST + OPENSSL + LIBUSB + CPP_JWT + SOUNDTOUCH + CPP_HTTPLIB + JSON + DYNARMIC + FMT + XBYAK + INIH + FDK_AAC_HEADERS + FFMPEG_HEADERS + GLSLANG + ) + +# First, check that USE_SYSTEM_XXX is not used with USE_SYSTEM_LIBS + +if(USE_SYSTEM_LIBS) + foreach(CURRENT_LIB IN LISTS LIB_VAR_LIST) + if(USE_SYSTEM_${CURRENT_LIB}) + unset(USE_SYSTEM_${CURRENT_LIB}) + endif() + endforeach() + + # Next, set which libraries to use + + foreach(CURRENT_LIB IN LISTS LIB_VAR_LIST) + if(NOT DISABLE_SYSTEM_${CURRENT_LIB}) + set(USE_SYSTEM_${CURRENT_LIB} ON CACHE BOOL "Using system ${CURRENT_LIB}" FORCE) + else() + # Explicitly disable this in case of multiple CMake invocations + set(USE_SYSTEM_${CURRENT_LIB} OFF CACHE BOOL "Using system ${CURRENT_LIB}" FORCE) + endif() + endforeach() +endif()