NetdataFetchContentExtra.cmake 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Extra tools for working with FetchContent on older CMake
  2. #
  3. # Copyright (c) 2024 Netdata Inc.
  4. # SPDX-License-Identifier: GPL-3.0-or-later
  5. # FetchContent_MakeAvailable_NoInstall
  6. #
  7. # Add a sub-project with FetchContent, but with the EXCLUDE_FROM_ALL
  8. # argument for the add_subdirectory part.
  9. #
  10. # CMake 3.28 and newer provide a way to do this with an extra argument
  11. # on FetchContent_Declare, but older versions need you to implement
  12. # the logic yourself. Once we no longer support CMake versions older
  13. # than 3.28, we can get rid of this macro.
  14. #
  15. # Unlike FetchContent_MakeAvailble, this only accepts a single project
  16. # to make available.
  17. macro(FetchContent_MakeAvailable_NoInstall name)
  18. include(FetchContent)
  19. FetchContent_GetProperties(${name})
  20. if(NOT ${name}_POPULATED)
  21. FetchContent_Populate(${name})
  22. add_subdirectory(${${name}_SOURCE_DIR} ${${name}_BINARY_DIR} EXCLUDE_FROM_ALL)
  23. endif()
  24. endmacro()
  25. # NETDATA_PROPAGATE_TOOLCHAIN_ARGS
  26. #
  27. # Defines a set of CMake flags to be passed to CMAKE_ARGS for
  28. # FetchContent_Declare and ExternalProject_Add to ensure that toolchain
  29. # configuration propagates correctly to sub-projects.
  30. #
  31. # This needs to be explicitly included for any sub-project that needs
  32. # to be built for the target system.
  33. set(NETDATA_PROPAGATE_TOOLCHAIN_ARGS
  34. "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  35. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
  36. $<$<BOOL:${CMAKE_C_COMPILER_TARGET}>:-DCMAKE_C_COMPILER_TARGET=${CMAKE_C_COMPILER_TARGET}
  37. $<$<BOOL:${CMAKE_CXX_COMPILER_TARGET}>:-DCMAKE_CXX_COMPILER_TARGET=${CMAKE_CXX_COMPILER_TARGET}")