-
-
Notifications
You must be signed in to change notification settings - Fork 420
/
HPX_SetupTarget.cmake
231 lines (202 loc) · 6.86 KB
/
HPX_SetupTarget.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
# Copyright (c) 2014 Thomas Heller
# Copyright (c) 2007-2018 Hartmut Kaiser
# Copyright (c) 2011 Bryce Lelbach
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
cmake_policy(PUSH)
hpx_set_cmake_policy(CMP0054 NEW)
function(hpx_setup_target target)
# retrieve arguments
set(options EXPORT NOHPX_INIT INSTALL NOLIBS PLUGIN NONAMEPREFIX)
set(one_value_args TYPE FOLDER NAME SOVERSION VERSION HPX_PREFIX)
set(multi_value_args DEPENDENCIES COMPONENT_DEPENDENCIES COMPILE_FLAGS LINK_FLAGS INSTALL_FLAGS)
cmake_parse_arguments(target "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
hpx_is_target(is_target ${target})
if(NOT is_target)
hpx_error("${target} does not represent a target")
endif()
# Figure out which type we want...
if(target_TYPE)
string(TOUPPER "${target_TYPE}" _type)
else()
get_target_property(type_prop ${target} TYPE)
if(type_prop STREQUAL "STATIC_LIBRARY")
set(_type "LIBRARY")
endif()
if(type_prop STREQUAL "MODULE_LIBRARY")
set(_type "LIBRARY")
endif()
if(type_prop STREQUAL "SHARED_LIBRARY")
set(_type "LIBRARY")
endif()
if(type_prop STREQUAL "EXECUTABLE")
set(_type "EXECUTABLE")
endif()
endif()
if(target_FOLDER)
set_target_properties(${target} PROPERTIES FOLDER "${target_FOLDER}")
endif()
get_target_property(target_SOURCES ${target} SOURCES)
# Manage files with .cu extension in case When Cuda Clang is used
if(target_SOURCES AND HPX_WITH_CUDA_CLANG)
foreach(source ${target_SOURCES})
get_filename_component(extension ${source} EXT)
if(${extension} STREQUAL ".cu")
SET_SOURCE_FILES_PROPERTIES(${source} PROPERTIES
COMPILE_FLAGS "${HPX_CUDA_CLANG_FLAGS}")
endif()
endforeach()
endif()
if(target_COMPILE_FLAGS)
hpx_append_property(${target} COMPILE_FLAGS ${target_COMPILE_FLAGS})
endif()
if(target_LINK_FLAGS)
hpx_append_property(${target} LINK_FLAGS ${target_LINK_FLAGS})
endif()
if(target_NAME)
set(name "${target_NAME}")
else()
set(name "${target}")
endif()
set(nohpxinit FALSE)
if(target_NOHPX_INIT)
set(nohpxinit TRUE)
endif()
set(target_STATIC_LINKING OFF)
if(HPX_WITH_STATIC_LINKING)
set(target_STATIC_LINKING ON)
else()
set(_hpx_library_type)
if(TARGET hpx)
get_target_property(_hpx_library_type hpx TYPE)
endif()
if("${_hpx_library_type}" STREQUAL "STATIC_LIBRARY")
set(target_STATIC_LINKING ON)
endif()
endif()
if(HPX_INCLUDE_DIRS)
set_property(TARGET ${target} APPEND
PROPERTY INCLUDE_DIRECTORIES
"${HPX_INCLUDE_DIRS}"
)
endif()
if("${_type}" STREQUAL "EXECUTABLE")
if(target_HPX_PREFIX)
set(_prefix ${target_HPX_PREFIX})
else()
set(_prefix ${HPX_PREFIX})
endif()
if(MSVC)
string(REPLACE ";" ":" _prefix "${_prefix}")
endif()
set_property(TARGET ${target} APPEND
PROPERTY COMPILE_DEFINITIONS
"HPX_APPLICATION_NAME=${name}"
"HPX_APPLICATION_STRING=\"${name}\""
"HPX_PREFIX=\"${_prefix}\""
"HPX_APPLICATION_EXPORTS")
endif()
if("${_type}" STREQUAL "LIBRARY")
set(nohpxinit FALSE)
if(DEFINED HPX_LIBRARY_VERSION AND DEFINED HPX_SOVERSION)
# set properties of generated shared library
set_target_properties(${target}
PROPERTIES
VERSION ${HPX_LIBRARY_VERSION}
SOVERSION ${HPX_SOVERSION})
endif()
if(NOT target_NONAMEPREFIX)
hpx_set_lib_name(${target} ${name})
endif()
set_target_properties(${target}
PROPERTIES
# create *nix style library versions + symbolic links
# allow creating static and shared libs without conflicts
CLEAN_DIRECT_OUTPUT 1
OUTPUT_NAME ${name})
if(target_PLUGIN)
set(plugin_name "HPX_PLUGIN_NAME=hpx_${name}")
endif()
set(nohpxinit TRUE)
set_property(TARGET ${target} APPEND
PROPERTY COMPILE_DEFINITIONS
"HPX_LIBRARY_EXPORTS"
${plugin_name})
endif()
if("${_type}" STREQUAL "COMPONENT")
set(nohpxinit FALSE)
if(DEFINED HPX_LIBRARY_VERSION AND DEFINED HPX_SOVERSION)
# set properties of generated shared library
set_target_properties(${target}
PROPERTIES
VERSION ${HPX_LIBRARY_VERSION}
SOVERSION ${HPX_SOVERSION})
endif()
if(NOT target_NONAMEPREFIX)
hpx_set_lib_name(${target} ${name})
endif()
set_target_properties(${target}
PROPERTIES
# create *nix style library versions + symbolic links
# allow creating static and shared libs without conflicts
CLEAN_DIRECT_OUTPUT 1
OUTPUT_NAME ${name})
set(nohpxinit TRUE)
set_property(TARGET ${target} APPEND
PROPERTY COMPILE_DEFINITIONS
"HPX_COMPONENT_NAME=hpx_${name}"
"HPX_COMPONENT_STRING=\"hpx_${name}\""
"HPX_COMPONENT_EXPORTS")
endif()
# We force the -DDEBUG and -D_DEBUG defines in debug mode to avoid
# ABI differences
# if hpx is an imported target, get the config debug/release
set(HPX_IMPORT_CONFIG "NOTFOUND")
if (TARGET "hpx")
get_target_property(HPX_IMPORT_CONFIG "hpx" IMPORTED_CONFIGURATIONS)
endif()
if(HPX_IMPORT_CONFIG MATCHES NOTFOUND)
# we are building HPX not importing, so we should use the $<CONFIG:variable
set(_USE_CONFIG 1)
else()
# hpx is an imported target, so set HPX_DEBUG based on build config of hpx library
set(_USE_CONFIG 0)
endif()
if(NOT target_NOLIBS)
set(hpx_libs hpx)
if(NOT target_STATIC_LINKING)
set(hpx_libs ${hpx_libs})
if(NOT nohpxinit)
set(hpx_libs hpx_init ${hpx_libs})
endif()
endif()
hpx_handle_component_dependencies(target_COMPONENT_DEPENDENCIES)
set(hpx_libs ${hpx_libs} ${target_COMPONENT_DEPENDENCIES})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(hpx_libs ${hpx_libs} imf svml irng intlc)
endif()
if(DEFINED HPX_LIBRARIES)
set(hpx_libs ${hpx_libs} ${HPX_LIBRARIES})
endif()
get_target_property(target_type ${target} TYPE)
if(CMAKE_SYSTEM_NAME STREQUAL Linux AND target_type STREQUAL EXECUTABLE)
set_target_properties(${target} PROPERTIES LINK_FLAGS "-Wl,-wrap=__libc_start_main")
endif()
else()
target_compile_options(${target} PUBLIC ${CXX_FLAG})
endif()
target_link_libraries(${target} ${HPX_TLL_PUBLIC} ${hpx_libs} ${target_DEPENDENCIES})
get_target_property(target_EXCLUDE_FROM_ALL ${target} EXCLUDE_FROM_ALL)
if(target_EXPORT AND NOT target_EXCLUDE_FROM_ALL)
hpx_export_targets(${target})
set(install_export EXPORT HPXTargets)
endif()
if(target_INSTALL AND NOT target_EXCLUDE_FROM_ALL)
install(TARGETS ${target}
${target_INSTALL_FLAGS}
${install_export}
)
endif()
endfunction()
cmake_policy(POP)