[cmake-developers] [CMake 0014203]: Automatically add "call" in "add_custom_command()".
Mantis Bug Tracker
mantis at public.kitware.com
Tue Jun 4 16:07:37 EDT 2013
The following issue has been SUBMITTED.
======================================================================
http://www.cmake.org/Bug/view.php?id=14203
======================================================================
Reported By: André Caron
Assigned To:
======================================================================
Project: CMake
Issue ID: 14203
Category: CMake
Reproducibility: always
Severity: minor
Priority: normal
Status: new
======================================================================
Date Submitted: 2013-06-04 16:07 EDT
Last Modified: 2013-06-04 16:07 EDT
======================================================================
Summary: Automatically add "call" in "add_custom_command()".
Description:
When 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 Reproduce:
Unzip 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 Information:
When 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 :-)
======================================================================
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
======================================================================
More information about the cmake-developers
mailing list