@@ -59,19 +59,23 @@ function(_get_common_compile_options output_var flags)
59
59
set (${output_var} ${compile_options} PARENT_SCOPE )
60
60
endfunction ()
61
61
62
- # Builds the entrypoint target for the GPU.
62
+ # Builds the object target for the GPU.
63
+ # This compiles the target for all supported architectures and embeds it into
64
+ # host binary for installing. The internal target contains the GPU code directly
65
+ # compiled for a single architecture used internally.
63
66
# Usage:
64
- # _build_gpu_entrypoint_objects (
67
+ # _build_gpu_objects (
65
68
# <target_name>
69
+ # <internal_target_name>
66
70
# SRCS <list of .cpp files>
67
71
# HDRS <list of .h files>
68
72
# DEPENDS <list of dependencies>
69
73
# COMPILE_OPTIONS <optional list of special compile options for this target>
70
74
# FLAGS <optional list of flags>
71
75
# )
72
- function (_build_gpu_entrypoint_objects fq_target_name )
76
+ function (_build_gpu_objects fq_target_name internal_target_name )
73
77
cmake_parse_arguments (
74
- "ADD_GPU_ENTRYPOINT_OBJ "
78
+ "ADD_GPU_OBJ "
75
79
"" # No optional arguments
76
80
"NAME;CXX_STANDARD" # Single value arguments
77
81
"SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;FLAGS" # Multi value arguments
@@ -82,7 +86,7 @@ function(_build_gpu_entrypoint_objects fq_target_name)
82
86
# this so we can support multiple accelerators on the same machine.
83
87
foreach (gpu_arch ${all_gpu_architectures} )
84
88
set (gpu_target_name ${fq_target_name} .${gpu_arch} )
85
- set (compile_options ${ADD_GPU_ENTRYPOINT_OBJ_COMPILE_OPTIONS } )
89
+ set (compile_options ${ADD_GPU_OBJ_COMPILE_OPTIONS } )
86
90
# Derive the triple from the specified architecture.
87
91
if ("${gpu_arch} " IN_LIST all_amdgpu_architectures )
88
92
set (gpu_target_triple "amdgcn-amd-amdhsa" )
@@ -101,14 +105,16 @@ function(_build_gpu_entrypoint_objects fq_target_name)
101
105
add_library (${gpu_target_name}
102
106
EXCLUDE_FROM_ALL
103
107
OBJECT
104
- ${ADD_GPU_ENTRYPOINT_OBJ_SRCS }
105
- ${ADD_GPU_ENTRYPOINT_OBJ_HDRS }
108
+ ${ADD_GPU_OBJ_SRCS }
109
+ ${ADD_GPU_OBJ_HDRS }
106
110
)
107
111
108
112
target_compile_options (${gpu_target_name} PRIVATE ${compile_options} )
109
113
target_include_directories (${gpu_target_name} PRIVATE ${include_dirs} )
110
- add_dependencies (${gpu_target_name} ${ADD_GPU_ENTRYPOINT_OBJ_DEPENDS} )
111
114
target_compile_definitions (${gpu_target_name} PRIVATE LIBC_COPT_PUBLIC_PACKAGING )
115
+ if (ADD_GPU_OBJ_DEPENDS )
116
+ add_dependencies (${gpu_target_name} ${ADD_GPU_OBJ_DEPENDS} )
117
+ endif ()
112
118
113
119
# Append this target to a list of images to package into a single binary.
114
120
set (input_file $< TARGET_OBJECTS:${gpu_target_name} > )
@@ -135,7 +141,7 @@ function(_build_gpu_entrypoint_objects fq_target_name)
135
141
# TODO: In the future we will want to combine every architecture for a target
136
142
# into a single bitcode file and use that. For now we simply build for
137
143
# every single one and let the offloading linker handle it.
138
- get_filename_component (stub_filename ${ADD_GPU_ENTRYPOINT_OBJ_SRCS } NAME )
144
+ get_filename_component (stub_filename ${ADD_GPU_OBJ_SRCS } NAME )
139
145
file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /stubs )
140
146
file (WRITE ${CMAKE_CURRENT_BINARY_DIR} /stubs/${stub_filename} "// Empty file.\n " )
141
147
add_library (
@@ -151,28 +157,16 @@ function(_build_gpu_entrypoint_objects fq_target_name)
151
157
target_include_directories (${fq_target_name} PRIVATE ${include_dirs} )
152
158
add_dependencies (${fq_target_name} ${full_deps_list} ${packaged_target_name} )
153
159
154
- set_target_properties (
155
- ${fq_target_name}
156
- PROPERTIES
157
- ENTRYPOINT_NAME ${ADD_ENTRYPOINT_OBJ_NAME}
158
- TARGET_TYPE ${ENTRYPOINT_OBJ_TARGET_TYPE}
159
- OBJECT_FILE "$<TARGET_OBJECTS:${fq_target_name} >"
160
- CXX_STANDARD ${ADD_ENTRYPOINT_OBJ_CXX_STANDARD}
161
- DEPS "${fq_deps_list} "
162
- FLAGS "${ADD_ENTRYPOINT_OBJ_FLAGS} "
163
- )
164
-
165
160
# We only build the internal target for a single supported architecture.
166
- set (internal_target_name ${fq_target_name} .__internal__ )
167
161
set (include_dirs ${LIBC_BUILD_DIR} /include ${LIBC_SOURCE_DIR} ${LIBC_BUILD_DIR} )
168
162
if (LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU OR
169
163
LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX )
170
164
add_library (
171
165
${internal_target_name}
172
166
EXCLUDE_FROM_ALL
173
167
OBJECT
174
- ${ADD_ENTRYPOINT_OBJ_SRCS }
175
- ${ADD_ENTRYPOINT_OBJ_HDRS }
168
+ ${ADD_GPU_OBJ_SRCS }
169
+ ${ADD_GPU_OBJ_HDRS }
176
170
)
177
171
target_compile_options (${internal_target_name} BEFORE PRIVATE
178
172
${common_compile_options} --target=${LIBC_GPU_TARGET_TRIPLE} )
@@ -182,17 +176,9 @@ function(_build_gpu_entrypoint_objects fq_target_name)
182
176
target_compile_options (${internal_target_name} PRIVATE -march=${LIBC_GPU_TARGET_ARCHITECTURE} )
183
177
endif ()
184
178
target_include_directories (${internal_target_name} PRIVATE ${include_dirs} )
185
- add_dependencies (${internal_target_name} ${full_deps_list} )
186
- set_target_properties (
187
- ${internal_target_name}
188
- PROPERTIES
189
- CXX_STANDARD ${ADD_ENTRYPOINT_OBJ_CXX_STANDARD}
190
- FLAGS "${ADD_ENTRYPOINT_OBJ_FLAGS} "
191
- )
192
- set_target_properties (
193
- ${fq_target_name}
194
- PROPERTIES OBJECT_FILE_RAW "$<TARGET_OBJECTS:${internal_target_name} >"
195
- )
179
+ if (full_deps_list )
180
+ add_dependencies (${internal_target_name} ${full_deps_list} )
181
+ endif ()
196
182
endif ()
197
183
endfunction ()
198
184
@@ -209,7 +195,7 @@ endfunction()
209
195
function (create_object_library fq_target_name )
210
196
cmake_parse_arguments (
211
197
"ADD_OBJECT"
212
- "" # No optional arguments
198
+ "NO_GPU_BUNDLE " # No optional arguments
213
199
"CXX_STANDARD" # Single value arguments
214
200
"SRCS;HDRS;COMPILE_OPTIONS;DEPENDS;FLAGS" # Multivalue arguments
215
201
${ARGN}
@@ -219,28 +205,49 @@ function(create_object_library fq_target_name)
219
205
message (FATAL_ERROR "'add_object_library' rule requires SRCS to be specified." )
220
206
endif ()
221
207
222
- add_library (
223
- ${fq_target_name}
224
- EXCLUDE_FROM_ALL
225
- OBJECT
226
- ${ADD_OBJECT_SRCS}
227
- ${ADD_OBJECT_HDRS}
228
- )
229
- target_include_directories (
230
- ${fq_target_name}
231
- PRIVATE
232
- ${LIBC_BUILD_DIR} /include
233
- ${LIBC_SOURCE_DIR}
234
- ${LIBC_BUILD_DIR}
235
- )
208
+ # The GPU build uses a separate internal file.
209
+ if (LIBC_TARGET_ARCHITECTURE_IS_GPU AND NOT ${ADD_OBJECT_NO_GPU_BUNDLE} )
210
+ set (internal_target_name ${fq_target_name} .__internal__ )
211
+ else ()
212
+ set (internal_target_name ${fq_target_name} )
213
+ endif ()
214
+
215
+ get_fq_deps_list (fq_deps_list ${ADD_OBJECT_DEPENDS} )
236
216
_get_common_compile_options (
237
217
compile_options
238
218
"${ADD_OBJECT_FLAGS} "
239
219
${ADD_OBJECT_COMPILE_OPTIONS}
240
220
)
241
- target_compile_options (${fq_target_name} PRIVATE ${compile_options} )
242
221
243
- get_fq_deps_list (fq_deps_list ${ADD_OBJECT_DEPENDS} )
222
+ # GPU builds require special handling for the objects because we want to
223
+ # export several different targets at once, e.g. for both Nvidia and AMD.
224
+ if (LIBC_TARGET_ARCHITECTURE_IS_GPU AND NOT ${ADD_OBJECT_NO_GPU_BUNDLE} )
225
+ _build_gpu_objects (
226
+ ${fq_target_name}
227
+ ${internal_target_name}
228
+ SRCS ${ADD_OBJECT_SRCS}
229
+ HDRS ${ADD_OBJECT_HDRS}
230
+ DEPENDS ${fq_deps_list}
231
+ COMPILE_OPTIONS ${common_compile_options}
232
+ FLAGS "${ADD_ENTRYPOINT_OBJ_FLAGS} "
233
+ )
234
+ else ()
235
+ add_library (
236
+ ${fq_target_name}
237
+ EXCLUDE_FROM_ALL
238
+ OBJECT
239
+ ${ADD_OBJECT_SRCS}
240
+ ${ADD_OBJECT_HDRS}
241
+ )
242
+ target_include_directories (
243
+ ${fq_target_name}
244
+ PRIVATE
245
+ ${LIBC_BUILD_DIR} /include
246
+ ${LIBC_SOURCE_DIR}
247
+ ${LIBC_BUILD_DIR}
248
+ )
249
+ target_compile_options (${fq_target_name} PRIVATE ${compile_options} )
250
+ endif ()
244
251
245
252
if (SHOW_INTERMEDIATE_OBJECTS )
246
253
message (STATUS "Adding object library ${fq_target_name} " )
@@ -262,11 +269,18 @@ function(create_object_library fq_target_name)
262
269
${fq_target_name}
263
270
PROPERTIES
264
271
TARGET_TYPE ${OBJECT_LIBRARY_TARGET_TYPE}
265
- OBJECT_FILES "$<TARGET_OBJECTS:${fq_target_name} >"
266
272
CXX_STANDARD ${ADD_OBJECT_CXX_STANDARD}
267
273
DEPS "${fq_deps_list} "
268
274
FLAGS "${ADD_OBJECT_FLAGS} "
269
275
)
276
+
277
+ if (TARGET ${internal_target_name} )
278
+ set_target_properties (
279
+ ${fq_target_name}
280
+ PROPERTIES
281
+ OBJECT_FILES "$<TARGET_OBJECTS:${internal_target_name} >"
282
+ )
283
+ endif ()
270
284
endfunction (create_object_library )
271
285
272
286
# Internal function, used by `add_object_library`.
@@ -483,13 +497,13 @@ function(create_entrypoint_object fq_target_name)
483
497
# GPU builds require special handling for the objects because we want to
484
498
# export several different targets at once, e.g. for both Nvidia and AMD.
485
499
if (LIBC_TARGET_ARCHITECTURE_IS_GPU )
486
- _build_gpu_entrypoint_objects (
500
+ _build_gpu_objects (
487
501
${fq_target_name}
502
+ ${internal_target_name}
488
503
SRCS ${ADD_ENTRYPOINT_OBJ_SRCS}
489
504
HDRS ${ADD_ENTRYPOINT_OBJ_HDRS}
490
505
COMPILE_OPTIONS ${common_compile_options}
491
506
DEPENDS ${full_deps_list}
492
- CXX_STANDARD ${ADD_ENTRYPOINT_OBJ_CXX_STANDARD}
493
507
FLAGS "${ADD_ENTRYPOINT_OBJ_FLAGS} "
494
508
)
495
509
else ()
@@ -505,12 +519,6 @@ function(create_entrypoint_object fq_target_name)
505
519
target_compile_options (${internal_target_name} BEFORE PRIVATE ${common_compile_options} )
506
520
target_include_directories (${internal_target_name} PRIVATE ${include_dirs} )
507
521
add_dependencies (${internal_target_name} ${full_deps_list} )
508
- set_target_properties (
509
- ${internal_target_name}
510
- PROPERTIES
511
- CXX_STANDARD ${ADD_ENTRYPOINT_OBJ_CXX_STANDARD}
512
- FLAGS "${ADD_ENTRYPOINT_OBJ_FLAGS} "
513
- )
514
522
515
523
add_library (
516
524
${fq_target_name}
@@ -524,22 +532,36 @@ function(create_entrypoint_object fq_target_name)
524
532
target_compile_options (${fq_target_name} BEFORE PRIVATE ${common_compile_options} -DLIBC_COPT_PUBLIC_PACKAGING )
525
533
target_include_directories (${fq_target_name} PRIVATE ${include_dirs} )
526
534
add_dependencies (${fq_target_name} ${full_deps_list} )
535
+ endif ()
536
+
537
+ set_target_properties (
538
+ ${fq_target_name}
539
+ PROPERTIES
540
+ ENTRYPOINT_NAME ${ADD_ENTRYPOINT_OBJ_NAME}
541
+ TARGET_TYPE ${ENTRYPOINT_OBJ_TARGET_TYPE}
542
+ OBJECT_FILE "$<TARGET_OBJECTS:${fq_target_name} >"
543
+ CXX_STANDARD ${ADD_ENTRYPOINT_OBJ_CXX_STANDARD}
544
+ DEPS "${fq_deps_list} "
545
+ FLAGS "${ADD_ENTRYPOINT_OBJ_FLAGS} "
546
+ )
527
547
548
+ if (TARGET ${internal_target_name} )
549
+ set_target_properties (
550
+ ${internal_target_name}
551
+ PROPERTIES
552
+ CXX_STANDARD ${ADD_ENTRYPOINT_OBJ_CXX_STANDARD}
553
+ FLAGS "${ADD_ENTRYPOINT_OBJ_FLAGS} "
554
+ )
528
555
set_target_properties (
529
556
${fq_target_name}
530
557
PROPERTIES
531
- ENTRYPOINT_NAME ${ADD_ENTRYPOINT_OBJ_NAME}
532
- TARGET_TYPE ${ENTRYPOINT_OBJ_TARGET_TYPE}
533
- OBJECT_FILE "$<TARGET_OBJECTS:${fq_target_name} >"
534
558
# TODO: We don't need to list internal object files if the internal
535
559
# target is a normal static library.
536
560
OBJECT_FILE_RAW "$<TARGET_OBJECTS:${internal_target_name} >"
537
- CXX_STANDARD ${ADD_ENTRYPOINT_OBJ_CXX_STANDARD}
538
- DEPS "${fq_deps_list} "
539
- FLAGS "${ADD_ENTRYPOINT_OBJ_FLAGS} "
540
561
)
541
562
endif ()
542
563
564
+
543
565
if (LLVM_LIBC_ENABLE_LINTING AND TARGET ${internal_target_name} )
544
566
if (NOT LLVM_LIBC_CLANG_TIDY )
545
567
message (FATAL_ERROR "Something is wrong! LLVM_LIBC_ENABLE_LINTING is "
0 commit comments