You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.5 KiB

  1. # This module is used to strip symbols from targets
  2. If ( __STRIP_SYMBOLS_INCLUDED )
  3. Return ( )
  4. EndIf ( )
  5. Set ( __STRIP_SYMBOLS_INCLUDED TRUE )
  6. CMake_Minimum_Required ( VERSION 3.0 )
  7. # Strip symbols from the given target
  8. # TARGET_NAME - Target to strip symbols from
  9. # OUTPUT_FILENAME - Filename of the stripped debug informations
  10. Function ( Strip_Symbols TARGET_NAME OUTPUT_FILENAME )
  11. If ( CMAKE_OBJCOPY )
  12. Set ( OBJCOPY "${CMAKE_OBJCOPY}" )
  13. Else ( )
  14. Find_Program ( OBJCOPY objcopy )
  15. If ( NOT OBJCOPY )
  16. Message ( FATAL_ERROR "objcopy not found" )
  17. EndIf ( )
  18. EndIf ()
  19. Set ( STRIP_SRC_FILE $<TARGET_FILE:${TARGET_NAME}>)
  20. Set ( STRIP_DST_FILE ${STRIP_SRC_FILE}.dbg )
  21. Set ( ${OUTPUT_FILENAME} "${STRIP_DST_FILE}" PARENT_SCOPE )
  22. Add_Custom_Command ( TARGET ${TARGET_NAME}
  23. POST_BUILD
  24. VERBATIM
  25. COMMAND ${OBJCOPY} --only-keep-debug ${STRIP_SRC_FILE} ${STRIP_DST_FILE}
  26. COMMAND ${OBJCOPY} --strip-unneeded ${STRIP_SRC_FILE}
  27. COMMAND ${OBJCOPY} --add-gnu-debuglink=${STRIP_DST_FILE} ${STRIP_SRC_FILE} )
  28. EndFunction ( )