On Tue, May 17, 2011 at 1:30 PM, Michael Hertling <span dir="ltr">&lt;<a href="mailto:mhertling@online.de">mhertling@online.de</a>&gt;</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>
&gt; Hi all,<br>
&gt;<br>
&gt; I&#39;m wondering if there&#39;s a way to touch files on cached var changes. Let&#39;s say I have an option to enable or disable a feature<br>
&gt; in my application, and depending on its setting a preprocessor macro is defined (or not defined) in the CMakeLists.txt file:<br>
&gt;<br>
&gt; OPTION(FEATURE_X &quot;Check to enable feature X&quot; OFF)<br>
&gt;<br>
&gt; IF(FEATURE_X)<br>
&gt; ADD_DEFINITIONS(-DUSE_FEATURE_X=1)<br>
&gt; ELSE(FEATURE_X)<br>
&gt; ADD_DEFINITIONS(-DUSE_FEATURE_X=0)<br>
&gt; ENDIF(FEATURE_X)<br>
&gt;<br>
&gt; and in &quot;features.c&quot;:<br>
&gt;<br>
&gt; ...<br>
&gt; #if USE_FEATURE_X<br>
&gt; // Code for feature X<br>
&gt;<br>
&gt; #endif<br>
&gt; ...<br>
&gt;<br>
&gt; The source code file &quot;features.c&quot; that have code depending on the preprocessor macro needs to be recompiled each time the option changes, which does not automatically<br>
&gt; happen if the macro is defined like above (and I _really_ need to have it defined, either to zero or one...).<br>
&gt;<br>
&gt; So I pretty much need to hook a dependency of &quot;features.c&quot; to change of cached cmake options/vars...<br>
&gt;<br>
&gt; Ideas?<br>
&gt; TIA<br>
&gt; /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 &quot;Check to enable feature X&quot; 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&#39;s this latter file which is modified when the preprocessor<br>
definitions change, and the object file&#39;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&#39;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>