[CMake] cmake - escape/delay variable expansion

Doug Reiland dreiland at gmail.com
Thu Jun 3 10:43:33 EDT 2010


Thanks to both of you. This is exactly what I was looking for.


On Thu, Jun 3, 2010 at 8:01 AM, Ryan Pavlik <rpavlik at iastate.edu> wrote:
> I would think that this is exactly what the string configure command is for:
> http://cmake.org/cmake/help/cmake-2-8-docs.html#command:string
>
> Ryan
>
> On 6/2/10 9:24 PM, Michael Hertling wrote:
>>
>> On 06/02/2010 10:24 PM, Doug Reiland wrote:
>>
>>>
>>> Is there anyway to do in a generic fashion?
>>> For example, I don't know what all the variables are.
>>> I can be certain that they are valid, for example build-dir is set in
>>> scope.
>>> However, the string can have several "variables" in it.
>>>
>>
>> The following function EXPAND() replaces all occurrences of "${...}" in
>> INPUT with the current value of the appropriate variable and stores the
>> result in OUTPUT:
>>
>> FUNCTION(EXPAND OUTPUT INPUT)
>>     STRING(REGEX MATCH "\\\${[^}]*}" m "${INPUT}")
>>     WHILE(m)
>>         STRING(REGEX REPLACE "\\\${(.*)}" "\\1" v "${m}")
>>         STRING(REPLACE "\${${v}}" "${${v}}" INPUT "${INPUT}")
>>         STRING(REGEX MATCH "\\\${[^}]*}" m "${INPUT}")
>>     ENDWHILE()
>>     SET("${OUTPUT}" "${INPUT}" PARENT_SCOPE)
>> ENDFUNCTION()
>>
>> So, e.g., set(foo \${build-dir}/foo.c) and expand(foo ${foo})
>> with build-dir=/tmp/src yield foo=/tmp/src/foo.c as desired.
>>
>> Regards,
>>
>> Michael
>>
>>
>>>
>>> On Wed, Jun 2, 2010 at 3:06 PM, Michael Hertling<mhertling at online.de>
>>>  wrote:
>>>
>>>>
>>>> On 06/02/2010 08:37 PM, Doug Reiland wrote:
>>>>
>>>>>
>>>>> Sorry for another newbie question.
>>>>>
>>>>> Say, to setup a variable as follow so ${build-dir} doesn't get expanded
>>>>> set(foo \${build-dir}/foo.c)
>>>>>
>>>>> How would a expand foo so ${build-dir} gets expanded?
>>>>>
>>>>
>>>> STRING(REPLACE "\${build-dir}" "xyz" foo "${foo}")
>>>>
>>>> Regards,
>>>>
>>>> Michael
>>>>
>>
>> _______________________________________________
>> 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
>>
>
>
> --
> Ryan Pavlik
> Human-Computer Interaction Graduate Student
> Virtual Reality Applications Center
> Iowa State University
>
> rpavlik at iastate.edu
> http://academic.cleardefinition.com/
>
> _______________________________________________
> 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
>


More information about the CMake mailing list