-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMDEF_COMPILE_OPTION.cmake
More file actions
137 lines (122 loc) · 3.37 KB
/
CMDEF_COMPILE_OPTION.cmake
File metadata and controls
137 lines (122 loc) · 3.37 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
## Main
#
# Functions for managing Build options
#
#
INCLUDE_GUARD(GLOBAL)
FIND_PACKAGE(CMLIB REQUIRED)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/CMDEF_BUILD_TYPE.cmake)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/CMDEF_ADD_LIBRARY.cmake)
##
# Add build option for given BUILD type.
#
# ALL is list of compile options which will be add
# to each BUILD_TYPE
#
# BUILD_TYPE_UPPERCASE is uppercase version of build_type
# from BUILD_TYPE list.
#
# LANG - array, If specified must be on CMDEF_SUPPORTED_LANG_LIST.
# If not specified no exact language is select
#
# Each definition is passed to ADD_COMPILE_OPTIONS
# by generator_expression $<<CONFIG:build_type>:${option}>
#
# <function>(
# [LANG <lang> M]
# [ALL <compile_options>]
# [<BUILD_TYPE_UPERCASE> <compile_options>]{1,}
# )
#
MACRO(CMDEF_COMPILE_OPTIONS)
CMLIB_PARSE_ARGUMENTS(
MULTI_VALUE
LANG ALL
${CMDEF_BUILD_TYPE_LIST_UPPERCASE}
P_ARGN ${ARGN}
)
IF(DEFINED __LANG)
CMUTIL_TRAIT_IN_ARRAY(VALUES ${__LANG} ARRAY CMDEF_SUPPORTED_LANG_LIST
DESCRIPTION "Unsupported language")
ENDIF()
FOREACH(build_type IN LISTS CMDEF_BUILD_TYPE_LIST_UPPERCASE)
SET(build_type_var __${build_type})
IF(DEFINED __ALL)
LIST(APPEND ${build_type_var} ${__ALL})
ENDIF()
IF(NOT DEFINED ${build_type_var})
CONTINUE()
ENDIF()
FOREACH(option IN LISTS ${build_type_var})
IF(DEFINED __LANG)
SET(condition $<AND:$<COMPILE_LANGUAGE:${__LANG}>,$<CONFIG:${build_type}>>)
SET(compile_options $<${condition}:${option}>)
ADD_COMPILE_OPTIONS(${compile_options})
ELSE()
ADD_COMPILE_OPTIONS($<$<CONFIG:${build_type}>:${option}>)
ENDIF()
ENDFOREACH()
UNSET(${build_type_var})
ENDFOREACH()
ENDMACRO()
##
#
# BUILD_TYPE_UPPERCASE is uppercase version of build_type
# from BUILD_TYPE list.
#
# ALL is list of compile options which will be add
# to each BUILD_TYPE
#
# LANG - array, if specified must be one of CMDEF_SUPPORTED_LANG_LIST.
# If not specified no exact language is select
#
# Each definition is passed to ADD_COMPILE_OPTIONS
# by generator_expression $<<CONFIG:build_type>:${option}>
#
# VISIBILITY is passed to visibility section of TARGET_LINK_OPTIONS.
# If no visibility specified than visibility is omitted
#
# <function> (
# TARGET <target>
# [LANG <lang_list>]
# [ALL <compile_options>]
# [<BUILD_TYPE_UPPERCASE> <link_options>]{1,}
# [VISIBILITY <INTERFACE|PUBLIC|PRIVATE>]
# )
#
FUNCTION(CMDEF_COMPILE_OPTIONS_TARGET)
CMLIB_PARSE_ARGUMENTS(
MULTI_VALUE
LANG ALL
${CMDEF_BUILD_TYPE_LIST_UPPERCASE}
ONE_VALUE
TARGET
VISIBILITY
REQUIRED
TARGET
VISIBILITY
P_ARGN ${ARGN}
)
IF(DEFINED __LANG)
CMUTIL_TRAIT_IN_ARRAY(VALUES ${__LANG} ARRAY CMDEF_SUPPORTED_LANG_LIST
DESCRIPTION "Unsupported language")
ENDIF()
SET(original_target_name ${__TARGET})
FOREACH(build_type IN LISTS CMDEF_BUILD_TYPE_LIST_UPPERCASE)
SET(build_type_var __${build_type})
IF(DEFINED __ALL)
LIST(APPEND ${build_type_var} ${__ALL})
ENDIF()
IF(NOT DEFINED ${build_type_var})
CONTINUE()
ENDIF()
IF(DEFINED __LANG)
SET(option ${${build_type_var}})
SET(condition $<AND:$<COMPILE_LANGUAGE:${__LANG}>,$<CONFIG:${build_type}>>)
SET(compile_options $<${condition}:${option}>)
TARGET_COMPILE_OPTIONS(${original_target_name} ${__VISIBILITY} ${compile_options})
ELSE()
TARGET_COMPILE_OPTIONS(${original_target_name} ${__VISIBILITY} $<$<CONFIG:${build_type}>:${${build_type_var}}>)
ENDIF()
ENDFOREACH()
ENDFUNCTION()