diff options
author | Austin S. Hemmelgarn <austin@netdata.cloud> | 2024-02-26 08:47:02 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-26 08:47:02 -0500 |
commit | ca016406c3072cf5f7d2a28c36f4593ff33d67dc (patch) | |
tree | 5cc45494eb0ba865cf706cb3c56b39007f1bd0e5 /CMakeLists.txt | |
parent | cd145f82a3213fc3e040b8799decb722ec7f22b7 (diff) |
More concretely utilize local modules in our CMake code. (#17022)
* Properly handle systemd.cmake as a module.
* Split CMake compiler flag handling functions to their own module.
* Add include guards to modules.
* Prefix module names with Netdata.
This ensures that we end up using our local modules instead of possibly
using a system module with the same name.
* Drop include guards.
And shift systemd detection code to a macro so it’s less dangerous to
import the module multiple times.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 72 |
1 files changed, 4 insertions, 68 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 320a294e84..d6e9536bbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ project(netdata DESCRIPTION "Netdata real-time monitoring" HOMEPAGE_URL "https://www.netdata.cloud" LANGUAGES C CXX) +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/packaging/cmake/Modules") find_package(PkgConfig REQUIRED) @@ -165,8 +166,7 @@ endif() # handling of extra compiler flags # -include(CheckCCompilerFlag) -include(CheckCXXCompilerFlag) +include(NetdataCompilerFlags) # Disable hardening for debug builds by default. if(CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -175,71 +175,6 @@ else() option(DISABLE_HARDENING "disable adding extra compiler flags for hardening" FALSE) endif() -# Construct a pre-processor safe name -function(make_cpp_safe_name value target) - string(REPLACE "-" "_" tmp "${value}") - string(REPLACE "=" "_" tmp "${tmp}") - set(${target} "${tmp}" PARENT_SCOPE) -endfunction() - -# Conditionally add an extra compiler flag to C and C++ flags. -# -# If the language flags already match the `match` argument, skip this flag. -# Otherwise, check for support for `flag` and if support is found, add it to -# the language-specific `target` flag group. -function(add_simple_extra_compiler_flag match flag target) - set(CMAKE_REQUIRED_FLAGS "-Werror") - - make_cpp_safe_name("${flag}" flag_name) - - if(NOT ${CMAKE_C_FLAGS} MATCHES ${match}) - check_c_compiler_flag("${flag}" HAVE_C_${flag_name}) - if(HAVE_C_${flag_name}) - set(${target}_C_FLAGS "${${target}_C_FLAGS} ${flag}" PARENT_SCOPE) - endif() - endif() - - if(NOT ${CMAKE_CXX_FLAGS} MATCHES ${match}) - check_cxx_compiler_flag("${flag}" HAVE_CXX_${flag_name}) - if(HAVE_CXX_${flag_name}) - set(${target}_CXX_FLAGS "${${target}_CXX_FLAGS} ${flag}" PARENT_SCOPE) - endif() - endif() -endfunction() - -# Same as add_simple_extra_compiler_flag, but check for a second flag if the -# first one is unsupported. -function(add_double_extra_compiler_flag match flag1 flag2 target) - set(CMAKE_REQUIRED_FLAGS "-Werror") - - make_cpp_safe_name("${flag1}" flag1_name) - make_cpp_safe_name("${flag2}" flag2_name) - - if(NOT ${CMAKE_C_FLAGS} MATCHES ${match}) - check_c_compiler_flag("${flag1}" HAVE_C_${flag1_name}) - if(HAVE_C_${flag1_name}) - set(${target}_C_FLAGS "${${target}_C_FLAGS} ${flag1}" PARENT_SCOPE) - else() - check_c_compiler_flag("${flag2}" HAVE_C_${flag2_name}) - if(HAVE_C_${flag2_name}) - set(${target}_C_FLAGS "${${target}_C_FLAGS} ${flag2}" PARENT_SCOPE) - endif() - endif() - endif() - - if(NOT ${CMAKE_CXX_FLAGS} MATCHES ${match}) - check_cxx_compiler_flag("${flag1}" HAVE_CXX_${flag1_name}) - if(HAVE_CXX_${flag1_name}) - set(${target}_CXX_FLAGS "${${target}_CXX_FLAGS} ${flag1}" PARENT_SCOPE) - else() - check_cxx_compiler_flag("${flag2}" HAVE_CXX_${flag2_name}) - if(HAVE_CXX_${flag2_name}) - set(${target}_CXX_FLAGS "${${target}_CXX_FLAGS} ${flag2}" PARENT_SCOPE) - endif() - endif() - endif() -endfunction() - set(EXTRA_HARDENING_C_FLAGS "") set(EXTRA_HARDENING_CXX_FLAGS "") @@ -1524,7 +1459,8 @@ set_source_files_properties(JudyLTables.c PROPERTIES COMPILE_OPTIONS "-I${CMAKE_ # build libnetdata # -include(packaging/cmake/systemd.cmake) +include(NetdataDetectSystemd) +detect_systemd() add_library(libnetdata STATIC ${LIBNETDATA_FILES}) |