<div>I need the files to be copied at build time, not a compile time: They are files I am editing and I need the build system to export the files to the binary directory tree whenever they are changed.</div><div><br></div>
I know it looks stupid and probably is as well :-) The reason is that when the project is being used by clients, I want them to include each file as follows (something which I use myself):<div><br></div><div>#include "Braceless/Frontend/Scanner.hpp"</div>
<div><br></div><div>And the only way I could figure out to get it working was by naming the build directory "Braceless" and then do that thing I'm doing. The project is organized like this:</div><div><br></div>
<div> src/AST</div><div> src/Driver</div><div> src/Frontend</div><div> ...</div><div><br></div><div>And I want to be able to write "Braceless" in front so that it works also when the header files and libraries have been installed on a system. In the LLVM system, they solve this problem by storing the headers in another location than the source files - something I deeply loathe as it makes it very difficult to search for strings and even to edit a given source file and its header at the same time.</div>
<div><br></div><div>I'll try out your comments, but I don't see any way of getting rid of that ../.. construct. By the way, I am a CMake newbie so I just did what I could do to make it work somehow.</div><div><br>
</div><div><br></div><div>Cheers,</div><div>Mikael<br><br><div class="gmail_quote">2012/6/27 Rolf Eike Beer <span dir="ltr"><<a href="mailto:eike@sf-mail.de" target="_blank">eike@sf-mail.de</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">> Sigh, now I sent you the code from the wrong directory, but the code for<br>
> the "Backend" component is virtually identical. I don't know how to use<br>
> functions with CMake, so I simply made a verbatim copy of the below code<br>
> in<br>
> each subfolder and edited it to match the subfolder. So the Backend<br>
> project looks like this:<br>
><br>
> project(Backend)<br>
><br>
> set(PublicHeaders<br>
> "Backend.hpp"<br>
> "Context.hpp"<br>
> )<br>
> set(PublishedHeaders "")<br>
> foreach(Header IN LISTS PublicHeaders)<br>
> get_filename_component(HeaderFilename "${Header}" NAME)<br>
> set(Source "${CMAKE_CURRENT_SOURCE_DIR}/${Header}")<br>
> set(Output "${CMAKE_CURRENT_BINARY_DIR}/${HeaderFilename}")<br>
> list(APPEND PublishedHeaders "${Output}")<br>
> add_custom_command(<br>
> OUTPUT "${Output}"<br>
> COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${Source}"<br>
> "${Output}"<br>
> MAIN_DEPENDENCY "${Source}"<br>
> COMMENT "Publishing ${HeaderFilename}"<br>
> VERBATIM<br>
> )<br>
<br>
</div></div>Why don't you simply use configure_file(... COPYONLY) here?<br>
<div class="im"><br>
> endforeach()<br>
> add_custom_target(<br>
> publish_backend_headers<br>
> ALL<br>
> DEPENDS ${PublishedHeaders}<br>
> SOURCES ${PublicHeaders}<br>
> )<br>
> include_directories("${CMAKE_BINARY_DIR}/../")<br>
<br>
</div>This is almost certainly wrong. Guess my build dir is /tmp/foo, why on<br>
earth do you want to include /tmp? I could understand if it would be<br>
${CMAKE_CURRENT_BINARY_DIR}/.. if you are in a subdirectory, but otherwise<br>
this is likely completely bogus.<br>
<div class="im"><br>
> include_directories("$ENV{LLVM}/include")<br>
><br>
> add_definitions(-D__STDC_CONSTANT_MACROS)<br>
> add_definitions(-D__STDC_LIMIT_MACROS)<br>
><br>
> add_library(Backend<br>
> "Backend.cpp"<br>
> )<br>
><br>
> add_dependencies(Backend publish_backend_headers)<br>
<br>
</div>I think you can avoid the whole add_custom_target/add_library by just writing<br>
<br>
add_library(Backend Backend.cpp ${PublishedHeaders})<br>
<br>
(Untested. May only reliably work if you use configure_file. ymmv).<br>
<span class="HOEnZb"><font color="#888888"><br>
Eike<br>
</font></span><div class="HOEnZb"><div class="h5">--<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>
</div></div></blockquote></div><br>
</div>