[CMake] Delayed variable expansion?

David Cole david.cole at kitware.com
Wed Jul 20 17:28:09 EDT 2005


Ah... by "delayed" you mean expand a variable within a variable when the 
outer variable is dereferenced. Sorry - didn't get that from your first 
question. I don't think that's possible, but you could write a one line 
include script like this:

file named ProjReadMe.cmake located in CMAKE_SOURCE_DIR:
SET(PROJ_README "${PROJECT_SOURCE_DIR}/README.txt")

Then in both of your CMakeLists.txt files, include it after the PROJECT 
statement:
TOP/CMakeLists.txt:
PROJECT(TOP)
INCLUDE("${CMAKE_SOURCE_DIR}/ProjReadMe.cmake")

BOTTOM/CMakeLists.txt:
PROJECT(BOTTOM)
INCLUDE("${CMAKE_SOURCE_DIR}/ProjReadMe.cmake")

More like what you want?


David

Chris Green wrote:

> On Wed, 20 Jul 2005, David Cole wrote:
>
>> That'll work. You're missing the variable type from your set statement.
>> You have to give all three of "CACHE TYPE DOCSTRING" if you want to 
>> set a
>> cache variable.
>>
>> Use this instead and the rest should be ok:
>> SET ( PROJ_README "${PROJECT_SOURCE_DIR}/README.txt"
>> CACHE STRING "Where to find a project's README file"
>>   )
>
>
> Unfortunately this appears not to work:
>
> [greenc at leroy] /scratch1/greenc $ ls -lR TOP
> TOP:
> total 8
> drwxr-xr-x    2 greenc   e898         4096 Jul 20 15:51 BOTTOM
> -rw-r--r--    1 greenc   e898          145 Jul 20 15:49 CMakeLists.txt
>
> TOP/BOTTOM:
> total 4
> -rw-r--r--    1 greenc   e898           86 Jul 20 15:51 CMakeLists.txt
>
> [greenc at leroy] /scratch1/greenc $ cat TOP/CMakeLists.txt
> PROJECT ( TOP )
>
> SET ( PROJ_README "${PROJECT_SOURCE_DIR}/README.txt"
> CACHE STRING "Where to find a project's README file"
> )
>
> SUBDIRS ( BOTTOM )
>
> [greenc at leroy] /scratch1/greenc $ cat TOP/BOTTOM/CMakeLists.txt
> PROJECT ( BOTTOM )
> MESSAGE ( STATUS "Current value of PROJ_README = ${PROJ_README}" )
>
> [greenc at leroy] /scratch1/greenc $ mkdir b
> [greenc at leroy] /scratch1/greenc $ cd b
> [greenc at leroy] /scratch1/greenc/b $ cmake ../TOP
> -- Check for working C compiler: gcc
> -- Check for working C compiler: gcc -- works
> -- Check size of void *
> -- Check size of void * - done
> -- Check for working CXX compiler: c++
> -- Check for working CXX compiler: c++ -- works
> -- Current value of PROJ_README = /scratch1/greenc/TOP/README.txt
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /scratch1/greenc/b
>
> I would have liked to have seen:
>
> -- Current value of PROJ_README = /scratch1/greenc/TOP/BOTTOM/README.txt
>
> Help!
>
> Thanks,
> Chris.
>
>>
>>
>> David
>>
>> Chris Green wrote:
>>       Hi,
>>
>>       I'm pretty much expecting to be told, "Can't get there from
>>       here", but I'd like to set a variable in a top-level project
>>       in terms of another variable which may change. I'd then like
>>       to refer to that variable at a lower level and have it
>>       expanded at the time of evaluation.
>>
>>       For example:
>>
>>       PROJECT ( TOP )
>>       SET ( PROJ_README "${PROJECT_SOURCE_DIR}/README.txt"
>>       CACHE "Where to find a project's README file"
>>         )
>>       SUBDIRS ( BOTTOM )
>>
>>       Followed by:
>>
>>       PROJECT ( BOTTOM )
>>       MESSAGE ( STATUS "PROJ_README = ${PROJ_README}" )
>>
>>       Is this even possible?
>>
>>       Thanks,
>>       Chris.
>>
>>
>>
>


More information about the CMake mailing list