From cf2b805ef7af14dc88514bf13c126c13d9fe66f4 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 18 Sep 2020 14:15:36 +0200 Subject: [PATCH 1/4] Try FindPkgConfig to find modules before going manual --- cmake/modules/FindGnuTLS.cmake | 100 +++++++++++++----------- cmake/modules/FindLibevent2.cmake | 70 ++++++++++------- cmake/modules/FindLibidn2.cmake | 70 ++++++++++------- cmake/modules/FindLibunbound.cmake | 108 ++++++++++++++------------ cmake/modules/FindLibuv.cmake | 78 +++++++++++-------- cmake/modules/FindNettle.cmake | 120 ++++++++++++++++------------- 6 files changed, 311 insertions(+), 235 deletions(-) diff --git a/cmake/modules/FindGnuTLS.cmake b/cmake/modules/FindGnuTLS.cmake index 961aa088..f13da9c8 100644 --- a/cmake/modules/FindGnuTLS.cmake +++ b/cmake/modules/FindGnuTLS.cmake @@ -30,51 +30,65 @@ This module will set the following variables in your project: #]=======================================================================] -find_path(GNUTLS_INCLUDE_DIR gnutls/gnutls.h - HINTS - "${GNUTLS_DIR}" - "${GNUTLS_DIR}/include" -) - -find_library(GNUTLS_LIBRARY NAMES gnutls libgnutls - HINTS - "${GNUTLS_DIR}" - "${GNUTLS_DIR}/lib" -) - -find_library(GNUTLS_DANE_LIBRARY NAMES gnutls-dane libgnutls-dane - HINTS - "${GNUTLS_DIR}" - "${GNUTLS_DIR}/lib" -) - -set(GNUTLS_LIBRARIES "") - -if (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARY AND GNUTLS_DANE_LIBRARY) - if (NOT TARGET GnuTLS::GnuTLS) - add_library(GnuTLS::GnuTLS UNKNOWN IMPORTED) - set_target_properties(GnuTLS::GnuTLS PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${GNUTLS_INCLUDE_DIR}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${GNUTLS_LIBRARY}" - ) - endif () - if (NOT TARGET GnuTLS::Dane) - add_library(GnuTLS::Dane UNKNOWN IMPORTED) - set_target_properties(GnuTLS::Dane PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${GNUTLS_INCLUDE_DIR}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${GNUTLS_DANE_LIBRARY}" - ) - endif () - - if (NOT GNUTLS_VERSION AND GNUTLS_INCLUDE_DIR) - file(STRINGS "${GNUTLS_INCLUDE_DIR}/gnutls/gnutls.h" GNUTLS_VER_H REGEX "^#define GNUTLS_VERSION_(MAJOR|MINOR|PATCH) ") - string(REGEX REPLACE "^.*_MAJOR ([0-9]+).*_MINOR ([0-9]+).*_PATCH ([0-9]+).*$" "\\1.\\2.\\3c" GNUTLS_VERSION "${GNUTLS_VER_H}") - endif () +include(FindPkgConfig) +if(PKG_CONFIG_FOUND) + pkg_check_modules(PkgGnuTLS IMPORTED_TARGET GLOBAL QUIET gnutls) + pkg_check_modules(PkgGnuTLSDane IMPORTED_TARGET GLOBAL QUIET gnutls-dane) endif() -list(APPEND GNUTLS_LIBRARIES "${GNUTLS_LIBRARY}" "${GNUTLS_DANE_LIBRARY}") +if(PkgGnuTLS_FOUND AND PkgGnuTLSDane_FOUND) + set(GNUTLS_INCLUDE_DIR ${PkgGnuTLS_INCLUDE_DIRS} $PkgGnuTLSDane_INCLUDE_DIRS}) + set(NETTLE_LIBRARIES ${PkgGnuTLS_LIBRARIES} ${PkgGnuTLSDane_LIBRARIES}) + set(NETTLE_VERSION ${PkgGnuTLS_VERSION}) + add_library(GnuTLS::GnuTLS ALIAS PkgConfig::PkgGnuTLS) + add_library(GnuTLS::Dane ALIAS PkgConfig::PkgGnuTLSDane) +else() + find_path(GNUTLS_INCLUDE_DIR gnutls/gnutls.h + HINTS + "${GNUTLS_DIR}" + "${GNUTLS_DIR}/include" + ) + + find_library(GNUTLS_LIBRARY NAMES gnutls libgnutls + HINTS + "${GNUTLS_DIR}" + "${GNUTLS_DIR}/lib" + ) + + find_library(GNUTLS_DANE_LIBRARY NAMES gnutls-dane libgnutls-dane + HINTS + "${GNUTLS_DIR}" + "${GNUTLS_DIR}/lib" + ) + + set(GNUTLS_LIBRARIES "") + + if (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARY AND GNUTLS_DANE_LIBRARY) + if (NOT TARGET GnuTLS::GnuTLS) + add_library(GnuTLS::GnuTLS UNKNOWN IMPORTED) + set_target_properties(GnuTLS::GnuTLS PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${GNUTLS_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${GNUTLS_LIBRARY}" + ) + endif () + if (NOT TARGET GnuTLS::Dane) + add_library(GnuTLS::Dane UNKNOWN IMPORTED) + set_target_properties(GnuTLS::Dane PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${GNUTLS_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${GNUTLS_DANE_LIBRARY}" + ) + endif () + + if (NOT GNUTLS_VERSION AND GNUTLS_INCLUDE_DIR) + file(STRINGS "${GNUTLS_INCLUDE_DIR}/gnutls/gnutls.h" GNUTLS_VER_H REGEX "^#define GNUTLS_VERSION_(MAJOR|MINOR|PATCH) ") + string(REGEX REPLACE "^.*_MAJOR ([0-9]+).*_MINOR ([0-9]+).*_PATCH ([0-9]+).*$" "\\1.\\2.\\3c" GNUTLS_VERSION "${GNUTLS_VER_H}") + endif () + endif() + + list(APPEND GNUTLS_LIBRARIES "${GNUTLS_LIBRARY}" "${GNUTLS_DANE_LIBRARY}") +endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GnuTLS diff --git a/cmake/modules/FindLibevent2.cmake b/cmake/modules/FindLibevent2.cmake index 9b9f2bb4..cc4437cd 100644 --- a/cmake/modules/FindLibevent2.cmake +++ b/cmake/modules/FindLibevent2.cmake @@ -28,37 +28,49 @@ This module will set the following variables in your project: #]=======================================================================] -find_path(LIBEVENT2_INCLUDE_DIR event2/event.h - HINTS - "${LIBEVENT2_DIR}" - "${LIBEVENT2_DIR}/include" -) - -find_library(LIBEVENT2_LIBRARY NAMES event_core libevent_core - HINTS - "${LIBEVENT2_DIR}" - "${LIBEVENT2_DIR}/lib" -) - -set(LIBEVENT2_LIBRARIES "") - -if (LIBEVENT2_INCLUDE_DIR AND LIBEVENT2_LIBRARY) - if (NOT TARGET Libevent2::Libevent_core) - add_library(Libevent2::Libevent_core UNKNOWN IMPORTED) - set_target_properties(Libevent2::Libevent_core PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${LIBEVENT2_INCLUDE_DIR}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${LIBEVENT2_LIBRARY}" - ) - endif () - - if (NOT LIBEVENT2_VERSION AND LIBEVENT2_INCLUDE_DIR AND EXISTS "${LIBEVENT2_INCLUDE_DIR}/event2/event.h") - file(STRINGS "${LIBEVENT2_INCLUDE_DIR}/event2/event-config.h" LIBEVENT2_H REGEX "^#define _?EVENT_+VERSION ") - string(REGEX REPLACE "^.*EVENT_+VERSION \"([^\"]+)\".*$" "\\1" LIBEVENT2_VERSION "${LIBEVENT2_H}") - endif () +include(FindPkgConfig) +if(PKG_CONFIG_FOUND) + pkg_check_modules(PkgLibevent IMPORTED_TARGET GLOBAL QUIET libevent>=2) endif() -list(APPEND LIBEVENT2_LIBRARIES "${LIBEVENT2_LIBRARY}") +if(PkgLibevent_FOUND) + set(LIBEVENT2_INCLUDE_DIR ${PkgLibevent_INCLUDE_DIRS}) + set(LIBEVENT2_LIBRARIES ${PkgLibevent_LIBRARIES}) + set(LIBEVENT2_VERSION ${PkgLibevent_VERSION}) + add_library(Libevent2::Libevent_core ALIAS PkgConfig::PkgLibevent) +else() + find_path(LIBEVENT2_INCLUDE_DIR event2/event.h + HINTS + "${LIBEVENT2_DIR}" + "${LIBEVENT2_DIR}/include" + ) + + find_library(LIBEVENT2_LIBRARY NAMES event_core libevent_core + HINTS + "${LIBEVENT2_DIR}" + "${LIBEVENT2_DIR}/lib" + ) + + set(LIBEVENT2_LIBRARIES "") + + if (LIBEVENT2_INCLUDE_DIR AND LIBEVENT2_LIBRARY) + if (NOT TARGET Libevent2::Libevent_core) + add_library(Libevent2::Libevent_core UNKNOWN IMPORTED) + set_target_properties(Libevent2::Libevent_core PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBEVENT2_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${LIBEVENT2_LIBRARY}" + ) + endif () + + if (NOT LIBEVENT2_VERSION AND LIBEVENT2_INCLUDE_DIR AND EXISTS "${LIBEVENT2_INCLUDE_DIR}/event2/event.h") + file(STRINGS "${LIBEVENT2_INCLUDE_DIR}/event2/event-config.h" LIBEVENT2_H REGEX "^#define _?EVENT_+VERSION ") + string(REGEX REPLACE "^.*EVENT_+VERSION \"([^\"]+)\".*$" "\\1" LIBEVENT2_VERSION "${LIBEVENT2_H}") + endif () + endif() + + list(APPEND LIBEVENT2_LIBRARIES "${LIBEVENT2_LIBRARY}") +endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Libevent2 diff --git a/cmake/modules/FindLibidn2.cmake b/cmake/modules/FindLibidn2.cmake index 4ea374f5..1b49ef3c 100644 --- a/cmake/modules/FindLibidn2.cmake +++ b/cmake/modules/FindLibidn2.cmake @@ -28,37 +28,49 @@ This module will set the following variables in your project: #]=======================================================================] -find_path(LIBIDN2_INCLUDE_DIR idn2.h - HINTS - "${LIBIDN2_DIR}" - "${LIBIDN2_DIR}/include" -) - -find_library(LIBIDN2_LIBRARY NAMES idn2 libidn2 - HINTS - "${LIBIDN2_DIR}" - "${LIBIDN2_DIR}/lib" -) - -set(LIBIDN2_LIBRARIES "") - -if (LIBIDN2_INCLUDE_DIR AND LIBIDN2_LIBRARY) - if (NOT TARGET Libidn2::Libidn2) - add_library(Libidn2::Libidn2 UNKNOWN IMPORTED) - set_target_properties(Libidn2::Libidn2 PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${LIBIDN2_INCLUDE_DIR}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${LIBIDN2_LIBRARY}" - ) - endif () - - if (NOT LIBIDN2_VERSION AND LIBIDN2_INCLUDE_DIR AND EXISTS "${LIBIDN2_INCLUDE_DIR}/unbound.h") - file(STRINGS "${LIBIDN2_INCLUDE_DIR}/idn2.h" LIBIDN2_H REGEX "^#define IDN2_VERSION ") - string(REGEX REPLACE "^.*IDN2_VERSION \"([0-9.]+)\".*$" "\\1" LIBIDN2_VERSION "${LIBIDN2_H}") - endif () +include(FindPkgConfig) +if(PKG_CONFIG_FOUND) + pkg_check_modules(PkgLibIdn2 IMPORTED_TARGET GLOBAL libidn2) endif() -list(APPEND LIBIDN2_LIBRARIES "${LIBIDN2_LIBRARY}") +if(PkgLibIdn2_FOUND) + set(LIBIDN2_INCLUDE_DIR ${PkgLibIdn2_INCLUDE_DIRS}) + set(LIBIDN2_LIBRARIES ${PkgLibIdn2_LIBRARIES}) + set(LIBIDN2_VERSION ${PkgLibIdn2_VERSION}) + add_library(Libidn2::Libidn2 ALIAS PkgConfig::PkgLibIdn2) +else() + find_path(LIBIDN2_INCLUDE_DIR idn2.h + HINTS + "${LIBIDN2_DIR}" + "${LIBIDN2_DIR}/include" + ) + + find_library(LIBIDN2_LIBRARY NAMES idn2 libidn2 + HINTS + "${LIBIDN2_DIR}" + "${LIBIDN2_DIR}/lib" + ) + + set(LIBIDN2_LIBRARIES "") + + if (LIBIDN2_INCLUDE_DIR AND LIBIDN2_LIBRARY) + if (NOT TARGET Libidn2::Libidn2) + add_library(Libidn2::Libidn2 UNKNOWN IMPORTED) + set_target_properties(Libidn2::Libidn2 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBIDN2_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${LIBIDN2_LIBRARY}" + ) + endif () + + if (NOT LIBIDN2_VERSION AND LIBIDN2_INCLUDE_DIR AND EXISTS "${LIBIDN2_INCLUDE_DIR}/unbound.h") + file(STRINGS "${LIBIDN2_INCLUDE_DIR}/idn2.h" LIBIDN2_H REGEX "^#define IDN2_VERSION ") + string(REGEX REPLACE "^.*IDN2_VERSION \"([0-9.]+)\".*$" "\\1" LIBIDN2_VERSION "${LIBIDN2_H}") + endif () + + list(APPEND LIBIDN2_LIBRARIES "${LIBIDN2_LIBRARY}") + endif() +endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Libidn2 diff --git a/cmake/modules/FindLibunbound.cmake b/cmake/modules/FindLibunbound.cmake index bdef88be..86f01309 100644 --- a/cmake/modules/FindLibunbound.cmake +++ b/cmake/modules/FindLibunbound.cmake @@ -28,58 +28,70 @@ This module will set the following variables in your project: #]=======================================================================] -find_path(LIBUNBOUND_INCLUDE_DIR unbound.h - HINTS - "${LIBUNBOUND_DIR}" - "${LIBUNBOUND_DIR}/include" -) - -find_library(LIBUNBOUND_LIBRARY NAMES unbound - HINTS - "${LIBUNBOUND_DIR}" - "${LIBUNBOUND_DIR}/lib" -) - -set(LIBUNBOUND_LIBRARIES "") - -if (UNIX) - find_package(Threads REQUIRED) - find_package(OpenSSL REQUIRED) - - list(APPEND LIBUNBOUND_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") - list(APPEND LIBUNBOUND_LIBRARIES "${OPENSSL_LIBRARIES}") +include(FindPkgConfig) +if(PKG_CONFIG_FOUND) + pkg_check_modules(PkgLibunbound IMPORTED_TARGET GLOBAL QUIET libunbound) endif() -if (LIBUNBOUND_INCLUDE_DIR AND LIBUNBOUND_LIBRARY) - if (NOT TARGET Libunbound::Libunbound) - add_library(Libunbound::Libunbound UNKNOWN IMPORTED) - set_target_properties(Libunbound::Libunbound PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${LIBUNBOUND_INCLUDE_DIR}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${LIBUNBOUND_LIBRARY}" - ) - - if(UNIX AND TARGET Threads::Threads) - set_property(TARGET Libunbound::Libunbound APPEND PROPERTY - INTERFACE_LINK_LIBRARIES Threads::Threads) +if(PkgLibunbound_FOUND) + set(LIBUNBOUND_INCLUDE_DIR ${PkgLibunbound_INCLUDE_DIRS}) + set(LIBUNBOUND_LIBRARIES ${PkgLibunbound_LIBRARIES}) + set(LIBUNBOUND_VERSION ${PkgLibunbound_VERSION}) + add_library(Libunbound::Libunbound ALIAS PkgConfig::PkgLibunbound) +else() + find_path(LIBUNBOUND_INCLUDE_DIR unbound.h + HINTS + "${LIBUNBOUND_DIR}" + "${LIBUNBOUND_DIR}/include" + ) + + find_library(LIBUNBOUND_LIBRARY NAMES unbound + HINTS + "${LIBUNBOUND_DIR}" + "${LIBUNBOUND_DIR}/lib" + ) + + set(LIBUNBOUND_LIBRARIES "") + + if (UNIX) + find_package(Threads REQUIRED) + find_package(OpenSSL REQUIRED) + + list(APPEND LIBUNBOUND_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") + list(APPEND LIBUNBOUND_LIBRARIES "${OPENSSL_LIBRARIES}") + endif() + + if (LIBUNBOUND_INCLUDE_DIR AND LIBUNBOUND_LIBRARY) + if (NOT TARGET Libunbound::Libunbound) + add_library(Libunbound::Libunbound UNKNOWN IMPORTED) + set_target_properties(Libunbound::Libunbound PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBUNBOUND_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${LIBUNBOUND_LIBRARY}" + ) + + if(UNIX AND TARGET Threads::Threads) + set_property(TARGET Libunbound::Libunbound APPEND PROPERTY + INTERFACE_LINK_LIBRARIES Threads::Threads) + endif () + if(UNIX AND TARGET OpenSSL::SSL) + set_property(TARGET Libunbound::Libunbound APPEND PROPERTY + INTERFACE_LINK_LIBRARIES OpenSSL::SSL) + endif () + if(UNIX AND TARGET OpenSSL::Crypto) + set_property(TARGET Libunbound::Libunbound APPEND PROPERTY + INTERFACE_LINK_LIBRARIES OpenSSL::Crypto) + endif () endif () - if(UNIX AND TARGET OpenSSL::SSL) - set_property(TARGET Libunbound::Libunbound APPEND PROPERTY - INTERFACE_LINK_LIBRARIES OpenSSL::SSL) + + if (NOT LIBUNBOUND_VERSION AND LIBUNBOUND_INCLUDE_DIR AND EXISTS "${LIBUNBOUND_INCLUDE_DIR}/unbound.h") + file(STRINGS "${LIBUNBOUND_INCLUDE_DIR}/unbound.h" LIBUNBOUND_H REGEX "^#define UNBOUND_VERSION_M[A-Z]+") + string(REGEX REPLACE "^.*MAJOR ([0-9]+).*MINOR ([0-9]+).*MICRO ([0-9]+).*$" "\\1.\\2.\\3" LIBUNBOUND_VERSION "${LIBUNBOUND_H}") endif () - if(UNIX AND TARGET OpenSSL::Crypto) - set_property(TARGET Libunbound::Libunbound APPEND PROPERTY - INTERFACE_LINK_LIBRARIES OpenSSL::Crypto) - endif () - endif () - - if (NOT LIBUNBOUND_VERSION AND LIBUNBOUND_INCLUDE_DIR AND EXISTS "${LIBUNBOUND_INCLUDE_DIR}/unbound.h") - file(STRINGS "${LIBUNBOUND_INCLUDE_DIR}/unbound.h" LIBUNBOUND_H REGEX "^#define UNBOUND_VERSION_M[A-Z]+") - string(REGEX REPLACE "^.*MAJOR ([0-9]+).*MINOR ([0-9]+).*MICRO ([0-9]+).*$" "\\1.\\2.\\3" LIBUNBOUND_VERSION "${LIBUNBOUND_H}") - endif () -endif() - -list(APPEND LIBUNBOUND_LIBRARIES "${LIBUNBOUND_LIBRARY}") + endif() + + list(APPEND LIBUNBOUND_LIBRARIES "${LIBUNBOUND_LIBRARY}") +endif include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Libunbound diff --git a/cmake/modules/FindLibuv.cmake b/cmake/modules/FindLibuv.cmake index 749697aa..b6edeb09 100644 --- a/cmake/modules/FindLibuv.cmake +++ b/cmake/modules/FindLibuv.cmake @@ -28,41 +28,53 @@ This module will set the following variables in your project: #]=======================================================================] -find_path(LIBUV_INCLUDE_DIR uv.h - HINTS - "${LIBUV_DIR}" - "${LIBUV_DIR}/include" -) - -find_library(LIBUV_LIBRARY NAMES uv libuv - HINTS - "${LIBUV_DIR}" - "${LIBUV_DIR}/lib" -) - -set(LIBUV_LIBRARIES "") - -if (LIBUV_INCLUDE_DIR AND LIBUV_LIBRARY) - if (NOT TARGET Libuv::Libuv) - add_library(Libuv::Libuv UNKNOWN IMPORTED) - set_target_properties(Libuv::Libuv PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${LIBUV_INCLUDE_DIR}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${LIBUV_LIBRARY}" - ) - endif () - - if (NOT LIBUV_VERSION AND LIBUV_INCLUDE_DIR) - if (EXISTS "${LIBUV_INCLUDE_DIR}/uv-version.h") - file(STRINGS "${LIBUV_INCLUDE_DIR}/uv-version.h" LIBUV_VER_H REGEX "^#define UV_VERSION_(MAJOR|MINOR|PATCH) ") - elseif (EXISTS "${LIBUV_INCLUDE_DIR}/uv/version.h") - file(STRINGS "${LIBUV_INCLUDE_DIR}/uv/version.h" LIBUV_VER_H REGEX "^#define UV_VERSION_(MAJOR|MINOR|PATCH) ") - endif () - string(REGEX REPLACE "^.*_MAJOR ([0-9]+).*_MINOR ([0-9]+).*_PATCH ([0-9]+).*$" "\\1.\\2.\\3" LIBUV_VERSION "${LIBUV_VER_H}") - endif () +include(FindPkgConfig) +if(PKG_CONFIG_FOUND) + pkg_check_modules(PkgLibuv IMPORTED_TARGET GLOBAL QUIET libuv) endif() -list(APPEND LIBUV_LIBRARIES "${LIBUV_LIBRARY}") +if(PkgLibuv_FOUND) + set(LIBUV_INCLUDE_DIR ${PkgLibuv_INCLUDE_DIRS}) + set(LIBUV_LIBRARIES ${PkgLibuv_LIBRARIES}) + set(LIBUV_VERSION ${PkgLibuv_VERSION}) + add_library(Libuv::Libuv ALIAS PkgConfig::PkgLibuv) +else() + find_path(LIBUV_INCLUDE_DIR uv.h + HINTS + "${LIBUV_DIR}" + "${LIBUV_DIR}/include" + ) + + find_library(LIBUV_LIBRARY NAMES uv libuv + HINTS + "${LIBUV_DIR}" + "${LIBUV_DIR}/lib" + ) + + set(LIBUV_LIBRARIES "") + + if (LIBUV_INCLUDE_DIR AND LIBUV_LIBRARY) + if (NOT TARGET Libuv::Libuv) + add_library(Libuv::Libuv UNKNOWN IMPORTED) + set_target_properties(Libuv::Libuv PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBUV_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${LIBUV_LIBRARY}" + ) + endif () + + if (NOT LIBUV_VERSION AND LIBUV_INCLUDE_DIR) + if (EXISTS "${LIBUV_INCLUDE_DIR}/uv-version.h") + file(STRINGS "${LIBUV_INCLUDE_DIR}/uv-version.h" LIBUV_VER_H REGEX "^#define UV_VERSION_(MAJOR|MINOR|PATCH) ") + elseif (EXISTS "${LIBUV_INCLUDE_DIR}/uv/version.h") + file(STRINGS "${LIBUV_INCLUDE_DIR}/uv/version.h" LIBUV_VER_H REGEX "^#define UV_VERSION_(MAJOR|MINOR|PATCH) ") + endif () + string(REGEX REPLACE "^.*_MAJOR ([0-9]+).*_MINOR ([0-9]+).*_PATCH ([0-9]+).*$" "\\1.\\2.\\3" LIBUV_VERSION "${LIBUV_VER_H}") + endif () + endif() + + list(APPEND LIBUV_LIBRARIES "${LIBUV_LIBRARY}") +endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Libuv diff --git a/cmake/modules/FindNettle.cmake b/cmake/modules/FindNettle.cmake index 3303b4b5..900148de 100644 --- a/cmake/modules/FindNettle.cmake +++ b/cmake/modules/FindNettle.cmake @@ -30,61 +30,75 @@ This module will set the following variables in your project: #]=======================================================================] -find_path(NETTLE_INCLUDE_DIR nettle/version.h - HINTS - "${NETTLE_DIR}" - "${NETTLE_DIR}/include" -) - -find_library(NETTLE_LIBRARY NAMES nettle libnettle - HINTS - "${NETTLE_DIR}" - "${NETTLE_DIR}/lib" -) - -find_library(HOGWEED_LIBRARY NAMES hogweed libhogweed - HINTS - "${NETTLE_DIR}" - "${NETTLE_DIR}/lib" -) - -set(NETTLE_LIBRARIES "") - -# May need gmp library on Unix. -if (UNIX) - find_library(NETTLE_GMP_LIBRARY gmp) - - if (NETTLE_GMP_LIBRARY) - list(APPEND NETTLE_LIBRARIES "${NETTLE_GMP_LIBRARY}") - endif () -endif () - -if (NETTLE_INCLUDE_DIR AND NETTLE_LIBRARY AND HOGWEED_LIBRARY) - if (NOT TARGET Nettle::Nettle) - add_library(Nettle::Nettle UNKNOWN IMPORTED) - set_target_properties(Nettle::Nettle PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${NETTLE_INCLUDE_DIR}" - INTERFACE_LINK_LIBRARIES "${NETTLE_LIBRARIES}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${NETTLE_LIBRARY}" - ) - endif () - if (NOT TARGET Nettle::Hogweed) - add_library(Nettle::Hogweed UNKNOWN IMPORTED) - set_target_properties(Nettle::Hogweed PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${NETTLE_INCLUDE_DIR}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${HOGWEED_LIBRARY}" - ) - endif () - - if (NOT NETTLE_VERSION AND NETTLE_INCLUDE_DIR) - file(STRINGS "${NETTLE_INCLUDE_DIR}/nettle/version.h" NETTLE_VER_H REGEX "^#define NETTLE_VERSION_(MAJOR|MINOR) ") - string(REGEX REPLACE "^.*_MAJOR ([0-9]+).*_MINOR ([0-9]+).*$" "\\1.\\2" NETTLE_VERSION "${NETTLE_VER_H}") - endif () +include(FindPkgConfig) +if(PKG_CONFIG_FOUND) + pkg_check_modules(PkgNettle IMPORTED_TARGET GLOBAL nettle) + pkg_check_modules(PkgHogweed IMPORTED_TARGET GLOBAL QUIET hogweed) endif() -list(APPEND NETTLE_LIBRARIES "${NETTLE_LIBRARY}" "${HOGWEED_LIBRARY}") +if(PkgNettle_FOUND AND PkHogweed_FOUND) + set(NETTLE_INCLUDE_DIR ${PkgNettle_INCLUDE_DIRS} ${PkgHogweed_INCLUDE_DIRS}) + set(NETTLE_LIBRARIES ${PkgNettle_LIBRARIES} ${PkgHogweed_LIBRARIES}) + set(NETTLE_VERSION ${PkgNettle_VERSION}) + add_library(Nettle::Nettle ALIAS PkgConfig::PkgNettle) + add_library(Nettle::Hogweed ALIAS PkgConfig::PkgHogweed) +else() + find_path(NETTLE_INCLUDE_DIR nettle/version.h + HINTS + "${NETTLE_DIR}" + "${NETTLE_DIR}/include" + ) + + find_library(NETTLE_LIBRARY NAMES nettle libnettle + HINTS + "${NETTLE_DIR}" + "${NETTLE_DIR}/lib" + ) + + find_library(HOGWEED_LIBRARY NAMES hogweed libhogweed + HINTS + "${NETTLE_DIR}" + "${NETTLE_DIR}/lib" + ) + + set(NETTLE_LIBRARIES "") + + # May need gmp library on Unix. + if (UNIX) + find_library(NETTLE_GMP_LIBRARY gmp) + + if (NETTLE_GMP_LIBRARY) + list(APPEND NETTLE_LIBRARIES "${NETTLE_GMP_LIBRARY}") + endif () + endif () + + if (NETTLE_INCLUDE_DIR AND NETTLE_LIBRARY AND HOGWEED_LIBRARY) + if (NOT TARGET Nettle::Nettle) + add_library(Nettle::Nettle UNKNOWN IMPORTED) + set_target_properties(Nettle::Nettle PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${NETTLE_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${NETTLE_LIBRARIES}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${NETTLE_LIBRARY}" + ) + endif () + if (NOT TARGET Nettle::Hogweed) + add_library(Nettle::Hogweed UNKNOWN IMPORTED) + set_target_properties(Nettle::Hogweed PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${NETTLE_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${HOGWEED_LIBRARY}" + ) + endif () + + if (NOT NETTLE_VERSION AND NETTLE_INCLUDE_DIR) + file(STRINGS "${NETTLE_INCLUDE_DIR}/nettle/version.h" NETTLE_VER_H REGEX "^#define NETTLE_VERSION_(MAJOR|MINOR) ") + string(REGEX REPLACE "^.*_MAJOR ([0-9]+).*_MINOR ([0-9]+).*$" "\\1.\\2" NETTLE_VERSION "${NETTLE_VER_H}") + endif () + endif() + + list(APPEND NETTLE_LIBRARIES "${NETTLE_LIBRARY}" "${HOGWEED_LIBRARY}") +endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Nettle From f92f97bf1e10d11cfaa561a6d373a0fc3e49657c Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 18 Sep 2020 14:16:06 +0200 Subject: [PATCH 2/4] Findlibidn module is not available --- CMakeLists.txt | 9 --------- cmake/modules/FindLibunbound.cmake | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bac3a089..e9d991aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -684,9 +684,6 @@ if (NOT HAVE_SSL_DANE_ENABLE) target_include_directories(getdns_objects PRIVATE src/ssl_dane) set(USE_DANESSL 1) endif () -if (Libidn_FOUND) - target_include_directories(getdns_objects PRIVATE ${LIBIDN_INCLUDE_DIR}) -endif () if (Libidn2_FOUND) target_include_directories(getdns_objects PRIVATE ${LIBIDN2_INCLUDE_DIR}) endif () @@ -720,9 +717,6 @@ if (ENABLE_STATIC) if (Libunbound_FOUND) target_link_libraries(getdns PUBLIC Libunbound::Libunbound) endif () - if (Libidn_FOUND) - target_link_libraries(getdns PUBLIC Libidn::Libidn) - endif () if (Libidn2_FOUND) target_link_libraries(getdns PUBLIC Libidn2::Libidn2) endif () @@ -752,9 +746,6 @@ if (ENABLE_SHARED) if (Libunbound_FOUND) target_link_libraries(getdns_shared PUBLIC Libunbound::Libunbound) endif () - if (Libidn_FOUND) - target_link_libraries(getdns_shared PUBLIC Libidn::Libidn) - endif () if (Libidn2_FOUND) target_link_libraries(getdns_shared PUBLIC Libidn2::Libidn2) endif () diff --git a/cmake/modules/FindLibunbound.cmake b/cmake/modules/FindLibunbound.cmake index 86f01309..2b4c249e 100644 --- a/cmake/modules/FindLibunbound.cmake +++ b/cmake/modules/FindLibunbound.cmake @@ -91,7 +91,7 @@ else() endif() list(APPEND LIBUNBOUND_LIBRARIES "${LIBUNBOUND_LIBRARY}") -endif +endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Libunbound From 6eb1a6790a372a8b4a01757210e62959d1c7e663 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 28 May 2021 16:03:30 +0200 Subject: [PATCH 3/4] cmake: don't call find_package_handle_standard_args when using pkg_config + cache variables --- cmake/modules/FindCheck.cmake | 124 ++++++++++++++++------------- cmake/modules/FindGnuTLS.cmake | 38 ++++----- cmake/modules/FindLibevent2.cmake | 39 +++++---- cmake/modules/FindLibidn2.cmake | 40 +++++----- cmake/modules/FindLibunbound.cmake | 40 +++++----- cmake/modules/FindLibuv.cmake | 33 ++++---- cmake/modules/FindNettle.cmake | 38 ++++----- 7 files changed, 182 insertions(+), 170 deletions(-) diff --git a/cmake/modules/FindCheck.cmake b/cmake/modules/FindCheck.cmake index 81872b8b..ff404c14 100644 --- a/cmake/modules/FindCheck.cmake +++ b/cmake/modules/FindCheck.cmake @@ -28,71 +28,87 @@ This module will set the following variables in your project: #]=======================================================================] -find_path(CHECK_INCLUDE_DIR check.h - HINTS - "${CHECK_DIR}" - "${CHECK_DIR}/include" - ) +find_package(PkgConfig QUIET) +if (PKG_CONFIG_FOUND) + pkg_check_modules(PkgCheck IMPORTED_TARGET GLOBAL check) +endif () -# Check for PIC and non-PIC libraries. If PIC present, use that -# in preference (as per Debian check.pc). -find_library(CHECK_LIBRARY NAMES check_pic libcheck_pic - HINTS - "${CHECK_DIR}" - "${CHECK_DIR}/lib" - ) +if (PkgCheck_FOUND) + set(CHECK_INCLUDE_DIR ${PkgCheck_INCLUDE_DIRS} CACHE FILEPATH "check include path") + set(CHECK_LIBRARIES ${PkgCheck_LIBRARIES} CACHE STRING "check libraries") + set(CHECK_VERSION ${PkgCheck_VERSION}) + add_library(Check::Check ALIAS PkgConfig::PkgCheck) + set(Check_FOUND ON) +else () + find_path(CHECK_INCLUDE_DIR check.h + HINTS + "${CHECK_DIR}" + "${CHECK_DIR}/include" + ) -if (NOT CHECK_LIBRARY) - find_library(CHECK_LIBRARY NAMES check libcheck + # Check for PIC and non-PIC libraries. If PIC present, use that + # in preference (as per Debian check.pc). + find_library(CHECK_LIBRARY NAMES check_pic libcheck_pic HINTS "${CHECK_DIR}" "${CHECK_DIR}/lib" ) -endif () -set(CHECK_LIBRARIES "") - -# Check may need the math, subunit and rt libraries on Unix -if (UNIX) - find_library(CHECK_MATH_LIBRARY m) - find_library(CHECK_RT_LIBRARY rt) - find_library(CHECK_SUBUNIT_LIBRARY subunit) - - if (CHECK_MATH_LIBRARY) - list(APPEND CHECK_LIBRARIES "${CHECK_MATH_LIBRARY}") - endif () - if (CHECK_RT_LIBRARY) - list(APPEND CHECK_LIBRARIES "${CHECK_RT_LIBRARY}") - endif () - if (CHECK_SUBUNIT_LIBRARY) - list(APPEND CHECK_LIBRARIES "${CHECK_SUBUNIT_LIBRARY}") - endif () -endif() - -if (CHECK_INCLUDE_DIR AND CHECK_LIBRARY) - if (NOT TARGET Check::Check) - add_library(Check::Check UNKNOWN IMPORTED) - set_target_properties(Check::Check PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${CHECK_INCLUDE_DIR}" - INTERFACE_LINK_LIBRARIES "${CHECK_LIBRARIES}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${CHECK_LIBRARY}" + if (NOT CHECK_LIBRARY) + find_library(CHECK_LIBRARY NAMES check libcheck + HINTS + "${CHECK_DIR}" + "${CHECK_DIR}/lib" ) endif () - if (NOT CHECK_VERSION AND CHECK_INCLUDE_DIR AND EXISTS "${CHECK_INCLUDE_DIR}/check.h") - file(STRINGS "${CHECK_INCLUDE_DIR}/check.h" CHECK_H REGEX "^#define CHECK_M[A-Z]+_VERSION") - string(REGEX REPLACE "^.*\(([0-9]+)\).*\(([0-9]+)\).*\(([0-9]+)\).*$" "\\1.\\2.\\3" CHECK_VERSION "${CHECK_H}") - endif () + set(_CHECK_LIBARIES "") + + # Check may need the math, subunit and rt libraries on Unix + if (UNIX) + find_library(CHECK_MATH_LIBRARY m) + find_library(CHECK_RT_LIBRARY rt) + find_library(CHECK_SUBUNIT_LIBRARY subunit) + + if (CHECK_MATH_LIBRARY) + list(APPEND _CHECK_LIBARIES "${CHECK_MATH_LIBRARY}") + endif () + if (CHECK_RT_LIBRARY) + list(APPEND _CHECK_LIBARIES "${CHECK_RT_LIBRARY}") + endif () + if (CHECK_SUBUNIT_LIBRARY) + list(APPEND _CHECK_LIBARIES "${CHECK_SUBUNIT_LIBRARY}") + endif () + endif() + + set(CHECK_LIBRARIES ${_CHECK_LIBARIES} ${CHECK_LIBRARY} CACHE STRING "check libraries") + + if (CHECK_INCLUDE_DIR AND CHECK_LIBRARY) + if (NOT TARGET Check::Check) + add_library(Check::Check UNKNOWN IMPORTED) + set_target_properties(Check::Check PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CHECK_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${CHECK_LIBRARIES}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${CHECK_LIBRARY}" + ) + endif () + + if (NOT CHECK_VERSION AND CHECK_INCLUDE_DIR AND EXISTS "${CHECK_INCLUDE_DIR}/check.h") + file(STRINGS "${CHECK_INCLUDE_DIR}/check.h" CHECK_H REGEX "^#define CHECK_M[A-Z]+_VERSION") + string(REGEX REPLACE "^.*\(([0-9]+)\).*\(([0-9]+)\).*\(([0-9]+)\).*$" "\\1.\\2.\\3" CHECK_VERSION "${CHECK_H}") + endif () + endif() + + list(APPEND CHECK_LIBRARIES "${CHECK_LIBRARY}") + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Check + REQUIRED_VARS CHECK_LIBRARIES CHECK_INCLUDE_DIR + VERSION_VAR CHECK_VERSION + ) + endif() -list(APPEND CHECK_LIBRARIES "${CHECK_LIBRARY}") - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Check - REQUIRED_VARS CHECK_LIBRARIES CHECK_INCLUDE_DIR - VERSION_VAR CHECK_VERSION - ) - mark_as_advanced(CHECK_INCLUDE_DIR CHECK_LIBRARIES CHECK_LIBRARY CHECK_MATH_LIBRARY CHECK_RT_LIBRARY CHECK_SUBUNIT_LIBRARY) diff --git a/cmake/modules/FindGnuTLS.cmake b/cmake/modules/FindGnuTLS.cmake index f13da9c8..7df6ab17 100644 --- a/cmake/modules/FindGnuTLS.cmake +++ b/cmake/modules/FindGnuTLS.cmake @@ -30,19 +30,20 @@ This module will set the following variables in your project: #]=======================================================================] -include(FindPkgConfig) -if(PKG_CONFIG_FOUND) - pkg_check_modules(PkgGnuTLS IMPORTED_TARGET GLOBAL QUIET gnutls) - pkg_check_modules(PkgGnuTLSDane IMPORTED_TARGET GLOBAL QUIET gnutls-dane) -endif() +find_package(PkgConfig QUIET) +if (PKG_CONFIG_FOUND) + pkg_check_modules(PkgGnuTLS IMPORTED_TARGET GLOBAL QUIET gnutls) + pkg_check_modules(PkgGnuTLSDane IMPORTED_TARGET GLOBAL QUIET gnutls-dane) +endif () -if(PkgGnuTLS_FOUND AND PkgGnuTLSDane_FOUND) - set(GNUTLS_INCLUDE_DIR ${PkgGnuTLS_INCLUDE_DIRS} $PkgGnuTLSDane_INCLUDE_DIRS}) - set(NETTLE_LIBRARIES ${PkgGnuTLS_LIBRARIES} ${PkgGnuTLSDane_LIBRARIES}) +if (PkgGnuTLS_FOUND AND PkgGnuTLSDane_FOUND) + set(GNUTLS_INCLUDE_DIR ${PkgGnuTLS_INCLUDE_DIRS} $PkgGnuTLSDane_INCLUDE_DIRS} CACHE FILEPATH "GnuTLS include path") + set(NETTLE_LIBRARIES ${PkgGnuTLS_LIBRARIES} ${PkgGnuTLSDane_LIBRARIES} CACHE STRING "GnuTLS libraries") set(NETTLE_VERSION ${PkgGnuTLS_VERSION}) add_library(GnuTLS::GnuTLS ALIAS PkgConfig::PkgGnuTLS) add_library(GnuTLS::Dane ALIAS PkgConfig::PkgGnuTLSDane) -else() + set(GnuTLS_FOUND ON) +else () find_path(GNUTLS_INCLUDE_DIR gnutls/gnutls.h HINTS "${GNUTLS_DIR}" @@ -61,7 +62,7 @@ else() "${GNUTLS_DIR}/lib" ) - set(GNUTLS_LIBRARIES "") + set(_GNUTLS_LIBRARIES "") if (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARY AND GNUTLS_DANE_LIBRARY) if (NOT TARGET GnuTLS::GnuTLS) @@ -85,15 +86,16 @@ else() file(STRINGS "${GNUTLS_INCLUDE_DIR}/gnutls/gnutls.h" GNUTLS_VER_H REGEX "^#define GNUTLS_VERSION_(MAJOR|MINOR|PATCH) ") string(REGEX REPLACE "^.*_MAJOR ([0-9]+).*_MINOR ([0-9]+).*_PATCH ([0-9]+).*$" "\\1.\\2.\\3c" GNUTLS_VERSION "${GNUTLS_VER_H}") endif () - endif() + endif () - list(APPEND GNUTLS_LIBRARIES "${GNUTLS_LIBRARY}" "${GNUTLS_DANE_LIBRARY}") -endif() + list(APPEND _GNUTLS_LIBRARIES "${GNUTLS_LIBRARY}" "${GNUTLS_DANE_LIBRARY}") + set(GNUTLS_LIBRARIES ${_GNUTLS_LIBRARIES} CACHE STRING "GnuTLS libraries") -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(GnuTLS - REQUIRED_VARS GNUTLS_LIBRARIES GNUTLS_INCLUDE_DIR - VERSION_VAR GNUTLS_VERSION - ) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(GnuTLS + REQUIRED_VARS GNUTLS_LIBRARIES GNUTLS_INCLUDE_DIR + VERSION_VAR GNUTLS_VERSION + ) +endif () mark_as_advanced(GNUTLS_INCLUDE_DIR GNUTLS_LIBRARIES GNUTLS_LIBRARY GNUTLS_DANE_LIBRARY) diff --git a/cmake/modules/FindLibevent2.cmake b/cmake/modules/FindLibevent2.cmake index cc4437cd..b84dfa59 100644 --- a/cmake/modules/FindLibevent2.cmake +++ b/cmake/modules/FindLibevent2.cmake @@ -28,38 +28,37 @@ This module will set the following variables in your project: #]=======================================================================] -include(FindPkgConfig) -if(PKG_CONFIG_FOUND) +find_package(PkgConfig QUIET) +if (PKG_CONFIG_FOUND) pkg_check_modules(PkgLibevent IMPORTED_TARGET GLOBAL QUIET libevent>=2) -endif() +endif () -if(PkgLibevent_FOUND) - set(LIBEVENT2_INCLUDE_DIR ${PkgLibevent_INCLUDE_DIRS}) - set(LIBEVENT2_LIBRARIES ${PkgLibevent_LIBRARIES}) +if (PkgLibevent_FOUND) + set(LIBEVENT2_INCLUDE_DIR ${PkgLibevent_INCLUDE_DIRS} CACHE FILEPATH "libevent2 include path") + set(LIBEVENT2_LIBRARIES ${PkgLibevent_LIBRARIES} CACHE STRING "libevent2 libraries") set(LIBEVENT2_VERSION ${PkgLibevent_VERSION}) add_library(Libevent2::Libevent_core ALIAS PkgConfig::PkgLibevent) -else() + set(Libevent2_FOUND ON) +else () find_path(LIBEVENT2_INCLUDE_DIR event2/event.h HINTS "${LIBEVENT2_DIR}" "${LIBEVENT2_DIR}/include" ) - find_library(LIBEVENT2_LIBRARY NAMES event_core libevent_core + find_library(LIBEVENT2_LIBRARIES NAMES event_core libevent_core HINTS "${LIBEVENT2_DIR}" "${LIBEVENT2_DIR}/lib" ) - set(LIBEVENT2_LIBRARIES "") - - if (LIBEVENT2_INCLUDE_DIR AND LIBEVENT2_LIBRARY) + if (LIBEVENT2_INCLUDE_DIR AND LIBEVENT2_LIBRARIES) if (NOT TARGET Libevent2::Libevent_core) add_library(Libevent2::Libevent_core UNKNOWN IMPORTED) set_target_properties(Libevent2::Libevent_core PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBEVENT2_INCLUDE_DIR}" IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${LIBEVENT2_LIBRARY}" + IMPORTED_LOCATION "${LIBEVENT2_LIBRARIES}" ) endif () @@ -67,15 +66,13 @@ else() file(STRINGS "${LIBEVENT2_INCLUDE_DIR}/event2/event-config.h" LIBEVENT2_H REGEX "^#define _?EVENT_+VERSION ") string(REGEX REPLACE "^.*EVENT_+VERSION \"([^\"]+)\".*$" "\\1" LIBEVENT2_VERSION "${LIBEVENT2_H}") endif () - endif() - - list(APPEND LIBEVENT2_LIBRARIES "${LIBEVENT2_LIBRARY}") -endif() + endif () -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Libevent2 - REQUIRED_VARS LIBEVENT2_LIBRARIES LIBEVENT2_INCLUDE_DIR - VERSION_VAR LIBEVENT2_VERSION + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Libevent2 + REQUIRED_VARS LIBEVENT2_LIBRARIES LIBEVENT2_INCLUDE_DIR + VERSION_VAR LIBEVENT2_VERSION ) +endif () -mark_as_advanced(LIBEVENT2_INCLUDE_DIR LIBEVENT2_LIBRARIES LIBEVENT2_LIBRARY) +mark_as_advanced(LIBEVENT2_INCLUDE_DIR LIBEVENT2_LIBRARIES) diff --git a/cmake/modules/FindLibidn2.cmake b/cmake/modules/FindLibidn2.cmake index 1b49ef3c..d597dc0f 100644 --- a/cmake/modules/FindLibidn2.cmake +++ b/cmake/modules/FindLibidn2.cmake @@ -28,38 +28,37 @@ This module will set the following variables in your project: #]=======================================================================] -include(FindPkgConfig) -if(PKG_CONFIG_FOUND) +find_package(PkgConfig QUIET) +if (PKG_CONFIG_FOUND) pkg_check_modules(PkgLibIdn2 IMPORTED_TARGET GLOBAL libidn2) -endif() +endif () -if(PkgLibIdn2_FOUND) - set(LIBIDN2_INCLUDE_DIR ${PkgLibIdn2_INCLUDE_DIRS}) - set(LIBIDN2_LIBRARIES ${PkgLibIdn2_LIBRARIES}) +if (PkgLibIdn2_FOUND) + set(LIBIDN2_INCLUDE_DIR ${PkgLibIdn2_INCLUDE_DIRS} CACHE FILEPATH "libidn2 include path") + set(LIBIDN2_LIBRARIES ${PkgLibIdn2_LIBRARIES} CACHE STRING "libidn2 libraries") set(LIBIDN2_VERSION ${PkgLibIdn2_VERSION}) add_library(Libidn2::Libidn2 ALIAS PkgConfig::PkgLibIdn2) -else() + set(Libidn2_FOUND ON) +else () find_path(LIBIDN2_INCLUDE_DIR idn2.h HINTS "${LIBIDN2_DIR}" "${LIBIDN2_DIR}/include" ) - find_library(LIBIDN2_LIBRARY NAMES idn2 libidn2 + find_library(LIBIDN2_LIBRARIES NAMES idn2 libidn2 HINTS "${LIBIDN2_DIR}" "${LIBIDN2_DIR}/lib" ) - set(LIBIDN2_LIBRARIES "") - - if (LIBIDN2_INCLUDE_DIR AND LIBIDN2_LIBRARY) + if (LIBIDN2_INCLUDE_DIR AND LIBIDN2_LIBRARIES) if (NOT TARGET Libidn2::Libidn2) add_library(Libidn2::Libidn2 UNKNOWN IMPORTED) set_target_properties(Libidn2::Libidn2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBIDN2_INCLUDE_DIR}" IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${LIBIDN2_LIBRARY}" + IMPORTED_LOCATION "${LIBIDN2_LIBRARIES}" ) endif () @@ -67,15 +66,12 @@ else() file(STRINGS "${LIBIDN2_INCLUDE_DIR}/idn2.h" LIBIDN2_H REGEX "^#define IDN2_VERSION ") string(REGEX REPLACE "^.*IDN2_VERSION \"([0-9.]+)\".*$" "\\1" LIBIDN2_VERSION "${LIBIDN2_H}") endif () - - list(APPEND LIBIDN2_LIBRARIES "${LIBIDN2_LIBRARY}") - endif() -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Libidn2 - REQUIRED_VARS LIBIDN2_LIBRARIES LIBIDN2_INCLUDE_DIR - VERSION_VAR LIBIDN2_VERSION + endif () + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Libidn2 + REQUIRED_VARS LIBIDN2_LIBRARIES LIBIDN2_INCLUDE_DIR + VERSION_VAR LIBIDN2_VERSION ) +endif () -mark_as_advanced(LIBIDN2_INCLUDE_DIR LIBIDN2_LIBRARIES LIBIDN2_LIBRARY) +mark_as_advanced(LIBIDN2_INCLUDE_DIR LIBIDN2_LIBRARIES) diff --git a/cmake/modules/FindLibunbound.cmake b/cmake/modules/FindLibunbound.cmake index 2b4c249e..10d9a7e1 100644 --- a/cmake/modules/FindLibunbound.cmake +++ b/cmake/modules/FindLibunbound.cmake @@ -28,17 +28,18 @@ This module will set the following variables in your project: #]=======================================================================] -include(FindPkgConfig) -if(PKG_CONFIG_FOUND) - pkg_check_modules(PkgLibunbound IMPORTED_TARGET GLOBAL QUIET libunbound) -endif() +find_package(PkgConfig QUIET) +if (PKG_CONFIG_FOUND) + pkg_check_modules(PkgLibunbound IMPORTED_TARGET GLOBAL QUIET libunbound) +endif () -if(PkgLibunbound_FOUND) - set(LIBUNBOUND_INCLUDE_DIR ${PkgLibunbound_INCLUDE_DIRS}) - set(LIBUNBOUND_LIBRARIES ${PkgLibunbound_LIBRARIES}) +if (PkgLibunbound_FOUND) + set(LIBUNBOUND_INCLUDE_DIR ${PkgLibunbound_INCLUDE_DIRS} CACHE FILEPATH "libunbound include path") + set(LIBUNBOUND_LIBRARIES ${PkgLibunbound_LIBRARIES} CACHE STRING "libunbound libraries") set(LIBUNBOUND_VERSION ${PkgLibunbound_VERSION}) add_library(Libunbound::Libunbound ALIAS PkgConfig::PkgLibunbound) -else() + set(Libunbound_FOUND ON) +else () find_path(LIBUNBOUND_INCLUDE_DIR unbound.h HINTS "${LIBUNBOUND_DIR}" @@ -51,14 +52,14 @@ else() "${LIBUNBOUND_DIR}/lib" ) - set(LIBUNBOUND_LIBRARIES "") + set(_LIBUNBOUND_LIBRARIES "") if (UNIX) find_package(Threads REQUIRED) find_package(OpenSSL REQUIRED) - list(APPEND LIBUNBOUND_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") - list(APPEND LIBUNBOUND_LIBRARIES "${OPENSSL_LIBRARIES}") + list(APPEND _LIBUNBOUND_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") + list(APPEND _LIBUNBOUND_LIBRARIES "${OPENSSL_LIBRARIES}") endif() if (LIBUNBOUND_INCLUDE_DIR AND LIBUNBOUND_LIBRARY) @@ -88,15 +89,16 @@ else() file(STRINGS "${LIBUNBOUND_INCLUDE_DIR}/unbound.h" LIBUNBOUND_H REGEX "^#define UNBOUND_VERSION_M[A-Z]+") string(REGEX REPLACE "^.*MAJOR ([0-9]+).*MINOR ([0-9]+).*MICRO ([0-9]+).*$" "\\1.\\2.\\3" LIBUNBOUND_VERSION "${LIBUNBOUND_H}") endif () - endif() + endif () - list(APPEND LIBUNBOUND_LIBRARIES "${LIBUNBOUND_LIBRARY}") -endif() + list(APPEND _LIBUNBOUND_LIBRARIES "${LIBUNBOUND_LIBRARY}") + set(LIBUNBOUND_LIBRARIES ${_LIBUNBOUND_LIBRARIES} CACHE STRING "libunbound libraries") -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Libunbound - REQUIRED_VARS LIBUNBOUND_LIBRARIES LIBUNBOUND_INCLUDE_DIR - VERSION_VAR LIBUNBOUND_VERSION - ) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Libunbound + REQUIRED_VARS LIBUNBOUND_LIBRARIES LIBUNBOUND_INCLUDE_DIR + VERSION_VAR LIBUNBOUND_VERSION + ) +endif () mark_as_advanced(LIBUNBOUND_INCLUDE_DIR LIBUNBOUND_LIBRARIES LIBUNBOUND_LIBRARY) diff --git a/cmake/modules/FindLibuv.cmake b/cmake/modules/FindLibuv.cmake index b6edeb09..2906ba61 100644 --- a/cmake/modules/FindLibuv.cmake +++ b/cmake/modules/FindLibuv.cmake @@ -28,38 +28,37 @@ This module will set the following variables in your project: #]=======================================================================] -include(FindPkgConfig) +find_package(PkgConfig QUIET) if(PKG_CONFIG_FOUND) pkg_check_modules(PkgLibuv IMPORTED_TARGET GLOBAL QUIET libuv) endif() -if(PkgLibuv_FOUND) - set(LIBUV_INCLUDE_DIR ${PkgLibuv_INCLUDE_DIRS}) - set(LIBUV_LIBRARIES ${PkgLibuv_LIBRARIES}) +if (PkgLibuv_FOUND) + set(LIBUV_INCLUDE_DIR ${PkgLibuv_INCLUDE_DIRS} CACHE FILEPATH "libuv include path") + set(LIBUV_LIBRARIES ${PkgLibuv_LIBRARIES} CACHE STRING "libuv libraries") set(LIBUV_VERSION ${PkgLibuv_VERSION}) add_library(Libuv::Libuv ALIAS PkgConfig::PkgLibuv) -else() + set(Libuv_FOUND ON) +else () find_path(LIBUV_INCLUDE_DIR uv.h HINTS "${LIBUV_DIR}" "${LIBUV_DIR}/include" ) - find_library(LIBUV_LIBRARY NAMES uv libuv + find_library(LIBUV_LIBRARIES NAMES uv libuv HINTS "${LIBUV_DIR}" "${LIBUV_DIR}/lib" ) - set(LIBUV_LIBRARIES "") - if (LIBUV_INCLUDE_DIR AND LIBUV_LIBRARY) if (NOT TARGET Libuv::Libuv) add_library(Libuv::Libuv UNKNOWN IMPORTED) set_target_properties(Libuv::Libuv PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBUV_INCLUDE_DIR}" IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${LIBUV_LIBRARY}" + IMPORTED_LOCATION "${LIBUV_LIBRARIES}" ) endif () @@ -71,15 +70,13 @@ else() endif () string(REGEX REPLACE "^.*_MAJOR ([0-9]+).*_MINOR ([0-9]+).*_PATCH ([0-9]+).*$" "\\1.\\2.\\3" LIBUV_VERSION "${LIBUV_VER_H}") endif () - endif() - - list(APPEND LIBUV_LIBRARIES "${LIBUV_LIBRARY}") -endif() + endif () -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Libuv - REQUIRED_VARS LIBUV_LIBRARIES LIBUV_INCLUDE_DIR - VERSION_VAR LIBUV_VERSION + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Libuv + REQUIRED_VARS LIBUV_LIBRARIES LIBUV_INCLUDE_DIR + VERSION_VAR LIBUV_VERSION ) +endif () -mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARIES LIBUV_LIBRARY) +mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARIES) diff --git a/cmake/modules/FindNettle.cmake b/cmake/modules/FindNettle.cmake index 900148de..c88b05a9 100644 --- a/cmake/modules/FindNettle.cmake +++ b/cmake/modules/FindNettle.cmake @@ -30,18 +30,19 @@ This module will set the following variables in your project: #]=======================================================================] -include(FindPkgConfig) +find_package(PkgConfig QUIET) if(PKG_CONFIG_FOUND) - pkg_check_modules(PkgNettle IMPORTED_TARGET GLOBAL nettle) - pkg_check_modules(PkgHogweed IMPORTED_TARGET GLOBAL QUIET hogweed) + pkg_check_modules(PkgNettle IMPORTED_TARGET GLOBAL nettle) + pkg_check_modules(PkgHogweed IMPORTED_TARGET GLOBAL QUIET hogweed) endif() if(PkgNettle_FOUND AND PkHogweed_FOUND) - set(NETTLE_INCLUDE_DIR ${PkgNettle_INCLUDE_DIRS} ${PkgHogweed_INCLUDE_DIRS}) - set(NETTLE_LIBRARIES ${PkgNettle_LIBRARIES} ${PkgHogweed_LIBRARIES}) + set(NETTLE_INCLUDE_DIR ${PkgNettle_INCLUDE_DIRS} ${PkgHogweed_INCLUDE_DIRS} CACHE FILEPATH "Nettle include path") + set(NETTLE_LIBRARIES ${PkgNettle_LIBRARIES} ${PkgHogweed_LIBRARIES} CACHE STRING "Nettle libraries") set(NETTLE_VERSION ${PkgNettle_VERSION}) add_library(Nettle::Nettle ALIAS PkgConfig::PkgNettle) add_library(Nettle::Hogweed ALIAS PkgConfig::PkgHogweed) + set(Nettle_FOUND ON) else() find_path(NETTLE_INCLUDE_DIR nettle/version.h HINTS @@ -60,17 +61,18 @@ else() "${NETTLE_DIR}" "${NETTLE_DIR}/lib" ) - - set(NETTLE_LIBRARIES "") + + set(_NETTLE_LIBRARIES ${NETTLE_LIBRARY} ${HOGWEED_LIBRARY}) # May need gmp library on Unix. if (UNIX) find_library(NETTLE_GMP_LIBRARY gmp) - - if (NETTLE_GMP_LIBRARY) - list(APPEND NETTLE_LIBRARIES "${NETTLE_GMP_LIBRARY}") - endif () endif () + if (NETTLE_GMP_LIBRARY) + list(APPEND _NETTLE_LIBRARIES "${NETTLE_GMP_LIBRARY}") + endif () + set(NETTLE_LIBRARIES ${_NETTLE_LIBRARIES} CACHE STRING "nettle libraries") + if (NETTLE_INCLUDE_DIR AND NETTLE_LIBRARY AND HOGWEED_LIBRARY) if (NOT TARGET Nettle::Nettle) @@ -98,12 +100,12 @@ else() endif() list(APPEND NETTLE_LIBRARIES "${NETTLE_LIBRARY}" "${HOGWEED_LIBRARY}") + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Nettle + REQUIRED_VARS NETTLE_LIBRARIES NETTLE_INCLUDE_DIR + VERSION_VAR NETTLE_VERSION + ) endif() -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Nettle - REQUIRED_VARS NETTLE_LIBRARIES NETTLE_INCLUDE_DIR - VERSION_VAR NETTLE_VERSION - ) - -mark_as_advanced(NETTLE_INCLUDE_DIR NETTLE_LIBRARIES NETTLE_LIBRARY HOGWEED_LIBRARY) +mark_as_advanced(NETTLE_INCLUDE_DIR NETTLE_LIBRARIES NETTLE_LIBRARY HOGWEED_LIBRARY NETTLE_GMP_LIBRARY) From de2137562d73ea2365a4d98f6db097ef8aa5d86d Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 28 May 2021 23:03:41 +0200 Subject: [PATCH 4/4] cmake: find libuv pkgconfig non-QUIET --- cmake/modules/FindLibuv.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/modules/FindLibuv.cmake b/cmake/modules/FindLibuv.cmake index 2906ba61..e9ed8e66 100644 --- a/cmake/modules/FindLibuv.cmake +++ b/cmake/modules/FindLibuv.cmake @@ -29,9 +29,9 @@ This module will set the following variables in your project: #]=======================================================================] find_package(PkgConfig QUIET) -if(PKG_CONFIG_FOUND) - pkg_check_modules(PkgLibuv IMPORTED_TARGET GLOBAL QUIET libuv) -endif() +if (PKG_CONFIG_FOUND) + pkg_check_modules(PkgLibuv IMPORTED_TARGET GLOBAL libuv) +endif () if (PkgLibuv_FOUND) set(LIBUV_INCLUDE_DIR ${PkgLibuv_INCLUDE_DIRS} CACHE FILEPATH "libuv include path")