View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014203CMakeCMakepublic2013-06-04 16:072013-11-04 09:33
ReporterAndré Caron 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionduplicate 
PlatformOSWindowsOS VersionAll
Product VersionCMake 2.8.6 
Target VersionFixed in Version 
Summary0014203: Automatically add "call" in "add_custom_command()".
DescriptionWhen using "add_custom_command()"[1] with the Visual Studio 2010 generator such that the provided command-line resolves to a batch file, execution is interrupted without completing all commands.

This affects "add_custom_command()" directives with multiple commands most noticeably because execution is stopped after the first command that resolves to a batch file. However, even in the case of a single command, the batch file generated by CMake never completes, incorrectly reporting the process status.

This is caused by a well known limitation of the "cmd.exe" command prompt, where invoking another batch file transfers control without returning. See [3] and [4] for details.

This is quite annoying because for portable "CMakeLists.txt" files, I need to add the following:

   set(COMMAND_PREFIX "")
   if (MSVC) # not sure this correctly solves the problem for all generators.
     set(COMMAND_PREFIX "call")
   endif()

   add_custom_command(
     COMMAND "${COMMAND_PREFIX}" "external-program" ...
   )

It would be much easier if CMake automatically prefixed all calls to external programs with the "call" operator.

[1]: Presumably, "add_custom_target()" has the same limitation.
[2]: Presumably, other Visual Studio generators, the NMake generator and NMake JOM generator will have the same limitation.
[3]: http://stackoverflow.com/q/1103994/313063 [^]
[4]: http://www.robvanderwoude.com/call.php [^]
Steps To ReproduceUnzip the attachment, generate build scripts using the "Visual Studio 10" generator, open the solution.

Build the "IdealTarget" target and look at the Visual Studio output window; you should see that the "Running 2nd command." message does not appear.

Build the "PatchedTarget" target and look at the Visual Studio output window; you should see that the "Running 2nd command." appears as expected.
Additional InformationWhen using the "call" operator, you need to use a "setlocal"/"endlocal" pair but this is already in the generated ".tlog.command.*" files generated by CMake, so it really looks like there is not need to add anything else than the "call" prefix.

Note that the "call" operator is a no-op when the program being invoked is a real executable (".exe" file), so it is safe to add it to ALL external command calls in the batch file generated by CMake.

For backward compatibility with existing scripts that explicitly patch custom commands using the "call" operator, the fix should check if the first token is "call" and avoid repeating it if it is already present.

Bonus points if the "call" operator can be removed by generators that don't generate batch files. I'm not sure if this is safe as it might interfere with existing scripts named "call", but it's worth asking anyways :-)
TagsNo tags attached.
Attached Fileszip file icon cmake-bug.zip [^] (1,040 bytes) 2013-06-04 16:07

 Relationships
duplicate of 0012445closedDavid Cole Do not use git.cmd in FindGit module 

  Notes
(0033238)
Brad King (manager)
2013-06-04 16:22

This was resolved for CMake 2.8.7 about 18 months ago:

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

Please try the latest version before reporting bugs.
(0034364)
Robert Maynard (manager)
2013-11-04 09:33

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2013-06-04 16:07 André Caron New Issue
2013-06-04 16:07 André Caron File Added: cmake-bug.zip
2013-06-04 16:20 Brad King Relationship added duplicate of 0012445
2013-06-04 16:22 Brad King Note Added: 0033238
2013-06-04 16:22 Brad King Status new => resolved
2013-06-04 16:22 Brad King Resolution open => duplicate
2013-11-04 09:33 Robert Maynard Note Added: 0034364
2013-11-04 09:33 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team