-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeStripAll.cmake
48 lines (42 loc) · 1.25 KB
/
MeStripAll.cmake
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
if(NOT CMAKE_SCRIPT_MODE_FILE)
add_custom_target(
strip-all
DEPENDS install-all
COMMAND "${CMAKE_COMMAND}"
-D "PREFIX=${CMAKE_INSTALL_PREFIX}"
-D "OBJCOPY=${CMAKE_OBJCOPY}"
-P "${CMAKE_CURRENT_LIST_FILE}"
)
endif()
if(NOT CMAKE_SCRIPT_MODE_FILE STREQUAL CMAKE_CURRENT_LIST_FILE)
return()
endif()
file(GLOB binaries RELATIVE "${PREFIX}/bin/" "${PREFIX}/bin/*")
if(NOT OBJCOPY)
find_program(OBJCOPY objcopy llvm-objcopy)
endif()
if(NOT OBJCOPY OR OBJCOPY STREQUAL OBJCOPY-NOTFOUND)
message(FATAL_ERROR "objcopy not found")
else()
message(STATUS "Found objcopy: ${OBJCOPY}")
endif()
file(MAKE_DIRECTORY "${PREFIX}/dbg")
foreach(binary ${binaries})
set(file "${PREFIX}/bin/${binary}")
if(IS_DIRECTORY "${file}" OR IS_SYMLINK "${file}")
continue()
endif()
message(STATUS "Strip: ${file}")
if(x$ENV{NO_DBG} STREQUAL x)
execute_process(
COMMAND ${OBJCOPY} --only-keep-debug ${file} "${PREFIX}/dbg/${binary}.dbg"
ERROR_QUIET
)
endif()
execute_process(
COMMAND ${OBJCOPY} --strip-all ${file} ERROR_QUIET
)
execute_process(
COMMAND ${OBJCOPY} --remove-section .gnu_debuglink ${file} ERROR_QUIET
)
endforeach()