summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/CMP0160/READONLY_PROPERTIES.cmake
blob: 07bbe789a7ef7bb2f27b361632407405643b9291 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

set(read_only_properties
  "HEADER_SETS"
  "INTERFACE_HEADER_SETS"
  "MANUALLY_ADDED_DEPENDENCIES"
  "NAME"
  "TYPE"
  )
set(read_only_properties_imported
  "EXPORT_NAME"
  "SOURCES"
  )
set(read_only_properties_nonimported
  "IMPORTED_GLOBAL"
  )
set(read_only_properties_160
    "ALIAS_GLOBAL"
    "BINARY_DIR"
    "CXX_MODULE_SETS"
    "IMPORTED"
    "INTERFACE_CXX_MODULE_SETS"
    "LOCATION"
    "LOCATION_CONFIG"
    "SOURCE_DIR"
    )

cmake_policy(GET CMP0160 policy160)
add_library(ReadOnlyLib )
add_library(ReadOnlyImport IMPORTED UNKNOWN)

foreach(target ReadOnlyLib ReadOnlyImport)
  get_target_property(is_imported ${target} IMPORTED)
  set(are_read_only ${read_only_properties})
  if(NOT policy160 STREQUAL "OLD")
    list(APPEND are_read_only ${read_only_properties_160})
  endif()
  if(is_imported)
    list(APPEND are_read_only ${read_only_properties_imported})
  else()
    list(APPEND are_read_only ${read_only_properties_nonimported})
  endif()

  foreach(prop IN LISTS are_read_only)
    set_target_properties(${target} PROPERTIES ${prop} "a_value")
  endforeach()

  if(policy160 STREQUAL "OLD")
    foreach(prop IN LISTS read_only_properties_160)
      set_target_properties(${target} PROPERTIES ${prop} "a_value")
    endforeach()
  endif()
endforeach()