Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of OpenSSL linking on macOS #17535

Merged
merged 8 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
50 changes: 32 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()

#
Expand Down Expand Up @@ -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)
Expand Down