summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2024-05-21 06:55:41 -0400
committerGitHub <noreply@github.com>2024-05-21 06:55:41 -0400
commit9861bb5e7963c8375043570abffe406e383bedbe (patch)
tree49407c0fe7c8637a2d2c77a726d7f0f83bf69872
parent687bbb38844efe88730eb1e20a2c08cf73a9cc9e (diff)
Fix handling of OpenSSL linking on macOS (#17535)
* Pull in all dependencies for macOS CI jobs. Instead of only pulling in a basic set. * Switch to using imported target for OpenSSL in most cases. * Use imported libraries for OpenSSL in all cases. * Work around broken behavior in FindPkgConfig with static builds. It happened to be working before without this because we weren’t hitting any edge cases, but the use of IMPORTED targets with PkgConfig requires these fixes to behave correctly for transitive dependencies in static builds. * Correctly detect static builds. * Fix H2O linking. * Fix typo. * Always check for libcrypto if we found openssl. If we fail to find libcrypto when we found openssl with pkg_check_modules, then the openssl install is horribly broken and we will see failures either at link time or at runtime, so there is no point in not checking for it on macOS. This also more clearly delineates that we _do_ require libcrypto irrespective of the platform.
-rw-r--r--.github/workflows/build-macos.yml2
-rw-r--r--CMakeLists.txt50
2 files changed, 33 insertions, 19 deletions
diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml
index 1aa5167160..24c13150f3 100644
--- a/.github/workflows/build-macos.yml
+++ b/.github/workflows/build-macos.yml
@@ -105,7 +105,7 @@ jobs:
id: install-nd-dep
if: needs.file-check.outputs.run == 'true'
run: |
- bash ./packaging/installer/install-required-packages.sh --dont-wait --non-interactive netdata
+ bash ./packaging/installer/install-required-packages.sh --dont-wait --non-interactive netdata-all
- name: Build from source
id: build-source
if: needs.file-check.outputs.run == 'true'
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b6df570e7e..4d6864447f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -66,8 +66,23 @@ project(netdata
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/packaging/cmake/Modules")
include(CMakeDependentOption)
+if(DEFINED BUILD_SHARED_LIBS)
+ if(NOT BUILD_SHARED_LIBS)
+ set(STATIC_BUILD TRUE)
+ endif()
+endif()
+
+if(STATIC_BUILD)
+ set(CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_STATIC_LIBRARY_PREFIX}")
+ set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_STATIC_LIBRARY_SUFFIX}")
+endif()
+
find_package(PkgConfig REQUIRED)
+if(STATIC_BUILD)
+ list(APPEND PKG_CONFIG_EXECUTABLE "--static")
+endif()
+
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "netdata")
@@ -547,9 +562,9 @@ endif()
# openssl/crypto
set(ENABLE_OPENSSL True)
-pkg_check_modules(OPENSSL openssl)
+pkg_check_modules(TLS IMPORTED_TARGET openssl)
-if(NOT OPENSSL_FOUND)
+if(NOT TARGET PkgConfig::TLS)
if(MACOS)
execute_process(COMMAND
brew --prefix --installed openssl
@@ -561,17 +576,23 @@ if(NOT OPENSSL_FOUND)
message(FATAL_ERROR "OpenSSL (or LibreSSL) is required for building Netdata, but could not be found.")
endif()
- set(OPENSSL_INCLUDE_DIRS "${BREW_OPENSSL_PREFIX}/include")
- set(OPENSSL_CFLAGS_OTHER "")
- set(OPENSSL_LDFLAGS "-L${BREW_OPENSSL_PREFIX}/lib;-lssl;-lcrypto")
+ add_library(PkgConfig::CRYPTO IMPORTED)
+ set_target_properties(PkgConfig::CRYPTO
+ IMPORTED_LOCATION ${BREW_OPENSSL_PREFIX}/lib/libcrypto.dylib
+ INTERFACE_INCLUDE_DIRECTORIES ${BREW_OPENSSL_PREFIX}/include)
+
+ add_library(PkgConfig::TLS IMPORTED)
+ set_target_properties(PkgConfig::TLS
+ IMPORTED_LOCATION ${BREW_OPENSSL_PREFIX}/lib/libssl.dylib
+ INTERFACE_LINK_LIBRARIES PkgConfig::CRYPTO
+ INTERFACE_INCLUDE_DIRECTORIES ${BREW_OPENSSL_PREFIX}/include)
else()
message(FATAL_ERROR "OpenSSL (or LibreSSL) is required for building Netdata, but could not be found.")
endif()
+else()
+ pkg_check_modules(CRYPTO IMPORTED_TARGET REQUIRED libcrypto)
endif()
-if(NOT MACOS)
- pkg_check_modules(CRYPTO libcrypto)
-endif()
#
# figure out if we need protoc/protobuf
@@ -1576,10 +1597,7 @@ if(ENABLE_H2O)
)
target_compile_options(h2o PUBLIC -DH2O_USE_LIBUV=0)
-
- target_include_directories(h2o BEFORE PRIVATE ${OPENSSL_INCLUDE_DIRS})
- target_compile_options(h2o PRIVATE ${OPENSSL_CFLAGS_OTHER})
- target_link_libraries(h2o PRIVATE ${OPENSSL_LIBRARIES})
+ target_link_libraries(h2o PRIVATE PkgConfig::TLS)
endif()
#
@@ -1713,14 +1731,10 @@ target_compile_options(libnetdata PUBLIC ${LIBUV_CFLAGS_OTHER})
target_link_libraries(libnetdata PUBLIC ${LIBUV_LDFLAGS})
# crypto
-target_include_directories(libnetdata BEFORE PUBLIC ${CRYPTO_INCLUDE_DIRS})
-target_compile_options(libnetdata PUBLIC ${CRYPTO_CFLAGS_OTHER})
-target_link_libraries(libnetdata PUBLIC ${CRYPTO_LDFLAGS})
+target_link_libraries(libnetdata PUBLIC PkgConfig::CRYPTO)
# openssl
-target_include_directories(libnetdata BEFORE PUBLIC ${OPENSSL_INCLUDE_DIRS})
-target_compile_options(libnetdata PUBLIC ${OPENSSL_CFLAGS_OTHER})
-target_link_libraries(libnetdata PUBLIC ${OPENSSL_LDFLAGS})
+target_link_libraries(libnetdata PUBLIC PkgConfig::TLS)
# mnl
if(NOT MACOS)