[CMake] Delayed variable expansion?

Chris Green chissg at comcast.net
Wed Jul 20 16:54:30 EDT 2005


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

-- 
Chris Green, MiniBooNE / LANL. Email greenc at fnal.gov
Tel: (630) 840-2167. Fax: (630) 840-3867


More information about the CMake mailing list