[CMake] Automatic libraries stripping

rozelak at volny.cz rozelak at volny.cz
Thu May 7 09:13:49 EDT 2009


Hallo everybody.

I would like to ask you, if (and how, if so) it is possible to set CMake
to strip (/usr/bin/strip) the generated libraries. Let me note that
build works without problems.

I made the following definition (LIB_NAME is item defined by me):

ADD_CUSTOM_COMMAND(TARGET ${LIB_NAME}
POST_BUILD
COMMAND   ${CMAKE_STRIP} *.so )

and for SWIG generated wrappers (PYTHON_PACKAGE is item defined by me,
similar it is for java):

ADD_CUSTOM_COMMAND( TARGET    ${SWIG_MODULE_${PYTHON_PACKAGE}_REAL_NAME}
POST_BUILD
COMMAND   ${CMAKE_STRIP} *.so )

There are several problems with it:
- it does not strip .a libraries
- it does not strip .dll/.dll.a libraries generated by mingw toolchain

Well, I can play with the pattern given to strip binary, but I am not
sure which solution is the most robust, taking into account various
forms of library names (see further).

Therefore, I would like to ask, if there is a robust solution, how to
strip the libraries automatically, no matter if they are prefixed by
'lib*' or end by '.so', '.a' or '.dll'.


I know that CPACK_STRIP_FILES can be set to ON, but I do not build packages
(I just have INSTALL() which basically copy the generated stuff into
directory, from where it can be downloaded by other team members).

I also suppose that ADD_LIBRARY() knows exactly the name of library to
generate (for gcc it generates '-o libMyLib.so' in link command, or
'ar ... libMyLib.o' when static lib is built), and it also knows if
${CMAKE_STRIP} is defined. Also, ADD_LIBRARY() knows that there are
more libraries to generate for mingw toolchain (it generates '-o libMyLib.dll
-Wl,--out-implib,libMyLib.dll.a'). It would be cool to have an option
in ADD_LIBRARY() that would switch on the stripping of all libraries
generated. Well, I know that it is not implemented, it is just an idea
...


Nevertheless, I would like to ask you, if you know how to solve it by
means of CMake available at the moment (version 2.6). Is there for example
a variable holding the name of library, or libraries, if more are generated
(see mingw example)? Could it be solved in a robust and toolchain (e.g.
library name) independent way?

Thank you very much,
Dan


P.S. My CMake is version 2.6



More information about the CMake mailing list