[CMake] Help with ADD_CUSTOM_COMMAND
Alexander Neundorf
a.neundorf-work at gmx.net
Wed Feb 13 17:01:57 EST 2008
On Wednesday 13 February 2008, Michael Kaplan wrote:
> I am currently using cmake 2.4 (patch 8) and i'm having a problem with
> ADD_CUSTOM_COMMAND
>
> I created a macro which defined an add_custom_command to which i'd like
> to pass some extra arguments in variables. However, when I try to pass
> in a string with spaces, the spaces get "escaped" which breaks the
> command. Below is a simplified CMakeLists.txt that illustrates the
> issue I am having.
>
> SET(OPTIONS "-H -l")
>
> MACRO(RUN_CMD FILENAME)
> ADD_CUSTOM_COMMAND(
> OUTPUT new.cpp
> COMMAND cp ${OPTIONS} ${FILENAME} new.cpp
> )
> ENDMACRO(RUN_CMD)
>
> RUN_CMD(old.cpp)
>
> ADD_EXECUTABLE(new new.cpp)
>
>
> I'd like the the custom command to run to be
> cp -H -l old.cpp new.cpp
> but instead, what is generated into the CMakeFiles/new.dir/build.make
> file is
> cp -H\ -l old.cpp new.cpp
>
> Note the -H\ -l. This breaks the command I need to run. The above is a
> contrived example. In actuality, I define the Macro in a "UseXXX.cmake"
> type file and it is used elsewhere. The "OPTIONS" variable is used to
> pass extra options as needed to the command. Is there anyway to do this
> with getting the string escaped when run as part of the command?
The string is escape because you tell cmake that it is one string by putting
it into quotes. Just leave the quotes away and then cmake will interpret it
as two strings and so it will not be escaped when the command is executed.
Alex
More information about the CMake
mailing list