[CMake] is ccmake reliable?

Tyler Roscoe tyler at cryptio.net
Tue Sep 15 16:47:06 EDT 2009


On Tue, Sep 15, 2009 at 02:20:35PM -0600, James C. Sutherland wrote:
> >>>set( CMAKE_INSTALL_PREFIX
> >>>${CMAKE_CURRENT_BINARY_DIR}
> >>>CACHE PATH "installation path"
> >>>)
> >>This doesn't work - I assume that this is because  
> >>CMAKE_INSTALL_PREFIX
> >>is a special (internally defined) variable?  When I run ccmake and
> >>configure, the value remains as /usr/local.
> >
> >This will work when generating a new cache. If you have a pre-existing
> >cache, CMake won't override the value in there (otherwise how could a
> >user ever provide her own values for cache variables).
> >
> After wiping my cache (and the entire build directory) clean, I ran  
> ccmake (configure) and the CMAKE_INSTALL_PREFIX was set to /usr/ 
> local.  The only way I can get it to modify the CMAKE_INSTALL_PREFIX  
> by default (i.e. through the CMakeLists.txt file) is by removing the  
> CACHE PATH portion.  But then it isn't cached (obviously).

Yeah, duh, sorry. The problem is that CMake does something like the
above by default, so your later set(... CACHE ...) has no effect because
a value is already set in the cache.

Looks like the default for CMAKE_INSTALL_PREFIX comes from
CMakeGenericSystem.cmake:


# Set a variable to indicate whether the value of CMAKE_INSTALL_PREFIX
# was initialized by the block below.  This is useful for user
# projects to change the default prefix while still allowing the
# command line to override it.
IF(NOT DEFINED CMAKE_INSTALL_PREFIX)
  SET(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT 1)
ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)

IF(CMAKE_HOST_UNIX)
  SET(CMAKE_INSTALL_PREFIX "/usr/local"
    CACHE PATH "Install path prefix, prepended onto install directories.")
ELSE(CMAKE_HOST_UNIX)
[...]


The comment above the first stanza is interesting. I guess its intended
use is for something like this:

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    set (CMAKE_INSTALL_PREFIX "myPrefix" CACHE FORCE ...)
endif ()


Maybe a more seasoned CMaker can verify if this is the Right Way to do
what you want.

hth,
tyler


More information about the CMake mailing list