[CMake] --enable-* with cmake

Alexander Neundorf a.neundorf-work at gmx.net
Wed Aug 8 10:32:27 EDT 2007


On Wednesday 08 August 2007 10:19, Philip Lowman wrote:
> Eric Noulard wrote:
> > 2007/8/8, gga <ggarra at advancedsl.com.ar>:
> >> I'm currently using cmake for a variety of projects.  Love it.
> >> However, one feature I find myself missing more and more is one from
> >> autotools configure scripts: AC_ARG_ENABLE().
> >> That is, the ability to allow the configuration script (ie. cmake) to be
> >> run with arbitrary flags to turn on or turn off some options
> >> (--enable-X11 for example), regardless of what it finds on the standard
> >> paths.  Also this option in autoconf allows too have those options
> >> available to the user thru a simple help line.
> >>
> >> I know I can pass -D symbols to cmake to modify its behavior and that
> >
> > What do you think very different between
> >
> > configure --enable-X11
> > cmake -DENABLE_X11
>
> In defense of the original post,
>
> --enable-foo is much more readable than -DENABLE_FOO or -DUSE_FOO.
> Having implemented USE_FOO arguments for every single one of our
> optional dependencies and looked at them on a CMake command line I can
> attest to this. :)

Having a way to translate these long arguments into shorter arguments would be 
nice.
The first step to do this is to use the command line argument handler you can 
find in CMake/Source/kwsys/ in CMake. Once that is done, some kind of mapping 
could be added.

...
> Almost.  Automake has a neat feature the original poster pointed out
> that uses arguments to AC_ARG_ENABLE to output documentation when you
> call "./configure --help".  CMake doesn't have an equivalent feature I
> know of for this but I think the closest would be a visual inspection of
> the variables in "ccmake" or "CMakeSetup.exe".

For KDE I did the following macro, so you have a switch WITH_<package> name to 
enable/disable a feature:

MACRO (MACRO_OPTIONAL_FIND_PACKAGE _name )
   OPTION(WITH_${_name} "Search for ${_name} package" ON)
   if (WITH_${_name})
      FIND_PACKAGE(${_name} ${ARGN})
   else (WITH_${_name})
      set(${_name}_FOUND)
      set(${_name}_INCLUDE_DIR)
      set(${_name}_INCLUDES)
      set(${_name}_LIBRARY)
      set(${_name}_LIBRARIES)
   endif (WITH_${_name})
ENDMACRO (MACRO_OPTIONAL_FIND_PACKAGE)

Bye
Alex


More information about the CMake mailing list