[CMake] Touching files on cache var changes

Robert Bielik robert.bielik at xponaut.se
Tue May 17 11:45:58 EDT 2011


Hi all,

I'm wondering if there's a way to touch files on cached var changes. Let's say I have an option to enable or disable a feature
in my application, and depending on its setting a preprocessor macro is defined (or not defined) in the CMakeLists.txt file:

OPTION(FEATURE_X "Check to enable feature X" OFF)

IF(FEATURE_X)
ADD_DEFINITIONS(-DUSE_FEATURE_X=1)
ELSE(FEATURE_X)
ADD_DEFINITIONS(-DUSE_FEATURE_X=0)
ENDIF(FEATURE_X)

and in "features.c":

...
#if USE_FEATURE_X
// Code for feature X

#endif
...

The source code file "features.c" that have code depending on the preprocessor macro needs to be recompiled each time the option changes, which does not automatically
happen if the macro is defined like above (and I _really_ need to have it defined, either to zero or one...).

So I pretty much need to hook a dependency of "features.c" to change of cached cmake options/vars...

Ideas?
TIA
/Rob


More information about the CMake mailing list