[CMake] Custom target/command dependencies with Visual Studio

Lars Christensen larsch at belunktum.dk
Thu Feb 23 08:21:36 EST 2012


I have this simple CMakeLists.txt:

add_custom_target(deptest ALL DEPENDS files.out)
add_custom_command(OUTPUT foo.x COMMAND touch foo.x DEPENDS foo.cpp)
add_custom_command(OUTPUT bar.x COMMAND false DEPENDS bar.cpp)
add_custom_command(OUTPUT files.out COMMAND touch files.out DEPENDS foo.x
bar.x)

Notice that bar.x always fails building intentionally, to demonstrate this
issue:

When I generate Visual Studio 10 solution & project files from this and
build it, it keeps regenerating foo.x every time i choose "Build Solution",
even though it is generated perfectly the first time. Only if ALL the
dependencies of files.out are successfully generated, will VS stop building
each and every one.

This is a small problem for this example, but becomes a major nuisance in a
project with hundreds of custom commands generating intermediate files
based on .cpp source files. If just one of them fails, they are all rebuilt.

I don't know if this is the fault of CMake or Visual Studio, but perhaps
someone else have some insight. I cannot see anything wrong with the
dependency settings for the generated .vcxproj files.

With the "MinGW Makefiles" generator, I don't have the same problem, and
foo.x is only built once.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120223/28fa0ab5/attachment.htm>


More information about the CMake mailing list