From 2c2ff01e8562c870efbf5ffb1a3e4ba24a1ade83 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 28 Dec 2019 15:37:07 +0100 Subject: [PATCH] Problem: CMake does not look for NSS using pkg-config Solution: use pkg-config by default and FindPackage only as a fallback --- CMakeLists.txt | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f42897f4..e42de5fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,8 @@ include(TestZMQVersion) include(ZMQSourceRunChecks) include(ZMQSupportMacros) +find_package(PkgConfig) + option(ENABLE_ASAN "Build with address sanitizer" OFF) if(ENABLE_ASAN) message(STATUS "Instrumenting with Address Sanitizer") @@ -120,17 +122,23 @@ if (NOT DISABLE_WS) set(ZMQ_HAVE_WS 1) if (WITH_NSS) - find_package("NSS3") + pkg_check_modules(NSS3 "nss") if (NSS3_FOUND) - message(STATUS "Using NSS") - include_directories(${NSS3_INCLUDE_DIRS}) - set(pkg_config_names_private "${pkg_config_names_private} nss3") - set(pkg_config_libs_private "${pkg_config_libs_private} -lnss3") - set(ZMQ_USE_NSS 1) + set(pkg_config_names_private "${pkg_config_names_private} nss") else() - message(FATAL_ERROR - "nss is not installed. Install it, then run CMake again") + find_package("NSS3") + if (NSS3_FOUND) + set(pkg_config_libs_private "${pkg_config_libs_private} -lnss3") + else() + message(FATAL_ERROR + "nss is not installed. Install it, then run CMake again") + endif() endif() + message(STATUS "Using NSS") + include_directories(${NSS3_INCLUDE_DIRS}) + link_directories(${NSS3_LIBRARY_DIRS}) + set(OPTIONAL_LIBRARIES ${NSS3_LIBRARIES}) + set(ZMQ_USE_NSS 1) else() list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/external/sha1/sha1.c ${CMAKE_CURRENT_SOURCE_DIR}/external/sha1/sha1.h) message("Using builtin sha1") @@ -139,7 +147,6 @@ if (NOT DISABLE_WS) endif() if(NOT MSVC) - find_package(PkgConfig) option(WITH_LIBBSD "Use libbsd instead of builtin strlcpy" ON) if (WITH_LIBBSD) pkg_check_modules(LIBBSD "libbsd")