[CMake] How to set up user option defaults that depend on other user option defaults?

Alan W. Irwin irwin at beluga.phys.uvic.ca
Mon Nov 6 20:52:50 EST 2006


With the PLplot CMake build system I am trying to set up refined
installation directories for our users that are similar to what they have
previously used with the autotools configure script.

Here is a subset of the CMake logic which illustrates the problem:

set(
CMAKE_INSTALL_EXEC_PREFIX 
${CMAKE_INSTALL_PREFIX}
CACHE PATH "install location for architecture-dependent files"
)

set(
CMAKE_INSTALL_BINDIR
${CMAKE_INSTALL_EXEC_PREFIX}/bin
CACHE PATH "install location for user executables"
)
[...]

My idea was to mimic the autotools configure script where if you specify
prefix it overrides exec-prefix unless that is specified by the user.
Similarly, if you specify exec-prefix (or if it is overridden by prefix) it
forces bindir to be exec-prefix/bin unless bindir is specified by the user.

However, the above implementation does not work properly because of caching;
once CMAKE_INSTALL_BINDIR is in the cache it is completely unaffected by
subsequent changes to CMAKE_INSTALL_EXEC_PREFIX (or CMAKE_INSTALL_PREFIX).
This is extremely inconvenient for the typical user who usually just want to
change the prefix and doesn't want to change ~10 different install
directories that are already cached.  OTOH, fine-tune install directories
must also be available so that invidual values (e.g., CMAKE_INSTALL_BINDIR)
can be specified if so desired.

What I need to do is to set up a user option whose default value depends on
other user options.  Does anybody know how to do that?

I think something similar to the logic in macro VTK_DEPENDENT_OPTION
(mentioned before on list and located at
http://www.vtk.org/cgi-bin/viewcvs.cgi/CMake/vtkDependentOption.cmake?rev=1.5&view=markup)
might work, but I am having some trouble understanding that macro.  Does a
version of that macro exist without the MATCHES hacks that have always
confused me?  For example, I thought those hacks could be replaced by NOT
EXISTS logic, but then that macro seems to

SET(${option} "${${option}_ISSET}")

if that latter variable exists, but that latter variable is never set within
the macro or documented so it seems like an accident waiting to happen to me
when some unsuspecting user sets that variable by accident, but I may be
misunderstanding what is going on.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list