forked from cmakelib/cmakelib-component-cmdef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMDEF_COMPILE_DEFINITION.cmake
136 lines (122 loc) · 3.53 KB
/
CMDEF_COMPILE_DEFINITION.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
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
#
# Compile definition - set compile definitions (global or for target)
#
IF(DEFINED CMDEF_COMPILE_DEFINITION_MODULE)
RETURN()
ENDIF()
SET(CMDEF_COMPILE_DEFINITION_MODULE 1)
FIND_PACKAGE(CMLIB)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/CMDEF_BUILD_TYPE.cmake)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/CMDEF_ADD_LIBRARY.cmake)
##
# Add global compile definitions for given build type.
#
# ALL is list of definitions 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 one of CMDEF_SUPPORTED_LANG_LIST.
# If not specified no exact languege is select
#
# Each definition is passed to ADD_COMPILE_DEFINITION
# by generator_expression $<<CONFIG:build_type>:${definitnion}>
#
# <function>(
# [LANG <lang>]
# [ALL <compile_definitions>]
# [<BUILD_TYPE_UPERCASE> <compile_definitions>]{1,}
# )
#
FUNCTION(CMDEF_COMPILE_DEFINITIONS)
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(definition IN LISTS ${build_type_var})
IF(DEFINED __LANG)
SET(condition $<AND:$<COMPILE_LANGUAGE:${__LANG}>,$<CONFIG:${build_type}>>)
SET(compile_definitions $<${condition}:${definition}>)
ADD_COMPILE_DEFINITIONS(${compile_definitions})
ELSE()
ADD_COMPILE_DEFINITIONS($<$<CONFIG:${build_type}>:${definition}>)
ENDIF()
ENDFOREACH()
ENDFOREACH()
ENDFUNCTION()
##
# Set compile options for given target
#
# ALL is list of definitions 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 one of CMDEF_SUPPORTED_LANG_LIST.
# If not specified no exact languege is select
#
# Each definition is passed to TARGET_COMPILE_DEFINITION
# by generator_expression $<<CONFIG:build_type>:${definitnion}>
#
# VISIBLITY is passed to visiblity section of TARGET_LINK_OPTIONS.
# If no visiblity specified than visiblity is omitted
#
# <function>(
# TARGET <target>
# [LANG <lang> M]
# [ALL <compile_definitions>]
# [<BUILD_TYPE_UPPERCASE> <link_options>]{1,}
# [VISIBLITY <INTERFACE|PUBLIC|PRIVATE>]
# )
#
FUNCTION(CMDEF_COMPILE_DEFINITIONS_TARGET)
CMLIB_PARSE_ARGUMENTS(
MULTI_VALUE
LANG ALL
${CMDEF_BUILD_TYPE_LIST_UPPERCASE}
ONE_VALUE
TARGET
VISIBLITY
REQUIRED
TARGET VISIBLITY
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(condition $<AND:$<COMPILE_LANGUAGE:${__LANG}>,$<CONFIG:${build_type}>>)
SET(compile_definitions $<${condition}:${${build_type_var}}>)
TARGET_COMPILE_DEFINITIONS(${original_target_name} ${__VISIBLITY} ${compile_definitions})
ELSE()
TARGET_COMPILE_DEFINITIONS(${original_target_name} ${__VISIBLITY} $<$<CONFIG:${build_type}>:${${build_type_var}}>)
ENDIF()
ENDFOREACH()
ENDFUNCTION()