-
Notifications
You must be signed in to change notification settings - Fork 0
/
BLTPrivateMacros.cmake
270 lines (219 loc) · 9.9 KB
/
BLTPrivateMacros.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
###############################################################################
# Copyright (c) 2017, Lawrence Livermore National Security, LLC.
#
# Produced at the Lawrence Livermore National Laboratory
#
# LLNL-CODE-725085
#
# All rights reserved.
#
# This file is part of BLT.
#
# For additional details, please also read BLT/LICENSE.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the disclaimer below.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the disclaimer (as noted below) in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of the LLNS/LLNL nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
# LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
###############################################################################
include(CMakeParseArguments)
## Internal BLT CMake Macros
##------------------------------------------------------------------------------
## blt_copy_headers_target( NAME [name] HEADERS [hdr1 ...] DESTINATION [destination] )
##
## Adds a custom "copy_headers" target for the given project
##
## Adds a custom target, blt_copy_headers_[NAME], for the given project.
## The role of this target is to copy the given list of headers, [HEADERS], to
## the destination directory [DESTINATION].
##
## This macro is used to copy the header of each component in to the build
## space, under an "includes" directory.
##------------------------------------------------------------------------------
macro(blt_copy_headers_target)
set(options)
set(singleValueArgs NAME DESTINATION)
set(multiValueArgs HEADERS)
# Parse the arguments
cmake_parse_arguments(arg "${options}" "${singleValueArgs}"
"${multiValueArgs}" ${ARGN} )
# Make all headers paths absolute
set(temp_list "")
foreach(header ${arg_HEADERS})
list(APPEND temp_list ${CMAKE_CURRENT_LIST_DIR}/${header})
endforeach()
set(arg_HEADERS ${temp_list})
add_custom_target(blt_copy_headers_${arg_NAME}
COMMAND ${CMAKE_COMMAND}
-DOUTPUT_DIRECTORY=${arg_DESTINATION}
-DLIBHEADERS="${arg_HEADERS}"
-P ${BLT_ROOT_DIR}/cmake/copy_headers.cmake
DEPENDS
${arg_HEADERS}
WORKING_DIRECTORY
${PROJECT_SOURCE_DIR}
COMMENT
"copy headers ${arg_NAME}"
)
endmacro(blt_copy_headers_target)
##------------------------------------------------------------------------------
## blt_setup_target( NAME [name] DEPENDS_ON [dep1 ...] )
##------------------------------------------------------------------------------
macro(blt_setup_target)
set(options)
set(singleValueArgs NAME)
set(multiValueArgs DEPENDS_ON)
# Parse the arguments
cmake_parse_arguments(arg "${options}" "${singleValueArgs}"
"${multiValueArgs}" ${ARGN} )
# Check arguments
if ( NOT DEFINED arg_NAME )
message( FATAL_ERROR "Must provide a NAME argument to the 'blt_setup_target' macro" )
endif()
# Add it's own copy headers target
if (ENABLE_COPY_HEADERS AND TARGET "blt_copy_headers_${arg_NAME}")
add_dependencies( ${arg_NAME} "blt_copy_headers_${arg_NAME}")
endif()
# Expand dependency list
set(_expanded_DEPENDS_ON ${arg_DEPENDS_ON})
foreach( i RANGE 50 )
foreach( dependency ${_expanded_DEPENDS_ON} )
string(TOUPPER ${dependency} uppercase_dependency )
if ( DEFINED BLT_${uppercase_dependency}_DEPENDS_ON )
foreach(new_dependency ${BLT_${uppercase_dependency}_DEPENDS_ON})
if (NOT ${new_dependency} IN_LIST _expanded_DEPENDS_ON)
list(APPEND _expanded_DEPENDS_ON ${new_dependency})
endif()
endforeach()
endif()
endforeach()
endforeach()
# Add dependency's information
foreach( dependency ${_expanded_DEPENDS_ON} )
string(TOUPPER ${dependency} uppercase_dependency )
if ( DEFINED BLT_${uppercase_dependency}_INCLUDES )
target_include_directories( ${arg_NAME} PUBLIC
${BLT_${uppercase_dependency}_INCLUDES} )
endif()
if ( DEFINED BLT_${uppercase_dependency}_FORTRAN_MODULES )
target_include_directories( ${arg_NAME} PUBLIC
${BLT_${uppercase_dependency}_FORTRAN_MODULES} )
endif()
if ( DEFINED BLT_${uppercase_dependency}_LIBRARIES)
if(NOT "${BLT_${uppercase_dependency}_LIBRARIES}"
STREQUAL "BLT_NO_LIBRARIES" )
target_link_libraries( ${arg_NAME} PUBLIC
${BLT_${uppercase_dependency}_LIBRARIES} )
endif()
else()
target_link_libraries( ${arg_NAME} PUBLIC ${dependency} )
endif()
if ( DEFINED BLT_${uppercase_dependency}_DEFINES )
target_compile_definitions( ${arg_NAME} PUBLIC
${BLT_${uppercase_dependency}_DEFINES} )
endif()
if ( DEFINED BLT_${uppercase_dependency}_COMPILE_FLAGS )
if(NOT "${BLT_${uppercase_dependency}_COMPILE_FLAGS}"
STREQUAL "BLT_NO_COMPILE_FLAGS" )
blt_add_target_compile_flags(TO ${arg_NAME}
FLAGS ${BLT_${uppercase_dependency}_COMPILE_FLAGS} )
endif()
endif()
if ( DEFINED BLT_${uppercase_dependency}_LINK_FLAGS )
if(NOT "${BLT_${uppercase_dependency}_LINK_FLAGS}"
STREQUAL "BLT_NO_LINK_FLAGS" )
blt_add_target_link_flags(TO ${arg_NAME}
FLAGS ${BLT_${uppercase_dependency}_LINK_FLAGS} )
endif()
endif()
if (ENABLE_COPY_HEADERS AND TARGET "blt_copy_headers_${dependency}")
add_dependencies( ${arg_NAME} "blt_copy_headers_${dependency}")
endif()
endforeach()
endmacro(blt_setup_target)
##------------------------------------------------------------------------------
## blt_setup_cuda_source_properties(BUILD_TARGET TARGET_SOURCES <sources>)
##------------------------------------------------------------------------------
macro(blt_setup_cuda_source_properties)
set(options)
set(singleValueArgs BUILD_TARGET)
set(multiValueArgs TARGET_SOURCES)
# Parse the arguments
cmake_parse_arguments(arg "${options}" "${singleValueArgs}"
"${multiValueArgs}" ${ARGN} )
# Check arguments
if ( NOT DEFINED arg_BUILD_TARGET )
message( FATAL_ERROR "Must provide a BUILD_TARGET argument to the 'blt_setup_cuda_source_properties' macro")
endif()
if ( NOT DEFINED arg_TARGET_SOURCES )
message( FATAL_ERROR "Must provide TARGET_SOURCES to the 'blt_setup_cuda_source_properties' macro")
endif()
foreach (_file ${arg_TARGET_SOURCES})
if (${_file} MATCHES "\\.(f|F)\\*")
set(_non_cuda_sources ${_non_cuda_sources} ${_file})
else()
set(_cuda_sources ${_cuda_sources} ${_file})
endif()
endforeach()
set_source_files_properties( ${_cuda_sources}
PROPERTIES
CUDA_SOURCE_PROPERTY_FORMAT OBJ)
set_source_files_properties( ${_non_cuda_sources}
PROPERTIES
CUDA_SOURCE_PROPERTY_FORMAT False)
#
# for debugging, or if we add verbose BLT output
#
##message(STATUS "target '${arg_BUILD_TARGET}' CUDA Sources: ${_cuda_sources}")
##message(STATUS "target '${arg_BUILD_TARGET}' non-CUDA Sources: ${_non_cuda_sources}")
endmacro(blt_setup_cuda_source_properties)
##------------------------------------------------------------------------------
## update_project_sources( TARGET_SOURCES <sources> )
##------------------------------------------------------------------------------
macro(blt_update_project_sources)
set(options)
set(singleValueArgs)
set(multiValueArgs TARGET_SOURCES)
# Parse the arguments
cmake_parse_arguments(arg "${options}" "${singleValueArgs}"
"${multiValueArgs}" ${ARGN} )
# Check arguments
if ( NOT DEFINED arg_TARGET_SOURCES )
message( FATAL_ERROR "Must provide target sources" )
endif()
## append the target source to the all project sources
foreach( src ${arg_TARGET_SOURCES} )
if(IS_ABSOLUTE ${src})
list(APPEND "${PROJECT_NAME}_ALL_SOURCES" "${src}")
else()
list(APPEND "${PROJECT_NAME}_ALL_SOURCES"
"${CMAKE_CURRENT_SOURCE_DIR}/${src}")
endif()
endforeach()
set( "${PROJECT_NAME}_ALL_SOURCES" "${${PROJECT_NAME}_ALL_SOURCES}"
CACHE STRING "" FORCE )
mark_as_advanced("${PROJECT_NAME}_ALL_SOURCES")
endmacro(blt_update_project_sources)