diff --git a/CMakeLists.txt b/CMakeLists.txt index 86ffc710f5923e..1adb520ba69350 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ project(netdata HOMEPAGE_URL "https://www.netdata.cloud" LANGUAGES C CXX) include(CMakeDependentOption) +include(NetdataUtil) +netdata_fixup_system_processor() if(DEFINED BUILD_SHARED_LIBS) if(NOT BUILD_SHARED_LIBS) @@ -2167,11 +2169,13 @@ if(ENABLE_LIBUNWIND) if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(amd64)") target_link_libraries(libnetdata PUBLIC PkgConfig::LIBUNWIND -lunwind-x86_64) - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i?.86") + target_link_libraries(libnetdata PUBLIC PkgCOnfig::LIBUNWIND -lunwind-x86) + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(aarch64)") target_link_libraries(libnetdata PUBLIC PkgConfig::LIBUNWIND -lunwind-aarch64) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") target_link_libraries(libnetdata PUBLIC PkgConfig::LIBUNWIND -lunwind-arm) - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "powerpc|ppc") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "p(ower)?pc64") target_link_libraries(libnetdata PUBLIC PkgConfig::LIBUNWIND -lunwind-ppc64) else() message(WARNING "Unknown architecture ${CMAKE_SYSTEM_PROCESSOR} for libunwind. Stack traces may not work.") diff --git a/packaging/cmake/Modules/NetdataLibBPF.cmake b/packaging/cmake/Modules/NetdataLibBPF.cmake index 20261478f952f7..e2173d36676c39 100644 --- a/packaging/cmake/Modules/NetdataLibBPF.cmake +++ b/packaging/cmake/Modules/NetdataLibBPF.cmake @@ -59,7 +59,7 @@ function(netdata_bundle_libbpf) set(_libbpf_lib_dir lib) - if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(amd64)") set(_libbpf_lib_dir lib64) endif() diff --git a/packaging/cmake/Modules/NetdataUtil.cmake b/packaging/cmake/Modules/NetdataUtil.cmake index 02301314a43685..c86c2d3f83bf4e 100644 --- a/packaging/cmake/Modules/NetdataUtil.cmake +++ b/packaging/cmake/Modules/NetdataUtil.cmake @@ -3,6 +3,30 @@ include_guard() +# Fix up CMAKE_SYSTEM_PROCESSOR to actually match the build target +function(netdata_fixup_system_processor) + if(OS_WINDOWS) + return() + endif() + + if(CMAKE_TOOLCHAIN_FILE) + return() + endif() + + execute_process( + COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -dumpmachine + COMMAND cut -f 1 -d - + RESULT_VARIABLE return_code + OUTPUT_VARIABLE output_data + ) + + if(return_code EQUAL 0) + set(CMAKE_SYSTEM_PROCESSOR "${output_data}" PARENT_SCOPE) + else() + message(WARNING "Failed to detect target processor architecture, using CMake default") + endif() +endfunction() + # Determine the version of the host kernel. # # Only works on UNIX-like systems, stores the version in the cache