I do this by making a .in file that gets configured that contains the value of the CMake variable.
header.h.in: =========== #define FEATURE_X @FEATURE_X@ CMakeLists.txt: =========== configure_file(${CMAKE_CURRENT_SOURCE_DIR}/header.h.in ${CMAKE_CURRENT_BINARY_DIR}/header.h @ONLY) include_directories(${CMAKE_CURRENT_BINARY_DIR}) features.c: =========== #include "header.h" Now, when FEATURE_X changes in cmake, header.h changes, which triggers a re-compile of any files that include it. HTH, David On Tue, May 17, 2011 at 11:45 AM, Robert Bielik <robert.bie...@xponaut.se>wrote: > 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 > _______________________________________________ > Powered by www.kitware.com > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Follow this link to subscribe/unsubscribe: > http://www.cmake.org/mailman/listinfo/cmake >
_______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake