summaryrefslogtreecommitdiffstats
path: root/packaging
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2024-05-24 07:13:25 -0400
committerGitHub <noreply@github.com>2024-05-24 14:13:25 +0300
commite81a8d826cbab4b74fbca5c16e2d4fe683cecbf6 (patch)
tree1fd424e5892a701e4d8ec04613025dcd7d255467 /packaging
parent66b6f334c41cb660bcd9e44e8392b57c8a07d218 (diff)
Ensure that the choice of compiler and target is passed to sub-projects. (#17732)
If not explicitly set using exported environment variables, the choice of compilers and compiler targets used by CMake does not get propagated to sub-porjects created with ExternalProject_Add or FetchContent_Declare. In most cases this does not matter, because very few people are building using non-default compilers for their environment, but it can cause issues in two specific cases: - If building for the same system that the build is happening on, but using a non-default compiler specified using CMake arguments (instead of via exported environment variables), sub-projects will still use the default compiler for the system, which may result in linking errors (or runtime failures even if the link succeeds). - If cross-compiling and not using the preferred approaches of either a toolchain file or exported environment variables, sub-projects may not even build for the correct CPU architecture, causing the build to fail. This adds logic to ensure that the compiler and compiler targets get propagated correctly even if they are just specified on the command line, thus avoiding the above two possibilities.
Diffstat (limited to 'packaging')
-rw-r--r--packaging/cmake/Modules/NetdataFetchContentExtra.cmake14
-rw-r--r--packaging/cmake/Modules/NetdataJSONC.cmake1
-rw-r--r--packaging/cmake/Modules/NetdataProtobuf.cmake2
-rw-r--r--packaging/cmake/Modules/NetdataSentry.cmake1
-rw-r--r--packaging/cmake/Modules/NetdataYAML.cmake1
5 files changed, 19 insertions, 0 deletions
diff --git a/packaging/cmake/Modules/NetdataFetchContentExtra.cmake b/packaging/cmake/Modules/NetdataFetchContentExtra.cmake
index 1de1dcef92..cc70448de5 100644
--- a/packaging/cmake/Modules/NetdataFetchContentExtra.cmake
+++ b/packaging/cmake/Modules/NetdataFetchContentExtra.cmake
@@ -25,3 +25,17 @@ macro(FetchContent_MakeAvailable_NoInstall name)
add_subdirectory(${${name}_SOURCE_DIR} ${${name}_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endmacro()
+
+# NETDATA_PROPAGATE_TOOLCHAIN_ARGS
+#
+# Defines a set of CMake flags to be passed to CMAKE_ARGS for
+# FetchContent_Declare and ExternalProject_Add to ensure that toolchain
+# configuration propagates correctly to sub-projects.
+#
+# This needs to be explicitly included for any sub-project that needs
+# to be built for the target system.
+set(NETDATA_PROPAGATE_TOOLCHAIN_ARGS
+ "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+ -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
+ $<$<BOOL:${CMAKE_C_COMPILER_TARGET}>:-DCMAKE_C_COMPILER_TARGET=${CMAKE_C_COMPILER_TARGET}
+ $<$<BOOL:${CMAKE_CXX_COMPILER_TARGET}>:-DCMAKE_CXX_COMPILER_TARGET=${CMAKE_CXX_COMPILER_TARGET}")
diff --git a/packaging/cmake/Modules/NetdataJSONC.cmake b/packaging/cmake/Modules/NetdataJSONC.cmake
index 331d159c27..c9514d1cab 100644
--- a/packaging/cmake/Modules/NetdataJSONC.cmake
+++ b/packaging/cmake/Modules/NetdataJSONC.cmake
@@ -40,6 +40,7 @@ function(netdata_bundle_jsonc)
FetchContent_Declare(json-c
GIT_REPOSITORY https://github.com/json-c/json-c
GIT_TAG b4c371fa0cbc4dcbaccc359ce9e957a22988fb34 # json-c-0.17-20230812
+ CMAKE_ARGS ${NETDATA_CMAKE_PROPAGATE_TOOLCHAIN_ARGS}
)
FetchContent_MakeAvailable_NoInstall(json-c)
diff --git a/packaging/cmake/Modules/NetdataProtobuf.cmake b/packaging/cmake/Modules/NetdataProtobuf.cmake
index e00113bf35..44f9afc191 100644
--- a/packaging/cmake/Modules/NetdataProtobuf.cmake
+++ b/packaging/cmake/Modules/NetdataProtobuf.cmake
@@ -33,6 +33,7 @@ function(netdata_bundle_protobuf)
FetchContent_Declare(absl
GIT_REPOSITORY https://github.com/abseil/abseil-cpp
GIT_TAG ${ABSL_TAG}
+ CMAKE_ARGS ${NETDATA_CMAKE_PROPAGATE_TOOLCHAIN_ARGS}
)
FetchContent_MakeAvailable_NoInstall(absl)
message(STATUS "Finished preparing bundled Abseil")
@@ -47,6 +48,7 @@ function(netdata_bundle_protobuf)
FetchContent_Declare(protobuf
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
GIT_TAG ${PROTOBUF_TAG}
+ CMAKE_ARGS ${NETDATA_CMAKE_PROPAGATE_TOOLCHAIN_ARGS}
)
FetchContent_MakeAvailable_NoInstall(protobuf)
message(STATUS "Finished preparing bundled Protobuf.")
diff --git a/packaging/cmake/Modules/NetdataSentry.cmake b/packaging/cmake/Modules/NetdataSentry.cmake
index 518dcf0322..478c77498c 100644
--- a/packaging/cmake/Modules/NetdataSentry.cmake
+++ b/packaging/cmake/Modules/NetdataSentry.cmake
@@ -28,6 +28,7 @@ function(netdata_bundle_sentry)
sentry
GIT_REPOSITORY https://github.com/getsentry/sentry-native.git
GIT_TAG c97bcc63fa89ae557cef9c9b6e3acb11a72ff97d # v0.6.6
+ CMAKE_ARGS ${NETDATA_CMAKE_PROPAGATE_TOOLCHAIN_ARGS}
)
FetchContent_MakeAvailable(sentry)
endfunction()
diff --git a/packaging/cmake/Modules/NetdataYAML.cmake b/packaging/cmake/Modules/NetdataYAML.cmake
index fea316ec9b..1264cb2deb 100644
--- a/packaging/cmake/Modules/NetdataYAML.cmake
+++ b/packaging/cmake/Modules/NetdataYAML.cmake
@@ -23,6 +23,7 @@ function(netdata_bundle_libyaml)
FetchContent_Declare(yaml
GIT_REPOSITORY https://github.com/yaml/libyaml
GIT_TAG 2c891fc7a770e8ba2fec34fc6b545c672beb37e6 # v0.2.5
+ CMAKE_ARGS ${NETDATA_CMAKE_PROPAGATE_TOOLCHAIN_ARGS}
)
FetchContent_MakeAvailable_NoInstall(yaml)