GetProperties.cmake 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. cmake_policy(SET CMP0169 OLD)
  2. include(FetchContent)
  3. # First confirm properties are empty even before declare
  4. FetchContent_GetProperties(t1)
  5. if(t1_POPULATED)
  6. message(FATAL_ERROR "Property says populated before doing anything")
  7. endif()
  8. if(t1_SOURCE_DIR)
  9. message(FATAL_ERROR "SOURCE_DIR property not initially empty")
  10. endif()
  11. if(t1_BINARY_DIR)
  12. message(FATAL_ERROR "BINARY_DIR property not initially empty")
  13. endif()
  14. # Declare, but no properties should change yet
  15. FetchContent_Declare(
  16. t1
  17. SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/savedSrc
  18. BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/savedBin
  19. DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E echo "Do nothing"
  20. )
  21. FetchContent_GetProperties(t1)
  22. if(t1_POPULATED)
  23. message(FATAL_ERROR "Property says populated after only declaring details")
  24. endif()
  25. if(t1_SOURCE_DIR)
  26. message(FATAL_ERROR "SOURCE_DIR property not empty after declare")
  27. endif()
  28. if(t1_BINARY_DIR)
  29. message(FATAL_ERROR "BINARY_DIR property not empty after declare")
  30. endif()
  31. # Populate should make all properties non-empty/set
  32. FetchContent_Populate(t1)
  33. FetchContent_GetProperties(t1)
  34. if(NOT t1_POPULATED)
  35. message(FATAL_ERROR "Population did not set POPULATED property")
  36. endif()
  37. if(NOT "${t1_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/savedSrc")
  38. message(FATAL_ERROR "SOURCE_DIR property not correct after population: "
  39. "${t1_SOURCE_DIR}\n"
  40. " Expected: ${CMAKE_CURRENT_BINARY_DIR}/savedSrc")
  41. endif()
  42. if(NOT "${t1_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/savedBin")
  43. message(FATAL_ERROR "BINARY_DIR property not correct after population: "
  44. "${t1_BINARY_DIR}\n"
  45. " Expected: ${CMAKE_CURRENT_BINARY_DIR}/savedBin")
  46. endif()
  47. # Verify we can retrieve properties individually too
  48. FetchContent_GetProperties(t1 POPULATED varPop)
  49. FetchContent_GetProperties(t1 SOURCE_DIR varSrc)
  50. FetchContent_GetProperties(t1 BINARY_DIR varBin)
  51. if(NOT varPop)
  52. message(FATAL_ERROR "Failed to retrieve POPULATED property")
  53. endif()
  54. if(NOT "${varSrc}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/savedSrc")
  55. message(FATAL_ERROR "SOURCE_DIR property not retrieved correctly: ${varSrc}\n"
  56. " Expected: ${CMAKE_CURRENT_BINARY_DIR}/savedSrc")
  57. endif()
  58. if(NOT "${varBin}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/savedBin")
  59. message(FATAL_ERROR "BINARY_DIR property not retrieved correctly: ${varBin}\n"
  60. " Expected: ${CMAKE_CURRENT_BINARY_DIR}/savedBin")
  61. endif()