Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit baeec4d

Browse files
author
Mike McLaughlin
committed
Issue #3669
Created a common cmake strip_symbols function that all the modules and programs use to strip the symbols out of the main into a separate .dbg (Linux) or .dSYM (OSX) file. Added an install_clr cmake function to encapsulate the install logic. Changed all the library module cmake install lines from a TARGETS to a FILES one. The TARGETS based install directives caused cmake to relink the binary and copy the unstripped version to the install path. Left the all programs like corerun or ildasm as TARGETS installs because on OSX FILES type installs don't get marked as executable. Need to use "get_property(strip_source_file TARGET ${targetName} PROPERTY LOCATION)" for the older versions of cmake and "set(strip_source_file $<TARGET_FILE:${targetName}>)" on newer versions (v3 or greater).
1 parent 7022fc9 commit baeec4d

File tree

19 files changed

+114
-64
lines changed

19 files changed

+114
-64
lines changed

CMakeLists.txt

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,27 @@ else()
154154
if (AWK STREQUAL "AWK-NOTFOUND")
155155
message(FATAL_ERROR "AWK not found")
156156
endif()
157+
158+
if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
159+
160+
# Ensure that dsymutil and strip is present
161+
find_program(DSYMUTIL dsymutil)
162+
if (DSYMUTIL STREQUAL "DSYMUTIL-NOTFOUND")
163+
message(FATAL_ERROR "dsymutil not found")
164+
endif()
165+
find_program(STRIP strip)
166+
if (STRIP STREQUAL "STRIP-NOTFOUND")
167+
message(FATAL_ERROR "strip not found")
168+
endif()
169+
170+
else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
171+
172+
# Ensure that objcopy is present
173+
find_program(OBJCOPY objcopy)
174+
if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND")
175+
message(FATAL_ERROR "objcopy not found")
176+
endif()
177+
endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
157178
endif(WIN32)
158179

159180
# Build a list of compiler definitions by putting -D in front of each define.
@@ -242,6 +263,69 @@ function(add_precompiled_header header cppFile targetSources)
242263
endif(MSVC)
243264
endfunction()
244265

266+
function(strip_symbols targetName outputFilename)
267+
if(CLR_CMAKE_PLATFORM_UNIX)
268+
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
269+
270+
# On the older version of cmake (2.8.12) used on Ubuntu 14.04 the TARGET_FILE
271+
# generator expression doesn't work correctly returning the wrong path and on
272+
# the newer cmake versions the LOCATION property isn't supported anymore.
273+
if(CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
274+
set(strip_source_file $<TARGET_FILE:${targetName}>)
275+
else()
276+
get_property(strip_source_file TARGET ${targetName} PROPERTY LOCATION)
277+
endif()
278+
279+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
280+
set(strip_destination_file ${strip_source_file}.dwarf)
281+
282+
add_custom_command(
283+
TARGET ${targetName}
284+
POST_BUILD
285+
VERBATIM
286+
COMMAND ${DSYMUTIL} --flat --minimize ${strip_source_file}
287+
COMMAND ${STRIP} -u -r ${strip_source_file}
288+
COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
289+
)
290+
else(CMAKE_SYSTEM_NAME STREQUAL Darwin)
291+
set(strip_destination_file ${strip_source_file}.dbg)
292+
293+
add_custom_command(
294+
TARGET ${targetName}
295+
POST_BUILD
296+
VERBATIM
297+
COMMAND ${OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file}
298+
COMMAND ${OBJCOPY} --strip-unneeded ${strip_source_file}
299+
COMMAND ${OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file}
300+
COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
301+
)
302+
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
303+
304+
set(${outputFilename} ${strip_destination_file} PARENT_SCOPE)
305+
endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
306+
endif(CLR_CMAKE_PLATFORM_UNIX)
307+
endfunction()
308+
309+
function(install_clr targetName)
310+
strip_symbols(${targetName} strip_destination_file)
311+
312+
# On the older version of cmake (2.8.12) used on Ubuntu 14.04 the TARGET_FILE
313+
# generator expression doesn't work correctly returning the wrong path and on
314+
# the newer cmake versions the LOCATION property isn't supported anymore.
315+
if(CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
316+
set(install_source_file $<TARGET_FILE:${targetName}>)
317+
else()
318+
get_property(install_source_file TARGET ${targetName} PROPERTY LOCATION)
319+
endif()
320+
321+
install(PROGRAMS ${install_source_file} DESTINATION .)
322+
if(WIN32)
323+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pdb DESTINATION PDB)
324+
else()
325+
install(FILES ${strip_destination_file} DESTINATION .)
326+
endif()
327+
endfunction()
328+
245329
# Includes
246330

247331
if (CMAKE_CONFIGURATION_TYPES) # multi-configuration generator?

src/ToolBox/SOS/Strike/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ add_dependencies(sos mscordaccore)
146146
target_link_libraries(sos ${SOS_LIBRARY})
147147

148148
# add the install targets
149-
install (TARGETS sos DESTINATION .)
150-
if(WIN32)
151-
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/sos.pdb DESTINATION PDB)
152-
else(WIN32)
153-
install (FILES sosdocsunix.txt DESTINATION .)
154-
endif(WIN32)
149+
install_clr(sos)
150+
151+
if(NOT WIN32)
152+
install(FILES sosdocsunix.txt DESTINATION .)
153+
endif(NOT WIN32)

src/ToolBox/SOS/lldbplugin/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ if (CLR_CMAKE_PLATFORM_UNIX)
9393
endif()
9494

9595
# add the install targets
96-
install (TARGETS sosplugin DESTINATION .)
96+
install_clr(sosplugin)

src/coreclr/hosts/coreconsole/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ else()
2727
)
2828

2929
# Can't compile on linux yet so only add for windows
30-
# add the install targets
31-
install (TARGETS CoreConsole DESTINATION .)
32-
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/$ENV{__BuildType}/CoreConsole.pdb DESTINATION PDB)
30+
install_clr(CoreConsole)
3331

3432
endif(CLR_CMAKE_PLATFORM_UNIX)

src/coreclr/hosts/corerun/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ else()
3232
)
3333

3434
# Can't compile on linux yet so only add for windows
35-
# add the install targets
36-
install (TARGETS CoreRun DESTINATION .)
35+
install_clr(CoreRun)
3736

38-
# We will generate PDB only for the debug configuration
39-
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/CoreRun.pdb DESTINATION PDB)
40-
4137
endif(CLR_CMAKE_PLATFORM_UNIX)

src/coreclr/hosts/osxbundlerun/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ add_dependencies(osxbundlerun
2121
coreclr
2222
)
2323

24-
install (TARGETS osxbundlerun DESTINATION .)
24+
install_clr(osxbundlerun)

src/coreclr/hosts/unixcoreconsole/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ add_dependencies(coreconsole
3030
coreclr
3131
)
3232

33-
install (TARGETS coreconsole DESTINATION .)
33+
install_clr(coreconsole)

src/coreclr/hosts/unixcorerun/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ add_dependencies(corerun
3030
coreclr
3131
)
3232

33-
install (TARGETS corerun DESTINATION .)
33+
install_clr(corerun)

src/corefx/System.Globalization.Native/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,5 @@ else()
7373
add_definitions(-DU_DISABLE_RENAMING=1)
7474
endif()
7575

76-
install (TARGETS System.Globalization.Native DESTINATION .)
76+
# add the install targets
77+
install_clr(System.Globalization.Native)

src/dlls/clretwrc/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,4 @@ add_library_clr(clretwrc SHARED
2020
)
2121

2222
# add the install targets
23-
install (TARGETS clretwrc DESTINATION .)
24-
25-
if(WIN32)
26-
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/clretwrc.pdb DESTINATION PDB)
27-
endif(WIN32)
23+
install_clr(clretwrc)

0 commit comments

Comments
 (0)