MantisBT - CMake
View Issue Details
0014929CMakeCMakepublic2014-05-23 06:442014-11-03 08:38
Lars Christensen 
 
lowminoralways
closednot fixable 
CMake 2.8.12.2 
 
0014929: Dependencies of custom targets are built as part of "Build Solution" in Visual Studio
If a CMakeLists.txt has two add_custom_target()'s where one is a dependency of the other, the dependency gets built every time you "Build Solution" in Visual Studio.

add_custom_target(foo DEPENDS main COMMAND cmd /c echo foo MESSAGE foo)
add_custom_target(bar DEPENDS foo COMMAND cmd /c echo bar MESSAGE bar)

In this case, the 'foo' target is selected for as a project to build every time in the Visual Studio 'Configuration Manager'. 'bar' is NOT selected to build every time, and is only build if built explicitly. If 'bar' is removed from CMakeLists.txt, 'foo' is no longer built every time, and is deselected from Build in the 'Configuration Manager'.

Neither 'foo' nor 'bar' is marked as a dependency of ALL_BUILD (As expected). The problems is in the 'Configuration Manager', which selected which projects are build when you choose 'Build Solution'.

No tags attached.
Issue History
2014-05-23 06:44Lars ChristensenNew Issue
2014-05-23 06:53Nils GladitzNote Added: 0035916
2014-05-23 07:07Lars ChristensenNote Added: 0035917
2014-05-23 07:11Lars ChristensenNote Edited: 0035917bug_revision_view_page.php?bugnote_id=35917#r1459
2014-05-23 08:46Brad KingNote Added: 0035918
2014-05-23 09:41Lars ChristensenNote Added: 0035921
2014-05-23 09:52Brad KingNote Added: 0035922
2014-05-23 09:52Brad KingStatusnew => resolved
2014-05-23 09:52Brad KingResolutionopen => not fixable
2014-11-03 08:38Robert MaynardNote Added: 0037140
2014-11-03 08:38Robert MaynardStatusresolved => closed

Notes
(0035916)
Nils Gladitz   
2014-05-23 06:53   
DEPENDS is used for file dependencies.
Try add_dependencies() for inter-target dependencies.
(0035917)
Lars Christensen   
2014-05-23 07:07   
(edited on: 2014-05-23 07:11)
Good point - i forgot about this! I tried this:

add_custom_target(foo COMMAND cmd /c echo foo COMMENT "Building foo")
add_custom_target(bar COMMAND cmd /c echo bar COMMENT "Building bar")
add_dependencies(bar foo)

But the problem persist. foo is built every time, bar is not. If I remove add_dependencies(bar foo)", neither foo or bar is built.

Edit: MESSAGE => COMMENT

(0035918)
Brad King   
2014-05-23 08:46   
I think this behavior was introduced intentionally here:

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b0bc59f70 [^]

One can see it in the modern sources here:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmGlobalVisualStudio7Generator.cxx;hb=v3.0.0-rc6#l976 [^]

IIRC, if foo is not marked for the current configuration then it will be skipped when bar is built even though the dependency is recorded.
(0035921)
Lars Christensen   
2014-05-23 09:41   
Thanks for the rapid response, you guys are awesome. I think you are right. I tried removing the 'Build' flag in the Configuration Manager, so that 'foo' isn't built. When manually building 'bar', 'foo' isn't build either (as Brad expected), even though dependencies are correct in under 'Project Dependencies'.

In my case, I have a rather big InnoSetup build job in the target that was built, which I certainly don't want to build every time. I have worked around the problem by having the two targets depends on a file from an add_custom_command() instead of each other.
(0035922)
Brad King   
2014-05-23 09:52   
Okay, thanks for verifying my explanation (and memory). I'm glad you have a workaround. I'll resolve this as not fixable.
(0037140)
Robert Maynard   
2014-11-03 08:38   
Closing resolved issues that have not been updated in more than 4 months.