1 # Split debug information from an executable into a separate file.
2 # SPLIT_DEBUG_INFORMATION(EXE_TARGET)
5 # - http://cmake.3232098.n2.nabble.com/Save-stripped-debugging-information-td6819195.html
6 # - http://sourceware.org/bugzilla/show_bug.cgi?id=14527
7 # - If debug symbols are stripped before .gnu_debuglink is added,
8 # the section will be truncated to .gnu_deb, and hence won't
9 # be recognized by gdb.
10 # - FIXME: If the above .gnu_debuglink workaround is used, Windows XP
11 # and Windows 7 will claim that the executable isn't a valid Win32
12 # executable. (Wine ignores it and works fine!)
15 # CMake automatically finds objcopy and strip as
16 # part of its toolchain initialization.
18 MESSAGE(WARNING "'objcopy' was not found; debug information will not be split.")
19 ELSEIF(NOT CMAKE_STRIP)
20 MESSAGE(WARNING "'strip' was not found; debug information will not be split.")
24 MACRO(SPLIT_DEBUG_INFORMATION EXE_TARGET)
27 # MSVC splits debug information by itself.
29 ELSEIF(NOT CMAKE_OBJCOPY)
30 # 'objcopy' is missing.
32 ELSEIF(NOT CMAKE_STRIP)
38 # NOTE: $<TARGET_FILE:gcbanner> is preferred,
39 # but this doesn't seem to work on Ubuntu 10.04.
40 # (cmake_2.8.0-5ubuntu1_i386)
41 GET_PROPERTY(SPLITDEBUG_EXE_LOCATION TARGET ${EXE_TARGET} PROPERTY LOCATION)
43 # NOTE: objcopy --strip-debug does NOT fully
44 # strip the binary; two sections are left:
45 # - .symtab: Symbol table.
46 # - .strtab: String table.
47 # These sections are split into the .debug file, so there's
48 # no reason to keep them in the executable.
49 ADD_CUSTOM_COMMAND(TARGET ${EXE_TARGET} POST_BUILD
50 COMMAND ${CMAKE_OBJCOPY} --only-keep-debug
51 ${SPLITDEBUG_EXE_LOCATION} ${CMAKE_CURRENT_BINARY_DIR}/${EXE_TARGET}.debug
52 COMMAND ${CMAKE_STRIP}
53 ${SPLITDEBUG_EXE_LOCATION}
54 COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${EXE_TARGET}.debug
55 ${SPLITDEBUG_EXE_LOCATION}
58 UNSET(SPLITDEBUG_EXE_LOCATION)
60 ENDMACRO(SPLIT_DEBUG_INFORMATION)