GetProperties.cmake 2.4 KB

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