File: CreateDebugSym.cmake

package info (click to toggle)
gmt 6.5.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 117,824 kB
  • sloc: ansic: 291,750; sh: 10,024; fortran: 49; makefile: 43; perl: 32; csh: 9
file content (102 lines) | stat: -rw-r--r-- 3,548 bytes parent folder | download
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
#
#
# - Generates Mac .dSYM bundle
# CREATE_DEBUG_SYM ( DESTINATION TARGETS )
#
#  DESTINATION - destination directory for installed targets
#  TARGETS     - list of targets
#
# Copyright (c) 1991-2024 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
# See LICENSE.TXT file for copying and redistribution conditions.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; version 3 or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# Contact info: www.generic-mapping-tools.org
#-------------------------------------------------------------------------------

string(TOLOWER ${CMAKE_BUILD_TYPE} _build_type)
if (_build_type MATCHES "debug|relwithdebinfo")
	set (DEBUG_BUILD TRUE)
endif ()
set (_build_type)

if (APPLE AND DEBUG_BUILD)

	# useful macros
	include (GmtHelperMacros)

	# Check for dsymutil only on Mac
	find_program(DSYMUTIL dsymutil)

	# Macro for generating Mac debugging symbols
	macro (CREATE_DEBUG_SYM DESTINATION)
		if (DSYMUTIL AND ("${CMAKE_GENERATOR}" MATCHES "Make" OR "${CMAKE_GENERATOR}" MATCHES "Ninja"))
			# create tag from current dirname
			tag_from_current_source_dir (_tag "_")

			# generator
			foreach (target ${ARGN}) # get all args past the last expected
				add_custom_command (TARGET ${target}
					POST_BUILD
					COMMAND ${DSYMUTIL} $<TARGET_FILE:${target}>
					COMMENT "Generating .dSYM bundle for ${target}"
					VERBATIM)

				# clean target
				get_target_property (_type ${target} TYPE)
				get_target_property (_version ${target} VERSION)
				get_target_property (_name ${target} OUTPUT_NAME)
				if (_type STREQUAL "SHARED_LIBRARY")
					string (REPLACE ".dylib" ".${_version}.dylib" _name "${_name}")
				endif (_type STREQUAL "SHARED_LIBRARY")
				add_custom_target (_dsym_clean_${target}
					COMMAND ${RM} -rf $<TARGET_FILE:${target}>.dSYM
					COMMENT "Removing .dSYM bundle")
				add_depend_to_target (dsym_clean${_tag} _dsym_clean_${target})

				# install target
				install (DIRECTORY $<TARGET_FILE:${target}>
					DESTINATION ${DESTINATION}
					COMPONENT Debug)
			endforeach (target)

			# register with spotless target
			add_depend_to_target (spotless dsym_clean${_tag})
		endif (DSYMUTIL AND ("${CMAKE_GENERATOR}" MATCHES "Make" OR "${CMAKE_GENERATOR}" MATCHES "Ninja"))
	endmacro (CREATE_DEBUG_SYM _TARGETS)

elseif (MSVC AND DEBUG_BUILD)
	# Macro for installing MSVC debugging symbol files
	macro (CREATE_DEBUG_SYM DESTINATION)
		# create tag from current dirname
		tag_from_current_source_dir (_tag "_")

		foreach (target ${ARGN}) # get all args past the last expected
			# clean target
			add_custom_target (_pdb_clean_${target}
				COMMAND ${CMAKE_COMMAND} remove -f $<TARGET_PDB_FILE:${target}>
				COMMENT "Removing .pdb file")
			add_depend_to_target (pdb_clean${_tag} _pdb_clean_${target})

			# install target
			install (FILES $<TARGET_PDB_FILE:${target}>
				DESTINATION ${DESTINATION}
				COMPONENT Debug)
		endforeach (target)

		# register with spotless target
		add_depend_to_target (spotless pdb_clean${_tag})
	endmacro (CREATE_DEBUG_SYM _TARGETS)

else (APPLE AND DEBUG_BUILD)
	macro (CREATE_DEBUG_SYM _TARGETS)
		# do nothing
	endmacro (CREATE_DEBUG_SYM _TARGETS)
endif (APPLE AND DEBUG_BUILD)