[CMake] add_custom_command(TARGET ..) does nothing if target don't exist?

Johan Björk phb at spotify.com
Tue Aug 30 12:45:29 EDT 2011


Hi guys,

I just ran into the following issue, and I'm quite baffled? Is this really
expected behaviour?

cherimoya:cmake-postbuildearly phb$ cat CMakeLists
ADD_CUSTOM_COMMAND(TARGET foo POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo
'hello')
TARGET_LINK_LIBRARIES(foo "-lbar")
cherimoya:cmake-postbuildearly phb$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
ADD_CUSTOM_COMMAND(TARGET foo POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo
'hello')
FILE(WRITE foo.c "")
ADD_LIBRARY(foo foo.c)

FILE(WRITE bar.c "")
ADD_LIBRARY(bar bar.c)
ADD_CUSTOM_COMMAND(TARGET bar POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo
'hello')


<after generation, makefile or xcode generator doesn't matter>
cherimoya:cmake-postbuildearly phb$ grep -R hello *
CMakeFiles/bar.dir/build.make: /usr/local/Cellar/cmake/2.8.5/bin/cmake -E
echo 'hello'
CMakeLists:ADD_CUSTOM_COMMAND(TARGET foo POST_BUILD COMMAND ${CMAKE_COMMAND}
-E echo 'hello')
CMakeLists.txt:ADD_CUSTOM_COMMAND(TARGET foo POST_BUILD COMMAND
${CMAKE_COMMAND} -E echo 'hello')
CMakeLists.txt:ADD_CUSTOM_COMMAND(TARGET bar POST_BUILD COMMAND
${CMAKE_COMMAND} -E echo 'hello')
ie, it simply ignores the custom command for when the target does not yet
exist!


/Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110830/19d7fbc4/attachment.htm>


More information about the CMake mailing list