<br><div class="gmail_quote">2011/4/3 Michael Hertling <span dir="ltr">&lt;<a href="mailto:mhertling@online.de">mhertling@online.de</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div><div></div><div class="h5">On 04/01/2011 03:02 PM, Gaylord Charles wrote:<br>
&gt; Hello,<br>
&gt;<br>
&gt; I am migrating a project from Visual Studio 8 to CMake and I look for a way<br>
&gt; to exclude files from build for a defined configuration.<br>
&gt;<br>
&gt; I think the &quot;HEADER_FILE_ONLY&quot; source file property can suit my needs and it<br>
&gt; would be great to have a &quot;HEADER_FILE_ONLY_&lt;CONFIG&gt; version.<br>
&gt;<br>
&gt; But maybe there is a &quot;workaround&quot; that enables to get this kind of behavior.<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Gaylord CHARLES<br>
<br>
</div></div>AFAIK, you can not prevent the concerned files from being compiled, but<br>
you can prevent their object files from being incorporated in the final<br>
binaries. Admittedly, the method I could offer is somewhat weird:<br>
<br>
First of all, isolate the concerned files in a static library; linking<br>
against such a one is quite the same as incorporating the object files<br>
immediately. If desired, a shared library is alright, too. Further on,<br>
you need an intermediate empty static library as an imported target<br>
since imported targets can have arbitrary *configuration-specific*<br>
dependencies. Look at the following CMakeLists.txt:<br>
<br>
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)<br>
PROJECT(CONFIGEXCLUDE C)<br>
FILE(WRITE ${CMAKE_BINARY_DIR}/f.c &quot;void f(void){}\n&quot;)<br>
ADD_LIBRARY(f STATIC f.c)<br>
ADD_LIBRARY(helper STATIC &quot;&quot;)<br>
SET_TARGET_PROPERTIES(helper PROPERTIES LINKER_LANGUAGE &quot;C&quot;)<br>
EXPORT(TARGETS helper NAMESPACE &quot;reimp_&quot;<br>
    FILE ${CMAKE_BINARY_DIR}/helper.cmake)<br>
INCLUDE(${CMAKE_BINARY_DIR}/helper.cmake)<br>
SET_TARGET_PROPERTIES(reimp_helper PROPERTIES<br>
    IMPORTED_LINK_INTERFACE_LIBRARIES &quot;f&quot;<br>
    IMPORTED_LINK_INTERFACE_LIBRARIES_CUSTOM &quot;&quot;)<br>
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c &quot;int main(void){return 0;}\n&quot;)<br>
ADD_EXECUTABLE(main main.c)<br>
TARGET_LINK_LIBRARIES(main reimp_helper)<br>
ADD_DEPENDENCIES(main f helper)<br>
<br>
Target &quot;f&quot; comprises the files to exclude for a specific configuration.<br>
Target &quot;helper&quot; is the intermediate empty static library; it gets re-<br>
imported to the project to set its IMPORTED_LINK_INTERFACE_LIBRARIES<br>
property - to &quot;f&quot; generically and to &quot;&quot; for the &quot;CUSTOM&quot; configuration.<br>
Finally, target &quot;main&quot; is linked against the re-imported helper target.<br>
On *nix, I can see &quot;main&quot; being linked against libf.a unless the build<br>
type in CMAKE_BUILD_TYPE is set to &quot;custom&quot;, and I suppose it&#39;ll work<br>
in Visual Studio, too. Note that you need to establish the dependency<br>
of main on f and the helper explicitly by ADD_DEPENDENCIES() because<br>
TARGET_LINK_LIBARIES() can&#39;t do this anymore.<br>
<br>
&#39;hope that helps.<br>
<br>
Regards,<br>
<br>
Michael<br>
_______________________________________________<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>
</blockquote></div><br><br>Hello,<br><br>Ok, thank you very much for your help. <br><br>I tried your method today and it is quite good. I just had to make a little modification to your sample code because it did not work under Visual Studio. It seems that a library with no associated sources files is not supported.<br>

<br>So, I changed :<br><br>ADD_LIBRARY(helper STATIC &quot;&quot;)<br><br>into<br><br>FILE(WRITE ${CMAKE_BINARY_DIR}/empty.c &quot;&quot;)<br>ADD_LIBRARY(helper STATIC empty.c)<br><br><br>Thanks again,<br><br>Regards,<br>

Gaylord CHARLES<br><br><br><br>