Steven Van Ingelgem wrote:
The problem in fact is in cmcommand.h @ line 67: "InvokeInitialPass"

Here there is done the pass through "ExpandArguments", which removes
the knowledge of the quoted/unquoted nature of the arguments... Before
is known if it's VERBATIM or not...

I think this is a deep problem, and rather difficult to solve.

Do you want me to submit it to the bug tracker?

No. This is not a CMake bug. The VERBATIM option is a feature of add_custom_command, not of the CMake language. In fact the only reason it is there is to implement the correct behavior of add_custom_command without breaking compatibility with older code that tried to add all the shell escapes directly. The option does not indicate that the text following it will be placed in the build system verbatim.

It's the CMakeLists.txt file writer's job to get the text that should appear in the command through the CMake language and given to add_custom_command as arguments. Each argument to the COMMAND option of add_custom_command becomes one argument in the generated build system. The VERBATIM option just tells it to implement proper escaping for the arguments.

Placing shell code directly in a custom command is not a good idea. It will not work for non-Unix makes. Even if you want to run a unix shell script and don't care about other platforms, you should just run the shell with the script as part of the custom command instead of depending on the implementation detail that make tools run the commands in a shell.

add_custom_command(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test.txt
COMMAND /bin/sh ${CMAKE_CURRENT_SOURCE_DIR}/myscript.sh ${CMAKE_CURRENT_BINARY_DIR}/test.txt
  )
add_custom_target(
  DriveTest ALL
  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/test.txt
  )

Then put your code in myscript.sh and refer to "$1" for the output file.

-Brad

_______________________________________________
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to