1
1
#
2
- # A function to make target creation a little more declarative
2
+ # A function to make target specification a little more declarative
3
3
#
4
4
# See the comments on the options below for usage
5
5
#
@@ -21,6 +21,8 @@ function(slang_add_target dir type)
21
21
# Don't include any source in this target, this is a complement to
22
22
# EXPLICIT_SOURCE, and doesn't interact with EXTRA_SOURCE_DIRS
23
23
NO_SOURCE
24
+ # Don't generate split debug info for this target
25
+ NO_SPLIT_DEBUG_INFO
24
26
)
25
27
set (single_value_args
26
28
# Set the target name, useful for multiple targets from the same
@@ -49,7 +51,7 @@ function(slang_add_target dir type)
49
51
DEBUG_DIR
50
52
# Install this target as part of a component
51
53
INSTALL_COMPONENT
52
- # Don't install debug info by default for this target and use this
54
+ # Override the debug info component name for installation
53
55
# explicit name instead, used for externally built things such as
54
56
# slang-glslang and slang-llvm which have large pdb files
55
57
DEBUG_INFO_INSTALL_COMPONENT
@@ -198,6 +200,15 @@ function(slang_add_target dir type)
198
200
PDB_OUTPUT_DIRECTORY "${output_dir} /${runtime_subdir} "
199
201
)
200
202
203
+ if (NOT MSVC )
204
+ set_target_properties (
205
+ ${target}
206
+ PROPERTIES
207
+ COMPILE_OPTIONS
208
+ "$<$<CONFIG:Debug,RelWithDebInfo>:-fdebug-prefix-map=${CMAKE_CURRENT_BINARY_DIR} =${output_dir} >"
209
+ )
210
+ endif ()
211
+
201
212
#
202
213
# Set common compile options and properties
203
214
#
@@ -209,6 +220,118 @@ function(slang_add_target dir type)
209
220
set_default_compile_options(${target} )
210
221
endif ()
211
222
223
+ # Set debug info options if not disabled
224
+ # Determine if this target produces a binary that can have debug info
225
+ if (
226
+ NOT ARG_NO_SPLIT_DEBUG_INFO
227
+ AND type MATCHES "^(EXECUTABLE|SHARED|MODULE)$"
228
+ AND SLANG_ENABLE_SPLIT_DEBUG_INFO
229
+ )
230
+ set (generate_split_debug_info TRUE )
231
+ else ()
232
+ set (generate_split_debug_info FALSE )
233
+ endif ()
234
+
235
+ if (generate_split_debug_info)
236
+ if (MSVC )
237
+ get_target_property (
238
+ c_compiler_launcher
239
+ ${target}
240
+ C_COMPILER_LAUNCHER
241
+ )
242
+ get_target_property (
243
+ cxx_compiler_launcher
244
+ ${target}
245
+ CXX_COMPILER_LAUNCHER
246
+ )
247
+
248
+ if (
249
+ c_compiler_launcher MATCHES "ccache"
250
+ OR cxx_compiler_launcher MATCHES "ccache"
251
+ )
252
+ message (
253
+ WARNING
254
+ "(s)ccache detected for target ${target} . Removing launcher as it's incompatible with split debug info compiled with MSVC."
255
+ )
256
+ set_target_properties (
257
+ ${target}
258
+ PROPERTIES C_COMPILER_LAUNCHER "" CXX_COMPILER_LAUNCHER ""
259
+ )
260
+ endif ()
261
+
262
+ get_target_property (
263
+ msvc_debug_information_format
264
+ ${target}
265
+ MSVC_DEBUG_INFORMATION_FORMAT
266
+ )
267
+ if (
268
+ NOT msvc_debug_information_format
269
+ MATCHES
270
+ "(ProgramDatabase|EditAndContinue)"
271
+ )
272
+ message (
273
+ WARNING
274
+ "Debug format must be ProgramDatabase or EditAndContinue to generate split debug info with MSVC"
275
+ )
276
+ endif ()
277
+
278
+ set_target_properties (
279
+ ${target}
280
+ PROPERTIES
281
+ # While it would be nice to set this here, we don't know if
282
+ # the user wants ProgramDatabase or EditAndContinue, so
283
+ # just check above
284
+ # MSVC_DEBUG_INFORMATION_FORMAT
285
+ # "$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>"
286
+ COMPILE_PDB_NAME "${target} "
287
+ COMPILE_PDB_OUTPUT_DIRECTORY "${output_dir} "
288
+ )
289
+ else ()
290
+ # Common debug flags for GCC/Clang
291
+ target_compile_options (
292
+ ${target}
293
+ PRIVATE
294
+ $<$<CONFIG:Debug,RelWithDebInfo>:
295
+ -g
296
+ -fdebug-prefix -map=${CMAKE_SOURCE_DIR} =.
297
+ -fdebug-prefix -map=${CMAKE_BINARY_DIR} =.
298
+ >
299
+ )
300
+
301
+ if (CMAKE_SYSTEM_NAME MATCHES "Darwin" )
302
+ # macOS - use dsymutil with --flat to create separate debug file
303
+ add_custom_command (
304
+ TARGET ${target}
305
+ POST_BUILD
306
+ COMMAND
307
+ dsymutil --flat $<TARGET_FILE:${target} > -o
308
+ $<TARGET_FILE:${target} >.dwarf
309
+ COMMAND chmod 644 $<TARGET_FILE:${target} >.dwarf
310
+ COMMAND ${CMAKE_STRIP} -S $<TARGET_FILE:${target} >
311
+ WORKING_DIRECTORY ${output_dir}
312
+ VERBATIM
313
+ )
314
+ else ()
315
+ add_custom_command (
316
+ TARGET ${target}
317
+ POST_BUILD
318
+ COMMAND
319
+ ${CMAKE_OBJCOPY} --only-keep-debug
320
+ $<TARGET_FILE:${target} > $<TARGET_FILE:${target} >.dwarf
321
+ COMMAND chmod 644 $<TARGET_FILE:${target} >.dwarf
322
+ COMMAND
323
+ ${CMAKE_STRIP} --strip-debug $<TARGET_FILE:${target} >
324
+ COMMAND
325
+ ${CMAKE_OBJCOPY}
326
+ --add-gnu-debuglink=$<TARGET_FILE:${target} >.dwarf
327
+ $<TARGET_FILE:${target} >
328
+ WORKING_DIRECTORY ${output_dir}
329
+ VERBATIM
330
+ )
331
+ endif ()
332
+ endif ()
333
+ endif ()
334
+
212
335
set_target_properties (
213
336
${target}
214
337
PROPERTIES EXCLUDE_FROM_ALL ${ARG_EXCLUDE_FROM_ALL}
@@ -429,32 +552,41 @@ function(slang_add_target dir type)
429
552
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${ARGN}
430
553
)
431
554
endmacro ()
555
+
432
556
if (ARG_INSTALL_COMPONENT)
433
557
i(EXCLUDE_FROM_ALL COMPONENT ${ARG_INSTALL_COMPONENT} )
434
- set (pdb_component "${ARG_INSTALL_COMPONENT} -debug-info" )
558
+ set (debug_component "${ARG_INSTALL_COMPONENT} -debug-info" )
435
559
elseif (ARG_INSTALL)
436
560
i()
437
- set (pdb_component "debug-info" )
561
+ set (debug_component "debug-info" )
438
562
endif ()
439
- if (ARG_DEBUG_INFO_INSTALL_COMPONENT)
440
- set (pdb_component ${ARG_DEBUG_INFO_INSTALL_COMPONENT} )
563
+
564
+ if (DEFINED ARG_DEBUG_INFO_INSTALL_COMPONENT)
565
+ set (debug_component "${ARG_DEBUG_INFO_INSTALL_COMPONENT} " )
441
566
endif ()
442
- if (MSVC AND DEFINED pdb_component)
443
- if (
444
- type STREQUAL "EXECUTABLE"
445
- OR type STREQUAL "SHARED"
446
- OR type STREQUAL "MODULE"
447
- )
448
- install (
449
- FILES $<TARGET_PDB_FILE:${target} >
450
- DESTINATION ${runtime_subdir}
451
- # Optional, because if we're building without debug info (like
452
- # a release build) then we don't want to fail here.
453
- OPTIONAL
454
- COMPONENT ${pdb_component}
455
- EXCLUDE_FROM_ALL
456
- )
567
+
568
+ # Install debug info only if target is being installed
569
+ if ((ARG_INSTALL OR ARG_INSTALL_COMPONENT) AND generate_split_debug_info)
570
+ if (type STREQUAL "EXECUTABLE" OR WIN32 )
571
+ set (debug_dest ${runtime_subdir} )
572
+ else ()
573
+ set (debug_dest ${library_subdir} )
457
574
endif ()
575
+
576
+ if (MSVC )
577
+ set (debug_file $<TARGET_PDB_FILE:${target} >)
578
+ else ()
579
+ set (debug_file "$<TARGET_FILE:${target} >.dwarf" )
580
+ endif ()
581
+
582
+ install (
583
+ FILES ${debug_file}
584
+ DESTINATION ${debug_dest}
585
+ CONFIGURATIONS Debug RelWithDebInfo
586
+ COMPONENT ${debug_component}
587
+ EXCLUDE_FROM_ALL
588
+ OPTIONAL
589
+ )
458
590
endif ()
459
591
endfunction ()
460
592
0 commit comments