[CMake] Passing options into COMMAND inside of add_custom_target() or add_custom_command()
Hendrik Sattler
post at hendrik-sattler.de
Sat Jun 28 13:21:50 EDT 2014
On 28. Juni 2014 18:00:52 MESZ, Kornel Benko <kornel at lyx.org> wrote:
>Am Samstag, 28. Juni 2014 um 12:06:56, schrieb Martin Mitáš
><mity at morous.org>
>>
>> Hello,
>>
>> I'm trying to pass multiple options from outside to a command in
>add_custom_target()
>> or add_custom_command(). I am new to CMake and I don't know whether
>the observed
>> behavior is bug or I do it in a wrong way.
>>
>> I am doing all this with CMake 3.0 on Windows within MSYS environment
>if it
>> plays some role.
>>
>> A test demonstrating the issue follows (using 'ls' as the command and
>'-l -h'
>> as the options):
>>
>> # ==== CMakeLists.txt ====
>> cmake_minimum_required(VERSION 3.0)
>> project(test_project)
>>
>> set(MYTOOL "ls")
>>
>> add_custom_target(
>> x ALL
>> COMMAND ${MYTOOL} ${MYTOOL_FLAGS}
>> COMMENT "test"
>> VERBATIM
>> )
>> # ==== End of CMakeLists.txt ====
>>
>>
>> Using the CMakeLists.txt above, I get this:
>>
>> $ mkdir build && cd build
>> $ cmake -G "MSYS Makefiles" -DMYTOOL_FLAGS="-l -h" ..
>> ... (unimportant output censored)
>> $ make VERBOSE=1
>> ... (unimportant output censored)
>> [100%] test
>> ls "-l -h"
>> ls: invalid option --
>
>So 'ls' got '-l -h' as one paramater.
>I would use
>1.) -DMYTOOL_FLAGS="-lh"
>
>or
>2.) -DMYTOOL_FLAGS="-l;-h"
Or maybe escaping on the shell as
"-DMYTOOL_FLAGS=-l -h"
also works?
>> Try `ls --help' for more information.
>> make[2]: *** [CMakeFiles/x] Error 2
>> make[2]: Leaving directory `/prj/pok/build'
>> make[1]: *** [CMakeFiles/x.dir/all] Error 2
>> make[1]: Leaving directory `/prj/pok/build'
>> make: *** [all] Error 2
>>
>>
>> As can be seen, CMake propagates the contents of ${MYTOOL_FLAGS} as a
>single
>> option into 'ls', i.e. generated Makefile attempts to execute
>>
>> ls "-l -h"
>>
>> instead of
>>
>> ls -l -h
>>
>> Any ideas how to do this correctly?
>>
>> Thanks,
>> Martin
>>
>
> Kornel
>
>------------------------------------------------------------------------
--
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.
More information about the CMake
mailing list