Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: How to output semicolon (;) as command options in ADD_CUSTOM_TARGET

Tags:

cmake

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?

like image 686
Ding-Yi Chen Avatar asked Jul 21 '12 14:07

Ding-Yi Chen


People also ask

What does Add_custom_target do in CMake?

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.

What would happen if you execute the file add_custom_command?

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> .

What is add_custom_command?

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."


1 Answers

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.

like image 145
gshep Avatar answered Oct 13 '22 00:10

gshep