From 7b8a5413add02004d778252c0b67bf921c1fb7d8 Mon Sep 17 00:00:00 2001 From: Alexandre Bouvier Date: Fri, 24 Feb 2023 23:45:38 +0100 Subject: cmake: support components in find modules --- CMakeModules/FindLLVM.cmake | 18 ++++++++++++++---- CMakeModules/Findhttplib.cmake | 12 +++++++++++- CMakeModules/Findinih.cmake | 19 +++++++++++++++---- 3 files changed, 40 insertions(+), 9 deletions(-) (limited to 'CMakeModules') diff --git a/CMakeModules/FindLLVM.cmake b/CMakeModules/FindLLVM.cmake index 513d9a536..efbd0ca46 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 861207eb5..48967add9 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 b8d38dcff..791befebd 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() -- cgit v1.2.3