[CMake] Passing options into COMMAND inside of add_custom_target() or add_custom_command()
Kornel Benko
kornel at lyx.org
Sat Jun 28 12:00:52 EDT 2014
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"
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140628/a09884a0/attachment.sig>
More information about the CMake
mailing list