forked from commontk/CTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctkMacroTargetLibraries.cmake
242 lines (201 loc) · 8.56 KB
/
ctkMacroTargetLibraries.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
###########################################################################
#
# Library: CTK
#
# Copyright (c) Kitware Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
#!
#! This macro could be invoked using two different signatures:
#! ctkFunctionGetTargetLibraries(TARGET_LIBS)
#! or
#! ctkFunctionGetTargetLibraries(TARGET_LIBS "/path/to/ctk_target_dir")
#!
#! Without specifying the second argument, the current folder will be used.
#!
#! \ingroup CMakeUtilities
function(ctkFunctionGetTargetLibraries varname)
set(expanded_target_library_list)
set(TARGET_DIRECTORY ${ARGV1})
if("${TARGET_DIRECTORY}" STREQUAL "")
set(TARGET_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
set(filepath ${TARGET_DIRECTORY}/target_libraries.cmake)
set(manifestpath ${TARGET_DIRECTORY}/manifest_headers.cmake)
# Check if "target_libraries.cmake" or "manifest_headers.cmake" file exists
if(NOT EXISTS ${filepath} AND NOT EXISTS ${manifestpath})
message(FATAL_ERROR "${filepath} or ${manifestpath} doesn't exists !")
endif()
# Make sure the variable is cleared
set(target_libraries )
set(Require-Plugin )
if(EXISTS ${filepath})
# Let's make sure target_libraries contains only strings
file(STRINGS "${filepath}" stringtocheck) # read content of 'filepath' into 'stringtocheck'
string(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
foreach(incorrect_element ${incorrect_elements})
string(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
message(FATAL_ERROR "In ${filepath}, ${incorrect_element} should be replaced by ${correct_element}")
endforeach()
include(${filepath})
# Loop over all target library, if it does *NOT* start with "CTK",
# let's resolve the variable to access its content
foreach(target_library ${target_libraries})
if(${target_library} MATCHES "^CTK[a-zA-Z0-9]+$" OR
${target_library} MATCHES "^org_commontk_[a-zA-Z0-9_]+$")
list(APPEND expanded_target_library_list ${target_library})
else()
list(APPEND expanded_target_library_list "${${target_library}}")
endif()
endforeach()
endif()
if(EXISTS ${manifestpath})
# Let's make sure Require-Plugins contains only strings
file(STRINGS "${manifestpath}" stringtocheck) # read content of 'manifestpath' into 'stringtocheck'
string(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
foreach(incorrect_element ${incorrect_elements})
string(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
message(FATAL_ERROR "In ${manifestpath}, ${incorrect_element} should be replaced by ${correct_element}")
endforeach()
include(${manifestpath})
# Loop over all plugin dependencies,
foreach(plugin_symbolicname ${Require-Plugin})
string(REPLACE "." "_" plugin_library ${plugin_symbolicname})
list(APPEND expanded_target_library_list ${plugin_library})
endforeach()
endif()
# Pass the list of target libraries to the caller
set(${varname} ${expanded_target_library_list} PARENT_SCOPE)
endfunction()
#! \ingroup CMakeUtilities
function(ctkFunctionCollectTargetLibraryNames target_dir varname)
set(target_library_list)
#message(STATUS target:${target})
set(lib_targets)
set(filepath ${target_dir}/target_libraries.cmake)
set(manifestpath ${target_dir}/manifest_headers.cmake)
# Check if "target_libraries.cmake" or "manifest_headers.cmake" file exists
if(NOT EXISTS ${filepath} AND NOT EXISTS ${manifestpath})
message(FATAL_ERROR "${filepath} or ${manifestpath} doesn't exists !")
endif()
# Make sure the variable is cleared
set(target_libraries )
set(Require-Plugin )
if(EXISTS ${filepath})
# Let's make sure target_libraries contains only strings
file(STRINGS "${filepath}" stringtocheck) # read content of 'filepath' into 'stringtocheck'
string(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
foreach(incorrect_element ${incorrect_elements})
string(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
message(FATAL_ERROR "In ${filepath}, ${incorrect_element} should be replaced by ${correct_element}")
endforeach()
include(${filepath})
list(APPEND target_library_list ${target_libraries})
endif()
if(EXISTS ${manifestpath})
# Let's make sure Require-Plugins contains only strings
file(STRINGS "${manifestpath}" stringtocheck) # read content of 'manifestpath' into 'stringtocheck'
string(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
foreach(incorrect_element ${incorrect_elements})
string(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
message(FATAL_ERROR "In ${manifestpath}, ${incorrect_element} should be replaced by ${correct_element}")
endforeach()
include(${manifestpath})
# Loop over all plugin dependencies
foreach(plugin_symbolicname ${Require-Plugin})
string(REPLACE "." "_" plugin_library ${plugin_symbolicname})
list(APPEND target_library_list ${plugin_library})
endforeach()
endif()
list(REMOVE_DUPLICATES target_library_list)
# Pass the list of target libraries to the caller
set(${varname} ${target_library_list} PARENT_SCOPE)
endfunction()
#! \ingroup CMakeUtilities
macro(ctkMacroCollectAllTargetLibraries targets subdir varname)
set(option_prefix)
if(${subdir} STREQUAL "Libs")
set(option_prefix CTK_LIB_)
elseif(${subdir} STREQUAL "Plugins")
set(option_prefix CTK_PLUGIN_)
elseif(${subdir} STREQUAL "Applications")
set(option_prefix CTK_APP_)
else()
message(FATAL_ERROR "Unknown subdir:${subdir}, expected value are: 'Libs, 'Plugins' or 'Applications'")
endif()
foreach(target ${targets})
# Make sure the variable is cleared
set(target_libraries )
set(option_name ${option_prefix}${target})
#message(STATUS option_name:${option_name})
if(${target}_SOURCE_DIR)
set(target_dir "${${target}_SOURCE_DIR}")
else()
set(target_dir "${CTK_SOURCE_DIR}/${subdir}/${target}")
endif()
#message(STATUS target_dir:${target_dir})
set(target_libraries)
# Collect target libraries only if option is ON
if(${option_name})
ctkFunctionCollectTargetLibraryNames(${target_dir} target_libraries)
endif()
if(target_libraries)
list(APPEND ${varname} ${target_libraries})
list(REMOVE_DUPLICATES ${varname})
endif()
endforeach()
endmacro()
#!
#! Extract all library names which are build within this project
#!
#! \ingroup CMakeUtilities
macro(ctkMacroGetAllProjectTargetLibraries all_target_libraries varname)
# Allow external projects to override the set of internal targets
if(COMMAND GetMyTargetLibraries)
GetMyTargetLibraries("${all_target_libraries}" ${varname})
else()
set(re_ctklib "^(c|C)(t|T)(k|K)[a-zA-Z0-9]+$")
set(re_ctkplugin "^org_commontk_[a-zA-Z0-9_]+$")
set(_tmp_list)
list(APPEND _tmp_list ${all_target_libraries})
#message("calling ctkMacroListFilter with varname:${varname}")
ctkMacroListFilter(_tmp_list re_ctklib re_ctkplugin OUTPUT_VARIABLE ${varname})
#message(STATUS "getallctklibs from ${all_target_libraries}")
#message(STATUS varname:${varname}:${${varname}})
endif()
endmacro()
#!
#! Extract all library names *NOT* being build within this project
#!
#! \ingroup CMakeUtilities
macro(ctkMacroGetAllNonProjectTargetLibraries all_target_libraries varname)
ctkMacroGetAllProjectTargetLibraries("${all_target_libraries}" all_project_libraries)
set(_tmp_list ${all_target_libraries})
if(all_project_libraries)
list(REMOVE_ITEM _tmp_list ${all_project_libraries})
endif()
set(${varname} ${_tmp_list})
#message(varname:${varname}:${${varname}})
endmacro()
#! \ingroup CMakeUtilities
macro(ctkMacroShouldAddExternalProject libraries_variable_name resultvar)
set(${resultvar} FALSE)
if(DEFINED NON_CTK_DEPENDENCIES)
list(FIND NON_CTK_DEPENDENCIES ${libraries_variable_name} index)
if(${index} GREATER -1)
set(${resultvar} TRUE)
endif()
endif()
endmacro()