Skip to content

Commit 93b8d97

Browse files
authored
cmake: only strip on non-msvc compilers (#246)
strip the binaries when packaging is active
1 parent a08408f commit 93b8d97

1 file changed

Lines changed: 36 additions & 29 deletions

File tree

SilKit/cmake/SilKitBuildTools.cmake

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,47 @@
55
include(CMakeFindBinUtils)
66

77
macro(silkit_split_debugsymbols targetName)
8-
set(_targetFile "$<TARGET_FILE:${targetName}>")
9-
set(_debugFile "${SILKIT_SYMBOLS_DIR}/${targetName}${CMAKE_DEBUG_POSTFIX}.debug")
10-
message(DEBUG "Split debugsymbols from ${_targetName} into ${_debugFile}")
11-
add_custom_command(
12-
TARGET ${targetName}
13-
POST_BUILD
14-
COMMAND ${CMAKE_OBJCOPY} --only-keep-debug "${_targetFile}" "${_debugFile}"
15-
COMMAND ${CMAKE_STRIP} "${_targetFile}"
16-
COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink="${_debugFile}" "${_targetFile}"
17-
COMMENT "SIL Kit: SILKIT_PACKAGE_SYMBOLS: splitting ELF debug symbols"
18-
)
19-
endmacro()
20-
macro(silkit_strip_distrib targetName)
21-
if(SILKIT_PACKAGE_SYMBOLS)
8+
if(NOT MSVC
9+
AND (CMAKE_STRIP AND EXISTS ${CMAKE_STRIP})
10+
AND (CMAKE_OBJCOPY AND EXISTS ${CMAKE_OBJCOPY})
11+
)
12+
2213
set(_targetFile "$<TARGET_FILE:${targetName}>")
14+
set(_debugFile "${SILKIT_SYMBOLS_DIR}/${targetName}${CMAKE_DEBUG_POSTFIX}.debug")
15+
message(DEBUG "Split debugsymbols from ${_targetName} into ${_debugFile}")
16+
file(MAKE_DIRECTORY "${SILKIT_SYMBOLS_DIR}")
2317
add_custom_command(
2418
TARGET ${targetName}
2519
POST_BUILD
20+
COMMAND ${CMAKE_OBJCOPY} --only-keep-debug "${_targetFile}" "${_debugFile}"
2621
COMMAND ${CMAKE_STRIP} "${_targetFile}"
27-
COMMENT "SIL Kit: stripping ${_targetName}"
22+
COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink="${_debugFile}" "${_targetFile}"
23+
COMMENT "SIL Kit: SILKIT_PACKAGE_SYMBOLS: splitting ELF debug symbols on ${targetName}"
2824
)
2925
endif()
3026
endmacro()
27+
macro(silkit_strip_distrib targetName)
28+
if(NOT MSVC)
29+
if(SILKIT_PACKAGE_SYMBOLS)
30+
set(_targetFile "$<TARGET_FILE:${targetName}>")
31+
add_custom_command(
32+
TARGET ${targetName}
33+
POST_BUILD
34+
COMMAND ${CMAKE_STRIP} "${_targetFile}"
35+
COMMENT "SIL Kit: stripping ${_targetName}"
36+
)
37+
endif()
38+
endif()
39+
endmacro()
3140

3241
macro(silkit_install_debugsymbols targetName)
3342
if(MSVC)
34-
message(STATUS "Installing .pdb symbols file")
35-
install(
36-
FILES $<TARGET_PDB_FILE:SilKit>
37-
DESTINATION ${INSTALL_LIB_DIR}
38-
COMPONENT bin
39-
)
43+
message(STATUS "Installing .pdb symbols file")
44+
install(
45+
FILES $<TARGET_PDB_FILE:SilKit>
46+
DESTINATION ${INSTALL_LIB_DIR}
47+
COMPONENT bin
48+
)
4049
endif()
4150
if(APPLE)
4251
return()
@@ -50,14 +59,12 @@ macro(silkit_install_debugsymbols targetName)
5059

5160
silkit_split_debugsymbols("${targetName}")
5261

53-
file(MAKE_DIRECTORY "${SILKIT_SYMBOLS_DIR}")
54-
55-
message(STATUS "Installing ELF debug file")
56-
install(
57-
FILES "${SILKIT_SYMBOLS_DIR}/${targetName}${CMAKE_DEBUG_POSTFIX}.debug"
58-
DESTINATION ${INSTALL_LIB_DIR}
59-
COMPONENT bin
60-
)
62+
message(STATUS "Installing ELF debug file")
63+
install(
64+
FILES "${SILKIT_SYMBOLS_DIR}/${targetName}${CMAKE_DEBUG_POSTFIX}.debug"
65+
DESTINATION ${INSTALL_LIB_DIR}
66+
COMPONENT bin
67+
)
6168
endif()
6269
endmacro()
6370

0 commit comments

Comments
 (0)