[CMake] Passing a CMake list "as is" to a custom target

David Cole david.cole at kitware.com
Wed Jun 22 16:32:58 EDT 2011


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

HTH,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110622/e8623813/attachment.htm>


More information about the CMake mailing list