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