NetdataFetchContentExtra.cmake 935 B

123456789101112131415161718192021222324252627
  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()