-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMDEF_LINK_OPTION.cmake
More file actions
134 lines (120 loc) · 3.33 KB
/
CMDEF_LINK_OPTION.cmake
File metadata and controls
134 lines (120 loc) · 3.33 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
## Main
#
# Link options - set link options (global or for target)
#
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)
##
#
# BUILD_TYPE_UPPERCASE is uppercase version of build_type
# from BUILD_TYPE list.
#
# ALL is list of link 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_LINK_OPTIONS
# by generator_expression $<<CONFIG:build_type>:${option}>
#
# <function>(
# [LANG <lang> M]
# [ALL <compile_options>]
# [<BUILD_TYPE_UPERCASE> <link_options>]{1,}
# )
#
FUNCTION(CMDEF_LINK_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})
# CONFIG generator expression is case insensitive against value
IF(DEFINED __LANG)
SET(condition $<AND:$<COMPILE_LANGUAGE:${__LANG}>,$<CONFIG:${build_type}>>)
SET(link_options $<${condition}:${option}>)
ADD_LINK_OPTIONS(${link_options})
ELSE()
ADD_LINK_OPTIONS($<$<CONFIG:${build_type}>:${option}>)
ENDIF()
ENDFOREACH()
ENDFOREACH()
ENDFUNCTION()
##
# Add link options to given target.
#
# BUILD_TYPE_UPPERCASE is uppercase version of build_type
# from BUILD_TYPE list.
#
# ALL is list of link 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_LINK_OPTIONS
# by generator_expression $<<CONFIG:build_type>:${option}>
#
# VISIBILITY is passed to visibility section of TARGET_LINK_OPTIONS.
#
# <function>(
# TARGET <target>
# [LANG <lang> M]
# [ALL <compile_options>]
# [<BUILD_TYPE_UPPERCASE> <link_options>]{1,}
# [VISIBILITY <INTERFACE|PUBLIC|PRIVATE>]
# )
#
FUNCTION(CMDEF_LINK_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(link_options $<${condition}:${option}>)
TARGET_LINK_OPTIONS(${original_target_name} ${__VISIBILITY} ${link_options})
ELSE()
TARGET_LINK_OPTIONS(${original_target_name} ${__VISIBILITY} $<$<CONFIG:${build_type}>:${${build_type_var}}>)
ENDIF()
ENDFOREACH()
ENDFUNCTION()