0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-07 06:45:39 +00:00

Actually handle the -fexceptions requirement correctly in our build system. ()

This commit is contained in:
Austin S. Hemmelgarn 2025-01-31 08:20:05 -05:00 committed by GitHub
parent 0164a51a86
commit 34236bffa4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 10 deletions
CMakeLists.txt
packaging/cmake/Modules
src/daemon

View file

@ -83,11 +83,6 @@ if(USE_MOLD)
endif()
endif()
check_c_compiler_flag("-fexceptions" HAVE_FEXCEPTIONS)
if (NOT HAVE_FEXCEPTIONS)
message(FATAL_ERROR "Missing required compiler flag: -fexceptions.")
endif()
set(CONFIG_H_DIR ${CMAKE_BINARY_DIR})
set(CONFIG_H ${CONFIG_H_DIR}/config.h)

View file

@ -69,6 +69,26 @@ function(add_double_extra_compiler_flag match flag1 flag2)
endif()
endfunction()
# Add a required extra compiler flag to C and C++ flags.
#
# Similar logic as add_simple_extra_compiler_flag, but ignores existing
# instances and throws an error if the flag is not supported.
function(add_required_compiler_flag flag)
set(CMAKE_REQUIRED_FLAGS "-Werror")
make_cpp_safe_name("${flag}" flag_name)
check_c_compiler_flag("${flag}" HAVE_C_${flag_name})
check_cxx_compiler_flag("${flag}" HAVE_CXX_${flag_name})
if(HAVE_C_${flag_name} AND HAVE_CXX_${flag_name})
add_compile_options("${flag}")
add_link_options("${flag}")
else()
message(FATAL_ERROR "${flag} support is required to build Netdata")
endif()
endfunction()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
option(DISABLE_HARDENING "Disable adding extra compiler flags for hardening" TRUE)
else()
@ -84,6 +104,8 @@ endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}")
add_required_compiler_flag("-fexceptions")
if(NOT ${DISABLE_HARDENING})
add_double_extra_compiler_flag("stack-protector" "-fstack-protector-strong" "-fstack-protector")
add_double_extra_compiler_flag("_FORTIFY_SOURCE" "-D_FORTIFY_SOURCE=3" "-D_FORTIFY_SOURCE=2")

View file

@ -228,11 +228,6 @@ int unittest_prepare_rrd(const char **user) {
}
int netdata_main(int argc, char **argv) {
#if !defined(HAVE_FEXCEPTIONS)
fprintf(stderr, "Netdata has been compiled without these required compiler flags: -fexceptions.\n");
exit(1);
#endif
string_init();
analytics_init();