forked from shacl/cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeDependentSelection.cmake
More file actions
78 lines (67 loc) · 2.51 KB
/
CMakeDependentSelection.cmake
File metadata and controls
78 lines (67 loc) · 2.51 KB
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
77
78
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 "CMakeDependentSelection" IN_LIST shacl.cmake.installed_modules)
set_property(GLOBAL APPEND PROPERTY
shacl.cmake.installed_modules "CMakeDependentSelection")
install(
FILES "${CMAKE_CURRENT_LIST_FILE}"
DESTINATION share/cmake/shacl/.cmake)
endif()
unset(shacl.cmake.installed_modules)
endif()
include(Selection)
include_guard(GLOBAL)
function(CMAKE_DEPENDENT_SELECTION variable docstring)
cmake_parse_arguments(${variable}_selection
"" "DEFAULT;CONDITION" OPTIONS ${ARGN})
if(NOT DEFINED ${variable}_selection_OPTIONS)
message(FATAL_ERROR
"CMAKE_DEPENDENT_SELECTION invoked without 'OPTIONS' keyword")
endif()
if(NOT DEFINED ${variable}_selection_CONDITION)
message(FATAL_ERROR
"CMAKE_DEPENDENT_SELECTION invoked without 'CONDITION' keyword")
endif()
if(NOT DEFINED ${variable}_selection_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"CMAKE_DEPENDENT_SELECTION invoked without fallback value")
else()
list(GET ${variable}_selection_UNPARSED_ARGUMENTS "0"
${variable}_selection_fallback)
list(REMOVE_AT ${variable}_selection_UNPARSED_ARGUMENTS "0")
if(${variable}_selection_UNPARSED_ARGUMENTS)
message("CMAKE_DEPENDENT_SELECTION called with unparsed arguments")
message(FATAL_ERROR "unparsed arguments: ${${variable}_selection_UNPARSED_ARGUMENTS}")
endif()
endif()
set(${variable}_selection_AVAILABLE TRUE)
foreach(condition ${${variable}_selection_CONDITION})
string(REGEX REPLACE " +" ";" condition "${condition}")
if(${condition})
else()
set(${variable}_selection_AVAILABLE FALSE)
endif()
endforeach()
if(${variable}_selection_AVAILABLE)
if(DEFINED ${variable}_selection_DEFAULT)
selection(${variable}
DOCSTRING "${docstring}"
DEFAULT "${${variable}_selection_DEFAULT}"
OPTIONS "${${variable}_selection_OPTIONS}")
else()
selection(${variable}
DOCSTRING "${docstring}"
OPTIONS "${${variable}_selection_OPTIONS}")
endif()
set(${variable} "${${variable}}" CACHE STRING "${docstring}" FORCE)
else()
if(DEFINED ${variable})
set(${variable} "${${variable}}" CACHE INTERNAL "${docstring}")
endif()
set(${variable} "${${variable}_selection_fallback}" PARENT_SCOPE)
endif()
endfunction()