[CMake] Custom Commands & Generator Expressions

Steven Wilson steven.wesley.wilson at gmail.com
Wed Jan 29 14:58:43 EST 2014


Consider the following CMakeLists.txt file (on a Mac, 10.9.1, Xcode 5, Unix
Makefiles generator):

cmake_minimum_required(VERSION 2.8.12)

project(CustomCommandTest)

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test.cpp
COMMAND echo "#include <iostream>" > ${CMAKE_CURRENT_BINARY_DIR}/test.cpp
COMMAND echo "" >> ${CMAKE_CURRENT_BINARY_DIR}/test.cpp
COMMAND echo "int main()" >> ${CMAKE_CURRENT_BINARY_DIR}/test.cpp
COMMAND echo "{" >> ${CMAKE_CURRENT_BINARY_DIR}/test.cpp
COMMAND echo " std::cout << \"Hello World\" << std::endl;" >>
${CMAKE_CURRENT_BINARY_DIR}/test.cpp
COMMAND echo " return 0;" >> ${CMAKE_CURRENT_BINARY_DIR}/test.cpp
COMMAND echo "}" >> ${CMAKE_CURRENT_BINARY_DIR}/test.cpp
COMMAND echo "" >> ${CMAKE_CURRENT_BINARY_DIR}/test.cpp
VERBATIM
)


add_executable(customcommandtest ${CMAKE_CURRENT_BINARY_DIR}/test.cpp)


add_custom_command(TARGET customcommandtest POST_BUILD
COMMAND $<$<CONFIG:Release>:strip -u -r customcommandtest>
)


The custom command for the POST_BUILD step should invoke strip to strip the
binary of symbols.

Instead the following output is produced:

Linking CXX executable customcommandtest

/Users/stevew/cmake/install/bin/cmake -E cmake_link_script
CMakeFiles/customcommandtest.dir/link.txt --verbose=1

/usr/bin/c++   -O3 -DNDEBUG -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
-Wl,-search_paths_first -Wl,-headerpad_max_install_names
CMakeFiles/customcommandtest.dir/test.cpp.o  -o customcommandtest

"\$<1:strip" -u -r customcommandtest>

Note the "\$<1:strip" -u -r customcommandtest> output from the generator
expression.

What do I need to change in the POST_BUILD custom command to make the
generator expression work correctly?

Thanks,

Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20140129/9b704b6a/attachment.html>


More information about the CMake mailing list