Suppose I have the following CMake snippet:
MACRO(ADD_CUSTOM_TARGET_COMMAND tag OUTPUT file)
ADD_CUSTOM_TARGET(tag
${ARGN}
)
ADD_CUSTOM_TARGET(OUTPUT file
${ARGN}
)
ENDMACRO()
ADD_CUSTOM_TARGET_COMMAND(tag
OUTPUT file
COMMAND git tag -a -m "${msg}" 1.0.0 HEAD
VERBATIM
)
If msg
contains semicolon such as "msg1;msg2"
, then the actual command is expanded to
git -a -m "msg1" "msg2" 1.0.0. HEAD
which leads to a syntax error.
I have tried to use \
to escape the ;
but to no avail.
What should I do?
Adds a target with the given name that executes the given commands. The target has no output file and is always considered out of date even if the commands try to create a file with the name of the target.
The command becomes part of the target and will only execute when the target itself is built. If the target is already built, the command will not execute. This defines a new command that will be associated with building the specified <target> .
The add_custom_command() documentation says "This defines a command to generate specified OUTPUT file(s). A target created in the same directory (CMakeLists. txt file) that specifies any output of the custom command as a source file is given a rule to generate the file using the command at build time."
There is a special token since 2.8.11 version: $<SEMICOLON> (http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:add_custom_command).
I use it for example for such find command:
find /path/to/search -name some\*name \! -path excluded\*Pattern -exec ln -sf "{}" \;
the following way:
set(
FIND_ARGUMENTS
"${SEARCH_PATH} -name some\\*name \\! -path exclued\\*Pattern -exec ln -sf {} \\$<SEMICOLON>"
)
separate_arguments(FIND_ARGUMENTS)
add_custom_command(TARGET ${PROJECT}
POST_BUILD
COMMAND "find" ${FIND_ARGUMENTS}
WORKING_DIRECTORY ${WORKING_PATH}
)
Note that with separate_arguments VERBATIM parameter for add_custom_command is not needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With