[CMake] How to get around a CACHE problem?

Eric Noulard eric.noulard at gmail.com
Mon Aug 6 02:17:02 EDT 2007


2007/8/5, Christian Convey <christian.convey at gmail.com>:
[...]

summary:
   SET (... CACHE ...) not set after a FATAL_ERROR.

>
> My work-around for now is to do it like this:
>
> SET( LIBRARY_OUTPUT_PATH ${MOOSBIN} CACHE PATH
>      "Output directory for the MOOS libraries" )
>
> IF("${LIBRARY_OUTPUT_PATH}" STREQUAL "")
>    SET( LIBRARY_OUTPUT_PATH ${MOOSBIN} CACHE PATH
>         "Output directory for the MOOS libraries"
>       FORCE)  <-- Note the FORCE directive
> ENDIF("${LIBRARY_OUTPUT_PATH}" STREQUAL "")
>
[...]

I think you did find the only workaround I know, including the drawback
of the user provided value matching the default empty string.

I think a discussion regarding "guessed" or "CACHED" VAR values
override did already occurs on the list may be you can dig the
archive to look for the discussion.
We should have a mean to test if a VAR value comes from CACHE,
or USER (be it GUI, or COMMAND LINE (-Dxxxx))  something like

IF (CACHED VAR)

IF (PROVIDED VAR)

such that ones may try

IF (DEFINED VAR AND PROVIDED VAR)
    SET(...)
ENDIF

note that CACHED and PROVIDED may not be mutually exclusive.
CACHED VAR  AND PROVIDED VAR would means that the
value was provided by user in a previous [c]cmake run an put in CACHE.

If I summarize I think a VAR may be tested with

IF (DEFINED VAR)  --> if true VAR is defined with a value
IF (CACHED VAR)   --> if true VAR value comes from CACHE
IF (PROVIDED VAR) --> if true the VAR value was provided by user
                                    either using GUI or command line -D
IF (GUESSED VAR) --> if true the VAR value comes from a DEFAULT
                                   guessed or built-in value

We may have GUESSED AND CACHED or PROVIDED AND CACHED.
(Which means the cache file should contains the GUESSED/PROVIDED state)

The default "state" of a VAR upon SET would be "PROVIDED"
but the CMake macro writer may want to SET value as a GUESSED.

SET(VAR [VALUE] [CACHE TYPE DOCSTRING [FORCE]] [GUESSED])

Do you think this proposition deserve a feature request?

However in your particular case I think CMake should not use
the cache AT ALL after a FATAL ERROR by either throwing it away
or mark it as unusable.

-- 
Erk


More information about the CMake mailing list