Skip to content

Commit

Permalink
Try finding OpenSSL using pkg-config first on macOS. (#17250)
Browse files Browse the repository at this point in the history
This is required to work correctly in Homebrew, as building within
Homebrew does not allow using Homebrew commands, but does generally
provide a properly working pkg-config setup.

(cherry picked from commit 67549f4)
  • Loading branch information
Ferroin committed Mar 27, 2024
1 parent 2ef91a8 commit e526d03
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions CMakeLists.txt
Expand Up @@ -479,40 +479,30 @@ endif()

# openssl/crypto
set(ENABLE_OPENSSL True)
if(NOT MACOS)
pkg_check_modules(CRYPTO libcrypto)
pkg_check_modules(OPENSSL REQUIRED openssl)
else()
# I think this is moot because we can only use openssl 3.x
execute_process(COMMAND
brew --prefix --installed openssl
RESULT_VARIABLE BREW_OPENSSL
OUTPUT_VARIABLE BREW_OPENSSL_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)

if((BREW_OPENSSL NOT EQUAL 0) OR (NOT EXISTS "${BREW_OPENSSL_PREFIX}"))
pkg_check_modules(OPENSSL openssl)

if(NOT OPENSSL_FOUND)
if(MACOS)
execute_process(COMMAND
brew --prefix --installed openssl@3
brew --prefix --installed openssl
RESULT_VARIABLE BREW_OPENSSL
OUTPUT_VARIABLE BREW_OPENSSL_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)

if((BREW_OPENSSL NOT EQUAL 0) OR (NOT EXISTS "${BREW_OPENSSL_PREFIX}"))
execute_process(COMMAND
brew --prefix --installed openssl@1.1
RESULT_VARIABLE BREW_OPENSSL
OUTPUT_VARIABLE BREW_OPENSSL_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)

if((BREW_OPENSSL NOT EQUAL 0) OR (NOT EXISTS "${BREW_OPENSSL_PREFIX}"))
message(FATAL_ERROR "Could not find openssl prefix with brew")
endif()
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")
else()
message(FATAL_ERROR "OpenSSL (or LibreSSL) is required for building Netdata, but could not be found.")
endif()
endif()

set(OPENSSL_INCLUDE_DIRS "${BREW_OPENSSL_PREFIX}/include")
set(OPENSSL_CFLAGS_OTHER "")
set(OPENSSL_LDFLAGS "-L${BREW_OPENSSL_PREFIX}/lib;-lssl;-lcrypto")
if(NOT MACOS)
pkg_check_modules(CRYPTO libcrypto)
endif()

#
Expand Down

0 comments on commit e526d03

Please sign in to comment.