forked from shacl/cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDelegatingOption.cmake
72 lines (61 loc) · 2.13 KB
/
DelegatingOption.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
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 "DelegatingOption" IN_LIST shacl.cmake.installed_modules)
set_property(GLOBAL APPEND PROPERTY
shacl.cmake.installed_modules "DelegatingOption")
install(
FILES "${CMAKE_CURRENT_LIST_FILE}"
DESTINATION share/cmake/shacl/.cmake)
endif()
unset(shacl.cmake.installed_modules)
endif()
include_guard(GLOBAL)
function(delegating_option variable)
set(OPTIONS)
set(UNARY_ARGUMENTS 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(do
"${OPTIONS}"
"${UNARY_ARGUMENTS}"
"${VARIADIC_ARGUMENTS}" ${arguments})
if(NOT DEFINED do_DEFAULT)
message(FATAL_ERROR
"delegating_option invoked without 'DEFAULT' argument")
endif()
if(do_DOCSTRING)
if(do_DOCSTRING MATCHES "\"(.*)\"")
set(do_DOCSTRING "${CMAKE_MATCH_1}")
endif()
string(CONCAT docstring
"${do_DOCSTRING}\n"
"When set to 'default', this variable assumes the value of ${do_DEFAULT} (${${do_DEFAULT}})")
else()
string(CONCAT docstring
"When set to 'default', this variable assumes the value of ${do_DEFAULT} (${${do_DEFAULT}})")
endif()
set(${variable} "default" CACHE STRING "${docstring}")
set_property(CACHE ${variable} PROPERTY HELPSTRING "${docstring}")
set_property(CACHE ${variable} PROPERTY STRINGS default ON OFF)
if(${variable} STREQUAL "default")
if(${do_DEFAULT})
set(${variable} ON PARENT_SCOPE)
else()
set(${variable} OFF PARENT_SCOPE)
endif()
endif()
endfunction()