forked from shacl/cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDelegatingCacheVariable.cmake
76 lines (63 loc) · 2.31 KB
/
DelegatingCacheVariable.cmake
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
cmake_minimum_required(VERSION 3.12.1)
include_guard(DIRECTORY)
include("${CMAKE_CURRENT_LIST_DIR}/config.cmake")
if(shacl.cmake.installation)
get_property(
shacl.cmake.installed_modules GLOBAL PROPERTY shacl.cmake.installed_modules)
if(NOT "DelegatingCacheVariable" IN_LIST shacl.cmake.installed_modules)
set_property(GLOBAL APPEND PROPERTY
shacl.cmake.installed_modules "DelegatingCacheVariable")
install(
FILES "${CMAKE_CURRENT_LIST_FILE}"
DESTINATION share/cmake/shacl/.cmake)
endif()
unset(shacl.cmake.installed_modules)
endif()
include_guard(GLOBAL)
function(delegating_cache_variable variable)
set(OPTIONS)
set(UNARY_ARGUMENTS TYPE DEFAULT DOCSTRING)
set(VARIADIC_ARGUMENTS)
set(arguments)
foreach(argument IN LISTS ARGN)
if(argument STREQUAL "" # argument empty string
OR argument MATCHES ".*[ ].*" # argument with embedded whitespace
OR argument MATCHES ".*[;].*" # argument list
OR argument MATCHES ".*\".*") # argument with embedded quotation
list(APPEND arguments "\"${argument}\"")
else()
list(APPEND arguments "${argument}")
endif()
endforeach()
cmake_parse_arguments(dcv
"${OPTIONS}"
"${UNARY_ARGUMENTS}"
"${VARIADIC_ARGUMENTS}" ${arguments})
if(NOT DEFINED dcv_DEFAULT)
message(FATAL_ERROR
"delegating_cache_variable invoked without 'DEFAULT' argument")
endif()
if(NOT DEFINED dcv_TYPE)
message(FATAL_ERROR
"delegating_cache_variable invoked without 'TYPE' argument")
endif()
set(valid_types FILEPATH PATH STRING BOOL INTERNAL)
if(NOT dcv_TYPE IN_LIST valid_types)
message("delegating_cache_variable error")
message("TYPE argument value: ${dcv_TYPE}")
message(FATAL_ERROR
"TYPE argument must be one of FILEPATH, PATH, STRING, BOOL, or INTERNAL")
endif()
if(dcv_DOCSTRING)
string(CONCAT docstring
"${dcv_DOCSTRING}\n"
"When set to 'default', this variable assumes the value of ${dcv_DEFAULT} ('${${dcv_DEFAULT}}')")
else()
string(CONCAT docstring
"When set to 'default', this variable assumes the value of ${dcv_DEFAULT} ('${${dcv_DEFAULT}}')")
endif()
set(${variable} "default" CACHE ${dcv_TYPE} "${docstring}")
if(${variable} STREQUAL "default")
set(${variable} "${${dcv_DEFAULT}}" PARENT_SCOPE)
endif()
endfunction()