<br><div class="gmail_quote">2011/4/3 Michael Hertling <span dir="ltr"><<a href="mailto:mhertling@online.de">mhertling@online.de</a>></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>
> Hello,<br>
><br>
> I am migrating a project from Visual Studio 8 to CMake and I look for a way<br>
> to exclude files from build for a defined configuration.<br>
><br>
> I think the "HEADER_FILE_ONLY" source file property can suit my needs and it<br>
> would be great to have a "HEADER_FILE_ONLY_<CONFIG> version.<br>
><br>
> But maybe there is a "workaround" that enables to get this kind of behavior.<br>
><br>
> Thanks,<br>
> 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 "void f(void){}\n")<br>
ADD_LIBRARY(f STATIC f.c)<br>
ADD_LIBRARY(helper STATIC "")<br>
SET_TARGET_PROPERTIES(helper PROPERTIES LINKER_LANGUAGE "C")<br>
EXPORT(TARGETS helper NAMESPACE "reimp_"<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 "f"<br>
IMPORTED_LINK_INTERFACE_LIBRARIES_CUSTOM "")<br>
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "int main(void){return 0;}\n")<br>
ADD_EXECUTABLE(main main.c)<br>
TARGET_LINK_LIBRARIES(main reimp_helper)<br>
ADD_DEPENDENCIES(main f helper)<br>
<br>
Target "f" comprises the files to exclude for a specific configuration.<br>
Target "helper" is the intermediate empty static library; it gets re-<br>
imported to the project to set its IMPORTED_LINK_INTERFACE_LIBRARIES<br>
property - to "f" generically and to "" for the "CUSTOM" configuration.<br>
Finally, target "main" is linked against the re-imported helper target.<br>
On *nix, I can see "main" being linked against libf.a unless the build<br>
type in CMAKE_BUILD_TYPE is set to "custom", and I suppose it'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't do this anymore.<br>
<br>
'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 "")<br><br>into<br><br>FILE(WRITE ${CMAKE_BINARY_DIR}/empty.c "")<br>ADD_LIBRARY(helper STATIC empty.c)<br><br><br>Thanks again,<br><br>Regards,<br>
Gaylord CHARLES<br><br><br><br>