[Cmake] Resetting a variable

Bill Hoffman bill.hoffman at kitware.com
Thu May 1 10:12:37 EDT 2003


We have discussed this quite a bit, and what you are talking about,
is a SET(var value FORCE_IF_NOT_USER_EDITED).    However, I don't
think that feature would be all the useful.   


A better approach for this problem with opengl on the Mac would be this:


IF(MAC_USE_X)
  # create a cache value for the X opengl, users can set this one
  SET(MAC_OPEN_GL_X openglx CACHE)
  # set the real open gl to the X value with a force
  # users will no longer be able to change this value
  SET(REAL_OPEN_GL ${MAC_OPEN_GL_X} CACHE INTERNAL FORCE)
ENDIF(MAC_USE_X)

# repeat the same for the native
IF(MAC_USE_NATIVE)
  SET(MAC_OPEN_GL_NATIVE openglnative CACHE)
  SET(REAL_OPEN_GL ${MAC_OPEN_GL_NATIVE} CACHE FORCE)
ENDIF(MAC_USE_NATIVE)


This means that when the user switches from native to X, the
REAL_OPEN_GL value is forced to the correct version.   
The user can edit the X or native versions of the variable if
cmake can not find them.   And this is still compatible with
the rest of the cmakelist files in the system because they
are expecting the REAL_OPEN_GL to be set.

-Bill

At 09:09 AM 5/1/2003, John Biddiscombe wrote:

>> You can change a cache value with a SET(var value FORCE).   However,
>> this is a dangerous feature.   The problem is that cache variables
>> can be set by the user.    If a cmakelist file changes the value set
>> by a user, it can no longer be set by the user.
>
>This has annoyed me many times...how does one change a default value to a different default (without editing the Cmake Modules). If you FORCE it, then it keeps getting reset every time the user changes it. If you don't, then you haven't changed the default, 
>
>you need to set a flag for the first time you run and change the default using FORCE, then clear the flag (anmd CACHE it) and afterwards stop FORCEing. it's grotesque...
>
>how about some kind of SET (variable FORCEONCE) ! is there an easy way of doing it (especially if you need to change lots of variables)
>
>JB






More information about the CMake mailing list