From 7b8a5413add02004d778252c0b67bf921c1fb7d8 Mon Sep 17 00:00:00 2001 From: Alexandre Bouvier Date: Fri, 24 Feb 2023 23:45:38 +0100 Subject: [PATCH] cmake: support components in find modules --- CMakeLists.txt | 6 +++--- CMakeModules/FindLLVM.cmake | 18 ++++++++++++++---- CMakeModules/Findhttplib.cmake | 12 +++++++++++- CMakeModules/Findinih.cmake | 19 +++++++++++++++---- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f344ffd9b..7a7faa1c46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,8 +212,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) # Enforce the search mode of non-required packages for better and shorter failure messages find_package(enet 1.3 MODULE) find_package(fmt 9 REQUIRED) -find_package(inih MODULE) -find_package(LLVM MODULE) +find_package(inih 52 MODULE COMPONENTS INIReader) +find_package(LLVM MODULE COMPONENTS Demangle) find_package(lz4 REQUIRED) find_package(nlohmann_json 3.8 REQUIRED) find_package(Opus 1.3 MODULE) @@ -246,7 +246,7 @@ endif() if (ENABLE_WEB_SERVICE) find_package(cpp-jwt 1.4 CONFIG) - find_package(httplib 0.12 MODULE) + find_package(httplib 0.12 MODULE COMPONENTS OpenSSL) endif() if (YUZU_TESTS) diff --git a/CMakeModules/FindLLVM.cmake b/CMakeModules/FindLLVM.cmake index 513d9a5365..efbd0ca460 100644 --- a/CMakeModules/FindLLVM.cmake +++ b/CMakeModules/FindLLVM.cmake @@ -2,15 +2,25 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -find_package(LLVM QUIET CONFIG) +find_package(LLVM QUIET COMPONENTS CONFIG) +if (LLVM_FOUND) + separate_arguments(LLVM_DEFINITIONS) + if (LLVMDemangle IN_LIST LLVM_AVAILABLE_LIBS) + set(LLVM_Demangle_FOUND TRUE) + endif() +endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LLVM CONFIG_MODE) +find_package_handle_standard_args(LLVM HANDLE_COMPONENTS CONFIG_MODE) -if (LLVM_FOUND AND NOT TARGET LLVM::Demangle) +if (LLVM_FOUND AND LLVM_Demangle_FOUND AND NOT TARGET LLVM::Demangle) add_library(LLVM::Demangle INTERFACE IMPORTED) - llvm_map_components_to_libnames(LLVM_LIBRARIES demangle) target_compile_definitions(LLVM::Demangle INTERFACE ${LLVM_DEFINITIONS}) target_include_directories(LLVM::Demangle INTERFACE ${LLVM_INCLUDE_DIRS}) + # prefer shared LLVM: https://github.com/llvm/llvm-project/issues/34593 + # but use ugly hack because llvm_config doesn't support interface library + add_library(_dummy_lib SHARED EXCLUDE_FROM_ALL src/yuzu/main.cpp) + llvm_config(_dummy_lib USE_SHARED demangle) + get_target_property(LLVM_LIBRARIES _dummy_lib LINK_LIBRARIES) target_link_libraries(LLVM::Demangle INTERFACE ${LLVM_LIBRARIES}) endif() diff --git a/CMakeModules/Findhttplib.cmake b/CMakeModules/Findhttplib.cmake index 861207eb5c..48967add96 100644 --- a/CMakeModules/Findhttplib.cmake +++ b/CMakeModules/Findhttplib.cmake @@ -6,13 +6,23 @@ include(FindPackageHandleStandardArgs) find_package(httplib QUIET CONFIG) if (httplib_CONSIDERED_CONFIGS) - find_package_handle_standard_args(httplib CONFIG_MODE) + find_package_handle_standard_args(httplib HANDLE_COMPONENTS CONFIG_MODE) else() find_package(PkgConfig QUIET) pkg_search_module(HTTPLIB QUIET IMPORTED_TARGET cpp-httplib) + if ("-DCPPHTTPLIB_OPENSSL_SUPPORT" IN_LIST HTTPLIB_CFLAGS_OTHER) + set(httplib_OpenSSL_FOUND TRUE) + endif() + if ("-DCPPHTTPLIB_ZLIB_SUPPORT" IN_LIST HTTPLIB_CFLAGS_OTHER) + set(httplib_ZLIB_FOUND TRUE) + endif() + if ("-DCPPHTTPLIB_BROTLI_SUPPORT" IN_LIST HTTPLIB_CFLAGS_OTHER) + set(httplib_Brotli_FOUND TRUE) + endif() find_package_handle_standard_args(httplib REQUIRED_VARS HTTPLIB_INCLUDEDIR VERSION_VAR HTTPLIB_VERSION + HANDLE_COMPONENTS ) endif() diff --git a/CMakeModules/Findinih.cmake b/CMakeModules/Findinih.cmake index b8d38dcff7..791befebdc 100644 --- a/CMakeModules/Findinih.cmake +++ b/CMakeModules/Findinih.cmake @@ -3,14 +3,25 @@ # SPDX-License-Identifier: GPL-3.0-or-later find_package(PkgConfig QUIET) -pkg_search_module(INIREADER QUIET IMPORTED_TARGET INIReader) +pkg_search_module(INIH QUIET IMPORTED_TARGET inih) +if (INIReader IN_LIST inih_FIND_COMPONENTS) + pkg_search_module(INIREADER QUIET IMPORTED_TARGET INIReader) + if (INIREADER_FOUND) + set(inih_INIReader_FOUND TRUE) + endif() +endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(inih - REQUIRED_VARS INIREADER_LINK_LIBRARIES - VERSION_VAR INIREADER_VERSION + REQUIRED_VARS INIH_LINK_LIBRARIES + VERSION_VAR INIH_VERSION + HANDLE_COMPONENTS ) -if (inih_FOUND AND NOT TARGET inih::INIReader) +if (inih_FOUND AND NOT TARGET inih::inih) + add_library(inih::inih ALIAS PkgConfig::INIH) +endif() + +if (inih_FOUND AND inih_INIReader_FOUND AND NOT TARGET inih::INIReader) add_library(inih::INIReader ALIAS PkgConfig::INIREADER) endif()