[CMake] Relaying all command line arguments from SuperBuild to ExternalProject_Add

Saad Khattak saadrustam at gmail.com
Wed Jan 31 21:47:54 EST 2018


Thanks J. I could use that to add preprocessor definitions.

However, my question was how I could forward 'all' the command line options
that the user uses to generate the SuperBuild project. Suppose I somehow
managed to capture all the command line arguments which can include
variables specific to CMake and/or projects (i.e. nothing to do with
preprocessor definitions) in a variable called CL_CMAKE_ARGS.

If I do message(${CL_CMAKE_ARGS}) I get:

 -DMY_OPTION_ONE=ON -DMY_OPTION_TWO=OFF -DSOME_VAR_1="Foo"

Now, when I try something like this:

ExternalProject_Add(target
...
CMAKE_ARGS ${CL_CMAKE_ARGS}
...
)

One would expect CL_CMAKE_ARGS to be expanded and the arguments passed to
the ExternalProject_Add function, but that is not the case. I also tried:

ExternalProject_Add(target
...
CMAKE_ARGS "${CL_CMAKE_ARGS}"
...
)

Neither works. It seems like a bug in CMake but I wanted to confirm that I
am not missing something.

On Wed, Jan 31, 2018 at 3:27 PM J Decker <d3ck0r at gmail.com> wrote:

>
> (platfrom defines is a variable suitable for like ADD_DEFINITIONS(
> ${PLATFORM_DEFINES} )
>
>
>   string( REPLACE ";" " " PLATFORM_DEFINES_ARG "${PLATFORM_DEFINES}" )
>   ExternalProject_Add( target
>     ....
> CMAKE_ARGS -DPLATFORM_DEFINES=${PLATFORM_DEFINES_ARG}
>     ......
>  )
>
>
> and in the target cmakelists to use the argument
>
>
> STRING( REPLACE " " ";" PLATFORM_DEFINES ${PLATFORM_DEFINES} )
>
> add_definitions( ${PLATFORM_DEFINES} )
>
>
>
> On Wed, Jan 31, 2018 at 9:36 AM, Saad Khattak <saadrustam at gmail.com>
> wrote:
>
>> I have the following setup:
>> Superbuild
>>    - ExternalProject_Add(a...)
>>    - ExternalProject_Add(b...)
>>    - ExternalProject_Add(c...)
>>    - ExternalProject_Add(d...)
>>
>> The SuperBuild is built from command line with some options e.g.
>> -DMY_OPTION=TRUE. I would like all these options to be passed to each of
>> the ExternalProject_Add CMAKE_ARGS.
>>
>> I tried to capture the arguments using the solution posted here:
>> https://stackoverflow.com/a/10218582/368599
>>
>> The arguments are captured properly (i.e. I printed them out to make sure
>> they are correct) but relaying them to ExternalProject_Add appears to be
>> problematic. I tried the following ways to forward the arguments (as
>> outlined in the stackoverflow solution):
>>
>> ExternalProject_Add(...
>>   CMAKE_ARGS ${CMAKE_ARGS}
>>   )
>>
>> ExternalProject_Add(...
>>   CMAKE_ARGS "${CMAKE_ARGS}" # quotes
>>   )
>>
>> ExternalProject_Add(...
>>   CMAKE_ARGS "${MY_CMAKE_ARGS}" # changed the variable name in case it
>> conflicts
>>   )
>>
>> None of that seems to work. CMake appears to ignore the commands
>> forwarded.
>>
>> Is there something I am missing?
>>
>> Thanks,
>> Saad
>>
>>
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more
>> information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> https://cmake.org/mailman/listinfo/cmake
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180201/8656ec4b/attachment.html>


More information about the CMake mailing list