[CMake] Newbie question about CMake cache

Joachim Ziegler ziegler at mpi-sb.mpg.de
Fri Oct 31 05:49:38 EDT 2008


Hello list,

am I correct in the following use of the CMake cache:

Suppose that in your source code, a preprocessor macro

#if defined(USE_MEMSET)
...
#elif defined(USE_BZERO)
...
#endif

decides on whether you want to use the function memset() or bzero() to
set the first n bytes of a byte area to zero. When you invoke CMake for
the first time, you do it like this in your build tree;

$ cmake -DMEMSET:string=USE_MEMSET /path/to/source/tree

This defines a variable MEMSET in the CMake cache, with a default value
of USE_MEMSET. You can alter the value of this variable in the cache by
calling ccmake . or cmake edit_cache.

In your CMakeLists.txt, you have a section

IF(MEMSET STREQUAL USE_MEMSET)
ADD_DEFINITIONS(-DUSE_MEMSET)
ELSE(MEMSET STREQUAL USE_BZERO)
ADD_DEFINITIONS(-DUSE_BZERO)
ENDIF(MEMSET STREQUAL USE_MEMSET)

that passes on the correct macro value to the preprocessor.

Or is there an easier way to do this, to pass on macro values to the
compiler, with different values in different compiler runs?

BTW, is there a *searchable* archive of the mailing list archived at
http://www.cmake.org/pipermail/cmake/
?

Greetings,
joachim


More information about the CMake mailing list