forked from shacl/cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeDependentCacheVar.cmake
More file actions
50 lines (43 loc) · 1.57 KB
/
CMakeDependentCacheVar.cmake
File metadata and controls
50 lines (43 loc) · 1.57 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
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 "CMakeDependentCacheVar" IN_LIST shacl.cmake.installed_modules)
set_property(GLOBAL APPEND PROPERTY
shacl.cmake.installed_modules "CMakeDependentCacheVar")
install(
FILES "${CMAKE_CURRENT_LIST_FILE}"
DESTINATION share/cmake/shacl/.cmake)
endif()
unset(shacl.cmake.installed_modules)
endif()
include_guard(GLOBAL)
function(CMAKE_DEPENDENT_CACHE_VAR variable type docstring default conditions force)
set(type_list FILEPATH PATH STRING BOOL INTERNAL)
list(FIND type_list ${type} type_found)
if( type_found LESS 0 )
message("CMAKE_DEPENDENT_CACHE_VAR error: variable type")
message(FATAL_ERROR
"'${type}' must be one of FILEPATH, PATH, STRING, BOOL, or INTERNAL")
endif()
set(${variable}_AVAILABLE TRUE)
foreach(condition ${conditions})
string(REGEX REPLACE " +" ";"
CMAKE_DEPENDENT_VARIABLE_DEP "${condition}")
if(${CMAKE_DEPENDENT_VARIABLE_DEP})
else()
set(${variable}_AVAILABLE FALSE)
endif()
endforeach()
if(${variable}_AVAILABLE)
set(${variable} "${default}" CACHE "${type}" "${docstring}")
set(${variable} "${${variable}}" CACHE "${type}" "${docstring}" FORCE)
else()
if(DEFINED ${variable})
set(${variable} "${${variable}}" CACHE INTERNAL "${docstring}")
endif()
set(${variable} "${force}" PARENT_SCOPE)
endif()
endfunction()