forked from sgumhold/cgv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcgv-options.cmake
74 lines (66 loc) · 2.62 KB
/
cgv-options.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
# global options list
set(CGV_OPTIONS_LIST "")
# declares a CMake option equivalent to some native PPP-based CGV option
function(cgv_define_option OPTION_NAME)
cmake_parse_arguments(
PARSE_ARGV 1 CGVARG_
"" "DOC;DEFAULT" ""
)
# add new option to list
set(CGV_OPTIONS_LIST_LOCAL ${CGV_OPTIONS_LIST})
list(APPEND CGV_OPTIONS_LIST_LOCAL ${OPTION_NAME})
# propagate upwards
set(CGV_OPTIONS_LIST ${CGV_OPTIONS_LIST_LOCAL} PARENT_SCOPE)
set(CGV_${OPTION_NAME}_DOC ${CGVARG__DOC} PARENT_SCOPE)
set(CGV_${OPTION_NAME}_INIT ${CGVARG__DEFAULT} PARENT_SCOPE)
endfunction()
# handles declaring CGV options to CMake and initializing them
function(cgv_init_cgvoptions)
# read current environment and prepare bookkeeping
set(CGV_OPTIONS_ENV "$ENV{CGV_OPTIONS}")
set(CGV_OPTIONS_LOCAL "")
set(CGV_OPTIONS_FROM_SYSTEM FALSE)
# handle each declared CGV option
set(CGV_OPTIONS "")
# - check for each option whether it needs initializing and from where
foreach(CGV_OPTION ${CGV_OPTIONS_LIST})
if (NOT DEFINED CGV_${CGV_OPTION})
if (DEFINED ENV{CGV_OPTIONS})
if (${CGV_OPTION} IN_LIST CGV_OPTIONS_ENV)
set(CGV_${CGV_OPTION}_INIT ON)
else()
set(CGV_${CGV_OPTION}_INIT OFF)
endif()
set(CGV_OPTIONS_FROM_SYSTEM TRUE)
list(APPEND CGV_OPTIONS_LOCAL "${CGV_OPTION}=${CGV_${CGV_OPTION}_INIT}")
endif()
endif()
option(CGV_${CGV_OPTION} ${CGV_${CGV_OPTION}_DOC} ${CGV_${CGV_OPTION}_INIT})
if (CGV_${CGV_OPTION})
list(APPEND CGV_OPTIONS "${CGV_OPTION}")
endif()
endforeach()
# - make sure the resulting CGV_OPTIONS string is available to any and all parent project(s) using the CGV Framework
set(CGV_OPTIONS ${CGV_OPTIONS} CACHE INTERNAL
"The CGV_OPTIONS string resulting from the chosen CMake options (for overriding local tool environments)" FORCE)
# print summary of options applied from system-wide configuration, if any
if (CGV_OPTIONS_FROM_SYSTEM)
message("---------------------------------------------------------")
message(" Following CGV options were initialized with values")
message(" from the system-wide CGV configuration:")
foreach(CGV_OPTION ${CGV_OPTIONS_LOCAL})
# print enabled options in default color, and disabled ones in highlight color
if (CGV_${CGV_OPTION} MATCHES "[oO][nN]$")
message(STATUS " ${CGV_OPTION}")
else()
message(" ${CGV_OPTION}")
endif()
endforeach()
message("---------------------------------------------------------")
endif()
# schedule an info message about enabled options after first configuration pass is done
cmake_language(
DEFER DIRECTORY ${CGV_DIR}
CALL message STATUS "Using CGV_OPTIONS string: \"${CGV_OPTIONS}\""
)
endfunction()