[CMake] Passing a CMake list "as is" to a custom target
Michael Hertling
mhertling at online.de
Wed Jun 22 17:31:20 EDT 2011
On 06/22/2011 10:32 PM, David Cole wrote:
> On Wed, Jun 22, 2011 at 4:24 PM, Hauke Heibel
> <hauke.heibel at googlemail.com>wrote:
>
>> On Wed, Jun 22, 2011 at 10:09 PM, Michael Hertling <mhertling at online.de>
>> wrote:
>>> You might use -DMY_VARIABLE="${ARGUMENTS}" without VERBATIM, and
>>> SEPARATE_ARGUMENTS(MY_VARIABLE) in Foo.cmake. This doesn't prevent
>>> the list's conversion, but seems a bit smarter than a FOREACH loop.
>>
>> I considered this but since MY_VARIABLE contains paths which may
>> contain white spaces, I explicitly chose the asterisk because it
>> cannot be part of a path.
>>
>> Nonetheless thanks for the reply.
>>
>> - Hauke
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>>
>
>
> We use a similar technique in the ExternalProject module with a parameter we
> call LIST_SEPARATOR.
>
> The idea is that you can encode a list with an arbitrary string of your
> choosing that is not otherwise in your input list (like you've chosen the
> asterisk) into a string that contains no semi-colons. And then decode it
> with a string replace operation just before using it.
>
> The code used in ExternalProject looks like this:
> get_property(sep TARGET ${name} PROPERTY _EP_LIST_SEPARATOR)
> if(sep AND command)
> string(REPLACE "${sep}" "\\;" command "${command}")
> endif()
>
> It ends up lookin like this at the calling point:
> ExternalProject_Add(proj
> ...
> LIST_SEPARATOR ::
> CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
> -DTEST_LIST:STRING=A::B::C
> ...
> )
>
> I think that's the best you can do, even though you called it a hack in the
> original posting. :-)
>
> Let me know if you come up with a non-hack. I'd be curious to see it...
AFAICS, there can't be a really universal solution to this issue;
regardless by which character/string the semicolon is replaced at
"cmake -D... -P ...", the replacement might already be contained in
the argument, so the occurrences are indistinguishable later on. Thus,
the approach using a separator known to not appear in the argument is
probably the most robust one. Perhaps, one could support the necessary
encoding/decoding of the list with an {EN,DE}CODE_LIST() function pair.
Regards,
Michael
More information about the CMake
mailing list