[CMake] Extra options for strip?

Michael Hertling mhertling at online.de
Fri Apr 1 05:09:29 EDT 2011


On 03/28/2011 03:08 PM, Hariharan wrote:
> I'm trying to build a stripped target using install/strip with the function
> and line information retained. I need to pass the "--strip-debug" and
> "--keep-file-symbols" to the system strip binary because the default is to
> strip all symbols. Is there any way to achieve this using cmake?
> 
> Regards,
> Hari

AFAICS, the only possibility to do this is the usage of a wrapper
script around the actual strip utility, e.g.: Place the following
strip.in template with execute permissions in CMAKE_SOURCE_DIR:

#!/bin/sh
@CMAKE_STRIP@ --strip-debug --keep-file-symbols $*

Now, look at the following CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(STRIP C)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/strip.in
               ${CMAKE_BINARY_DIR}/strip @ONLY)
SET(CMAKE_STRIP ${CMAKE_BINARY_DIR}/strip)
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "int main(void){return 0;}\n")
ADD_EXECUTABLE(main main.c)
INSTALL(TARGETS main RUNTIME DESTINATION bin)

This should embed ${CMAKE_BINARY_DIR}/strip as strip utility in the
${CMAKE_BINARY_DIR}/cmake_install.cmake script. Perhaps, your issue
would be worth a feature request for a CMAKE_STRIP_FLAGS variable.

'hope that helps.

Regards,

Michael


More information about the CMake mailing list