0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-14 01:29:11 +00:00

compile time and runtime check of required compiler flags ()

* compile time and runtime check of required compiler flags

* added compiler flags in buildinfo

* added basic runtime information in buildinfo

* check for -fexceptions
This commit is contained in:
Costa Tsaousis 2025-01-28 17:52:47 +00:00 committed by GitHub
parent a2df056233
commit 1138bde50e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 106 additions and 2 deletions

View file

@ -83,6 +83,11 @@ 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)
@ -2965,8 +2970,33 @@ endif()
set(WEB_DEST "${WEB_DIR}")
set(WEB_DIR "${NETDATA_RUNTIME_PREFIX}/${WEB_DEST}")
# Collect all compiler flags
get_directory_property(NETDATA_COMPILE_OPTIONS COMPILE_OPTIONS)
get_directory_property(NETDATA_COMPILE_DEFINITIONS COMPILE_DEFINITIONS)
# Collect all linker flags
get_directory_property(NETDATA_LINK_OPTIONS LINK_OPTIONS)
get_directory_property(NETDATA_LINK_LIBRARIES LINK_LIBRARIES)
list(APPEND CONFIGURE_OPTIONS
# Build type and languages
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DCMAKE_C_STANDARD=${CMAKE_C_STANDARD}"
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}"
# Compiler flags (dynamically collected)
"-DCMAKE_C_FLAGS='${CMAKE_C_FLAGS} ${NETDATA_COMPILE_OPTIONS}'"
"-DCMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS} ${NETDATA_COMPILE_OPTIONS}'"
"-DCMAKE_COMPILE_DEFINITIONS='${NETDATA_COMPILE_DEFINITIONS}'"
# Linker flags (dynamically collected)
"-DCMAKE_EXE_LINKER_FLAGS='${CMAKE_EXE_LINKER_FLAGS} ${NETDATA_LINK_OPTIONS}'"
"-DCMAKE_SHARED_LINKER_FLAGS='${CMAKE_SHARED_LINKER_FLAGS}'"
)
string(JOIN " " CONFIGURE_COMMAND "cmake" ${CONFIGURE_OPTIONS})
set(CONFIGURE_COMMAND "dummy-configure-command")
if (NOT NETDATA_USER)
set(NETDATA_USER "netdata")
endif()

View file

@ -14,6 +14,10 @@
#cmakedefine OS_MACOS
#cmakedefine OS_WINDOWS
// required compilation options
#cmakedefine HAVE_FEXCEPTIONS
// checked headers
#cmakedefine HAVE_NETINET_IN_H

View file

@ -118,6 +118,11 @@ typedef enum __attribute__((packed)) {
BIB_EXPORT_SHELL,
BIB_DEVEL_TRACE_ALLOCATIONS,
BIB_DEVELOPER_MODE,
BIB_RUNTIME_PROFILE,
BIB_RUNTIME_PARENT,
BIB_RUNTIME_CHILD,
BIB_RUNTIME_MEM_TOTAL,
BIB_RUNTIME_MEM_AVAIL,
// leave this last
BIB_TERMINATOR,
@ -135,7 +140,8 @@ typedef enum __attribute__((packed)) {
BIC_LIBS,
BIC_PLUGINS,
BIC_EXPORTERS,
BIC_DEBUG_DEVEL
BIC_DEBUG_DEVEL,
BIC_RUNTIME,
} BUILD_INFO_CATEGORY;
typedef enum __attribute__((packed)) {
@ -1040,6 +1046,46 @@ static struct {
.json = "dev-mode",
.value = NULL,
},
[BIB_RUNTIME_PROFILE] = {
.category = BIC_RUNTIME,
.type = BIT_STRING,
.analytics = "ConfigProfile",
.print = "Profile",
.json = "profile",
.value = NULL,
},
[BIB_RUNTIME_PARENT] = {
.category = BIC_RUNTIME,
.type = BIT_BOOLEAN,
.analytics = "StreamParent",
.print = "Stream Parent (accept data from Children)",
.json = "parent",
.value = NULL,
},
[BIB_RUNTIME_CHILD] = {
.category = BIC_RUNTIME,
.type = BIT_BOOLEAN,
.analytics = "StreamChild",
.print = "Stream Child (send data to a Parent)",
.json = "child",
.value = NULL,
},
[BIB_RUNTIME_MEM_TOTAL] = {
.category = BIC_RUNTIME,
.type = BIT_STRING,
.analytics = "TotalMemory",
.print = "Total System Memory",
.json = "mem-total",
.value = NULL,
},
[BIB_RUNTIME_MEM_AVAIL] = {
.category = BIC_RUNTIME,
.type = BIT_STRING,
.analytics = "AvailableMemory",
.print = "Available System Memory",
.json = "mem-available",
.value = NULL,
},
// leave this last
[BIB_TERMINATOR] = {
@ -1454,9 +1500,26 @@ static void populate_packaging_info() {
build_info_set_value(BIB_PACKAGING_INSTALL_TYPE, strdupz(BUILD_PACKAGING_INFO.install_type));
build_info_set_value(BIB_PACKAGING_ARCHITECTURE, strdupz(BUILD_PACKAGING_INFO.prebuilt_arch));
build_info_set_value(BIB_PACKAGING_DISTRO, strdupz(BUILD_PACKAGING_INFO.prebuilt_distro));
CLEAN_BUFFER *wb = buffer_create(0, NULL);
ND_PROFILE_2buffer(wb, nd_profile_detect_and_configure(false), " ");
build_info_set_value_strdupz(BIB_RUNTIME_PROFILE, buffer_tostring(wb));
build_info_set_status(BIB_RUNTIME_PARENT, stream_conf_is_parent(false));
build_info_set_status(BIB_RUNTIME_CHILD, stream_conf_is_child());
}
spinlock_unlock(&BUILD_PACKAGING_INFO.spinlock);
}
OS_SYSTEM_MEMORY sm = os_system_memory(true);
char buf[1024];
snprintfz(buf, sizeof(buf), "%" PRIu64, sm.ram_total_bytes);
// size_snprintf(buf, sizeof(buf), sm.ram_total_bytes, "B", false);
build_info_set_value_strdupz(BIB_RUNTIME_MEM_TOTAL, buf);
snprintfz(buf, sizeof(buf), "%" PRIu64, sm.ram_available_bytes);
// size_snprintf(buf, sizeof(buf), sm.ram_available_bytes, "B", false);
build_info_set_value_strdupz(BIB_RUNTIME_MEM_AVAIL, buf);
}
// ----------------------------------------------------------------------------
@ -1529,6 +1592,7 @@ void print_build_info(void) {
print_build_info_category_to_console(BIC_PLUGINS, "Plugins");
print_build_info_category_to_console(BIC_EXPORTERS, "Exporters");
print_build_info_category_to_console(BIC_DEBUG_DEVEL, "Debug/Developer Features");
print_build_info_category_to_console(BIC_RUNTIME, "Runtime Information");
}
void build_info_to_json_object(BUFFER *b) {
@ -1548,6 +1612,7 @@ void build_info_to_json_object(BUFFER *b) {
print_build_info_category_to_json(b, BIC_PLUGINS, "plugins");
print_build_info_category_to_json(b, BIC_EXPORTERS, "exporters");
print_build_info_category_to_json(b, BIC_DEBUG_DEVEL, "debug-n-devel");
print_build_info_category_to_json(b, BIC_RUNTIME, "runtime");
}
void print_build_info_json(void) {

View file

@ -227,6 +227,11 @@ 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();