On Tue, May 17, 2011 at 1:30 PM, Michael Hertling <span dir="ltr"><<a href="mailto:mhertling@online.de">mhertling@online.de</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On 05/17/2011 05:45 PM, Robert Bielik wrote:<br>
> Hi all,<br>
><br>
> 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<br>
> in my application, and depending on its setting a preprocessor macro is defined (or not defined) in the CMakeLists.txt file:<br>
><br>
> OPTION(FEATURE_X "Check to enable feature X" OFF)<br>
><br>
> IF(FEATURE_X)<br>
> ADD_DEFINITIONS(-DUSE_FEATURE_X=1)<br>
> ELSE(FEATURE_X)<br>
> ADD_DEFINITIONS(-DUSE_FEATURE_X=0)<br>
> ENDIF(FEATURE_X)<br>
><br>
> and in "features.c":<br>
><br>
> ...<br>
> #if USE_FEATURE_X<br>
> // Code for feature X<br>
><br>
> #endif<br>
> ...<br>
><br>
> 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<br>
> happen if the macro is defined like above (and I _really_ need to have it defined, either to zero or one...).<br>
><br>
> So I pretty much need to hook a dependency of "features.c" to change of cached cmake options/vars...<br>
><br>
> Ideas?<br>
> TIA<br>
> /Rob<br>
<br>
</div>AFAICS, with 2.8.4, the concerned files *are* recompiled:<br>
<br>
# CMakeLists.txt:<br>
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.4 FATAL_ERROR)<br>
PROJECT(RECOMPILE C)<br>
SET(CMAKE_VERBOSE_MAKEFILE ON)<br>
<div class="im">OPTION(FEATURE_X "Check to enable feature X" OFF)<br>
IF(FEATURE_X)<br>
ADD_DEFINITIONS(-DUSE_FEATURE_X=1)<br>
ELSE(FEATURE_X)<br>
ADD_DEFINITIONS(-DUSE_FEATURE_X=0)<br>
ENDIF(FEATURE_X)<br>
</div>ADD_EXECUTABLE(main main.c)<br>
<br>
/* main.c: */<br>
int main(void){return 0;}<br>
<br>
After reconfiguring the project with an altered FEATURE_X value,<br>
you will see main.c being recompiled. This is due to the line<br>
<br>
CMakeFiles/main.dir/main.c.o: CMakeFiles/main.dir/flags.make<br>
<br>
in ${CMAKE_BINARY_DIR}/CMakeFiles/main.dir/build.make with the<br>
${CMAKE_BINARY_DIR}/CMakeFiles/main.dir/flags.make containing:<br>
<br>
C_DEFINES = -DUSE_FEATURE_X=...<br>
<br>
It's this latter file which is modified when the preprocessor<br>
definitions change, and the object file's dependency provides<br>
for the recompilation. Can you confirm that?<br>
<br>
Regards,<br>
<font color="#888888"><br>
Michael<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</div></div></blockquote></div><br><br>That works with makefile generators, but we trust Visual Studio and Xcode to do their own dependency analysis, and with those generators, I don't think that the main.c will be recompiled after changing the FEATURE_X value in CMake...<br>
<br>However, if you use a configured header file, then it will.<br><br>HTH,<br>David<br><br>