[CMake] Adding non-file dependencies to a custom target
Giampiero Salvi
giampi at kth.se
Tue Oct 21 05:33:20 EDT 2008
Perhaps simplifying the code would make it clearer:
This is my CMakeLists.txt file (I modified the code from a post in August):
cmake_minimum_required(VERSION 2.6)
PROJECT(TEST)
ADD_CUSTOM_TARGET(foo
COMMAND echo "foo"
DEPENDS foo.txt
COMMENT "Fooing .."
)
ADD_CUSTOM_TARGET(bar ALL
COMMAND echo "bar"
COMMENT "Bar-tender .."
)
ADD_DEPENDENCIES(bar foo)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_SOURCE_DIR}/bar2.txt
COMMAND echo bar2 > ${CMAKE_SOURCE_DIR}/bar2.txt
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
ADD_CUSTOM_TARGET(bar2 ALL
DEPENDS ${CMAKE_SOURCE_DIR}/bar2.txt
)
ADD_DEPENDENCIES(bar2 foo)
In the case of target bar everything works because bar is built every
time, but this is not what I want. I want to build the target if and
*only* if the dependencies have changed. So I use the form in bar2
instead, as suggested by the documentation. However, in this case if I
change foo.txt, target foo is built again (as a matter of fact it is
always built), but target bar2 is not rebuilt.
Can anyone explain why? And tell me how to implement this right?
Thank you,
Giampiero
More information about the CMake
mailing list