Assorted macOS build fixes. (#17216)
* Use zlib provided by the system itself on macOS. Searching for it with find_package() should always work on macOS since it will find the system copy, which is always going to be there. * Use native libuuid on macOS. Much like zlib, macOS provides a libuuid implementation that (should) work for us, so just use that instead of fighting with brew to find one. * Don’t prepend system include paths. * Skip Linux-specific checks on macOS. This isn’t technically broken, but not making these checks makes debugging of the build system easier. * Minor CMake restructure.
Austin S. Hemmelgarn committed
Mar 26, 2024 at 07:43 UTC
7da059a24fa3b7e9e8d03ee824b6a93a33ba9a23
2 files changed
+56
-41
CMakeLists.txt
+29
-14
@@ -1479,8 +1479,10 @@ set_source_files_properties(JudyLTables.c PROPERTIES COMPILE_OPTIONS "-I${CMAKE_
1479
# build libnetdata
1480
#
1481
1482
-include(NetdataDetectSystemd)
1483
-detect_systemd()
1482
+if(LINUX)
1483
+ include(NetdataDetectSystemd)
1484
+ detect_systemd()
1485
+endif()
1486
1487
add_library(libnetdata STATIC ${LIBNETDATA_FILES})
1488
@@ -1539,10 +1541,16 @@ endif()
1541
netdata_add_libyaml_to_target(libnetdata)
1542
1543
# zlib
1542
-pkg_check_modules(ZLIB REQUIRED zlib)
1543
-target_include_directories(libnetdata BEFORE PUBLIC ${ZLIB_INCLUDE_DIRS})
1544
-target_compile_definitions(libnetdata PUBLIC ${ZLIB_CFLAGS_OTHER})
1545
-target_link_libraries(libnetdata PUBLIC ${ZLIB_LDFLAGS})
1544
+if(MACOS)
1545
+ find_package(ZLIB REQUIRED)
1546
+ target_include_directories(libnetdata BEFORE PUBLIC ${ZLIB_INCLUDE_DIRS})
1547
+ target_link_libraries(libnetdata PUBLIC ZLIB::ZLIB)
1548
+else()
1549
+ pkg_check_modules(ZLIB REQUIRED zlib)
1550
+ target_include_directories(libnetdata BEFORE PUBLIC ${ZLIB_INCLUDE_DIRS})
1551
+ target_compile_definitions(libnetdata PUBLIC ${ZLIB_CFLAGS_OTHER})
1552
+ target_link_libraries(libnetdata PUBLIC ${ZLIB_LDFLAGS})
1553
+endif()
1554
1555
# lz4 - try to find a version that is compatible with streaming compression
1556
# otherwise pick whichever one we can find to support dbengine but don't set
@@ -1571,16 +1579,21 @@ endif()
1579
pkg_check_modules(LIBBROTLI libbrotlidec libbrotlienc libbrotlicommon)
1580
if(LIBBROTLI_FOUND)
1581
set(ENABLE_BROTLI On)
1574
- target_include_directories(libnetdata BEFORE PUBLIC ${LIBBROTLI_INCLUDE_DIRS})
1582
+ target_include_directories(libnetdata PUBLIC ${LIBBROTLI_INCLUDE_DIRS})
1583
target_compile_definitions(libnetdata PUBLIC ${LIBBROTLI_CFLAGS_OTHER})
1584
target_link_libraries(libnetdata PUBLIC ${LIBBROTLI_LDFLAGS})
1585
endif()
1586
1587
# uuid
1580
-pkg_check_modules(UUID REQUIRED uuid)
1581
-target_include_directories(libnetdata BEFORE PUBLIC ${UUID_INCLUDE_DIRS})
1582
-target_compile_definitions(libnetdata PUBLIC ${UUID_CFLAGS_OTHER})
1583
-target_link_libraries(libnetdata PUBLIC ${UUID_LDFLAGS})
1588
+if(MACOS)
1589
+ # UUID functionality is part of the system libraries here, so no extra
1590
+ # stuff needed.
1591
+else()
1592
+ pkg_check_modules(UUID REQUIRED uuid)
1593
+ target_include_directories(libnetdata BEFORE PUBLIC ${UUID_INCLUDE_DIRS})
1594
+ target_compile_definitions(libnetdata PUBLIC ${UUID_CFLAGS_OTHER})
1595
+ target_link_libraries(libnetdata PUBLIC ${UUID_LDFLAGS})
1596
+endif()
1597
1598
# uv
1599
pkg_check_modules(LIBUV REQUIRED libuv)
@@ -1599,9 +1612,11 @@ target_compile_options(libnetdata PUBLIC ${OPENSSL_CFLAGS_OTHER})
1612
target_link_libraries(libnetdata PUBLIC ${OPENSSL_LDFLAGS})
1613
1614
# mnl
1602
-pkg_check_modules(MNL libmnl)
1603
-if(MNL_FOUND)
1604
- set(HAVE_LIBMNL True)
1615
+if(NOT MACOS)
1616
+ pkg_check_modules(MNL libmnl)
1617
+ if(MNL_FOUND)
1618
+ set(HAVE_LIBMNL True)
1619
+ endif()
1620
endif()
1621
1622
#
packaging/cmake/Modules/NetdataDetectSystemd.cmake
+27
-27
@@ -4,39 +4,39 @@
4
# SPDX-License-Identifier: GPL-3.0-or-later
5
6
macro(detect_systemd)
7
- find_library(SYSTEMD_LIBRARY NAMES systemd)
7
+ find_library(SYSTEMD_LIBRARY NAMES systemd)
8
9
- set(ENABLE_DSYSTEMD_DBUS NO)
10
- pkg_check_modules(SYSTEMD libsystemd)
9
+ set(ENABLE_DSYSTEMD_DBUS NO)
10
+ pkg_check_modules(SYSTEMD libsystemd)
11
12
- if(SYSTEMD_FOUND)
13
- set(CMAKE_REQUIRED_LIBRARIES_BEFORE_SYSTEMD "${CMAKE_REQUIRED_LIBRARIES}")
14
- set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};${SYSTEMD_LIBRARIES}")
12
+ if(SYSTEMD_FOUND)
13
+ set(CMAKE_REQUIRED_LIBRARIES_BEFORE_SYSTEMD "${CMAKE_REQUIRED_LIBRARIES}")
14
+ set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};${SYSTEMD_LIBRARIES}")
15
16
- check_c_source_compiles("
17
- #include <systemd/sd-journal.h>
16
+ check_c_source_compiles("
17
+ #include <systemd/sd-journal.h>
18
19
- int main() {
20
- int x = SD_JOURNAL_OS_ROOT;
21
- return 0;
22
- }" HAVE_SD_JOURNAL_OS_ROOT)
19
+ int main() {
20
+ int x = SD_JOURNAL_OS_ROOT;
21
+ return 0;
22
+ }" HAVE_SD_JOURNAL_OS_ROOT)
23
24
- check_symbol_exists(SD_JOURNAL_OS_ROOT "systemd/sd-journal.h" HAVE_SD_JOURNAL_OS_ROOT)
25
- check_symbol_exists(sd_journal_open_files_fd "systemd/sd-journal.h" HAVE_SD_JOURNAL_OPEN_FILES_FD)
26
- check_symbol_exists(sd_journal_restart_fields "systemd/sd-journal.h" HAVE_SD_JOURNAL_RESTART_FIELDS)
27
- check_symbol_exists(sd_journal_get_seqnum "systemd/sd-journal.h" HAVE_SD_JOURNAL_GET_SEQNUM)
24
+ check_symbol_exists(SD_JOURNAL_OS_ROOT "systemd/sd-journal.h" HAVE_SD_JOURNAL_OS_ROOT)
25
+ check_symbol_exists(sd_journal_open_files_fd "systemd/sd-journal.h" HAVE_SD_JOURNAL_OPEN_FILES_FD)
26
+ check_symbol_exists(sd_journal_restart_fields "systemd/sd-journal.h" HAVE_SD_JOURNAL_RESTART_FIELDS)
27
+ check_symbol_exists(sd_journal_get_seqnum "systemd/sd-journal.h" HAVE_SD_JOURNAL_GET_SEQNUM)
28
29
- check_symbol_exists(sd_bus_default_system "systemd/sd-bus.h" HAVE_SD_BUS_DEFAULT_SYSTEM)
30
- check_symbol_exists(sd_bus_call_method "systemd/sd-bus.h" HAVE_SD_BUS_CALL_METHOD)
31
- check_symbol_exists(sd_bus_message_enter_container "systemd/sd-bus.h" HAVE_SD_BUS_MESSAGE_ENTER_CONTAINER)
32
- check_symbol_exists(sd_bus_message_read "systemd/sd-bus.h" HAVE_SD_BUS_MESSAGE_READ)
33
- check_symbol_exists(sd_bus_message_exit_container "systemd/sd-bus.h" HAVE_SD_BUS_MESSAGE_EXIT_CONTAINER)
29
+ check_symbol_exists(sd_bus_default_system "systemd/sd-bus.h" HAVE_SD_BUS_DEFAULT_SYSTEM)
30
+ check_symbol_exists(sd_bus_call_method "systemd/sd-bus.h" HAVE_SD_BUS_CALL_METHOD)
31
+ check_symbol_exists(sd_bus_message_enter_container "systemd/sd-bus.h" HAVE_SD_BUS_MESSAGE_ENTER_CONTAINER)
32
+ check_symbol_exists(sd_bus_message_read "systemd/sd-bus.h" HAVE_SD_BUS_MESSAGE_READ)
33
+ check_symbol_exists(sd_bus_message_exit_container "systemd/sd-bus.h" HAVE_SD_BUS_MESSAGE_EXIT_CONTAINER)
34
35
- set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_BEFORE_SYSTEMD}")
35
+ set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_BEFORE_SYSTEMD}")
36
37
- set(HAVE_SYSTEMD True)
38
- if(HAVE_SD_BUS_DEFAULT_SYSTEM AND HAVE_SD_BUS_CALL_METHOD AND HAVE_SD_BUS_MESSAGE_ENTER_CONTAINER AND HAVE_SD_BUS_MESSAGE_READ AND HAVE_SD_BUS_MESSAGE_EXIT_CONTAINER)
39
- set(ENABLE_SYSTEMD_DBUS YES)
40
- endif()
41
- endif()
37
+ set(HAVE_SYSTEMD True)
38
+ if(HAVE_SD_BUS_DEFAULT_SYSTEM AND HAVE_SD_BUS_CALL_METHOD AND HAVE_SD_BUS_MESSAGE_ENTER_CONTAINER AND HAVE_SD_BUS_MESSAGE_READ AND HAVE_SD_BUS_MESSAGE_EXIT_CONTAINER)
39
+ set(ENABLE_SYSTEMD_DBUS YES)
40
+ endif()
41
+ endif()
42
endmacro()