<div dir="ltr"><div><div>Normally, you would want to keep your source tree clean from any build-time modifications (CMake *strongly discourages* in-source builds, with good reason).<br></div>Therefore, you'd want to generate the files in CMAKE_CURRENT_BINARY_DIR. Assuming the generator always writes them into its current directory, you'd do this:<br><br>set(EXIST_SOURCES A.cc B.cc C.cc)<br>
set(GEN_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/X.cc ${CMAKE_CURRENT_BINARY_DIR}/Y.cc ${CMAKE_CURRENT_BINARY_DIR}/Z.cc)<br>
add_custom_command(OUTPUT ${GEN_SOURCES}<br>
                       COMMAND generator<br></div>                       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}<div>
                       MAIN_DEPENDENCY gendir/generator)<br>add_library(mylib OBJECT ${EXIST_SOURCES} ${GEN_SOURCES} )<br><br></div><div>Petr<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 26, 2016 at 10:07 AM, Vania Joloboff <span dir="ltr"><<a href="mailto:vania.joloboff@inria.fr" target="_blank">vania.joloboff@inria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Petr,<br>
<br>
Thanks, indeed I had unset the property !<br>
Cmake works fine with removing the line. But I have now a doubt.<br>
My generator generates the files in the current dir.<br>
Should I indicate the working directory in add_custom_command ?<br>
so that the generated sources are added in CMAKE_CURRENT_SOURCE_DIR<br>
or it will automatically add them in the source dir and not the build dir ?<br>
Vania<span class=""><br>
<br>
<br>
<br>
On 01/26/2016 09:43 AM, Petr Kmoch wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
Hi, Vania.<br>
<br>
You should remove this line:<br>
<br>
set_property(SOURCE ${GEN_SOURCES} PROPERTY GENERATED )<br>
<br>
CMake will mark the files as generated automatically.<br>
<br>
What your line is actually doing is setting them as *not* generated, because you didn't pass any argument to set the property to, so it's implicitly unset. What you probably wanted would have been this:<br>
<br>
set_property(SOURCE ${GEN_SOURCES} PROPERTY GENERATED TRUE)<br>
<br>
But again, remove the line altogether, it's unnecessary.<br>
<br>
You should also remove the quotes from your `add_library` call. The way you have it would look for a single file named "A.cc;B.cc;C.cc X.cc;Y.cc;Z.cc".<br>
<br>
Petr<br>
<br></span><div><div class="h5">
On Tue, Jan 26, 2016 at 9:36 AM, Vania Joloboff <<a href="mailto:vania.joloboff@inria.fr" target="_blank">vania.joloboff@inria.fr</a> <mailto:<a href="mailto:vania.joloboff@inria.fr" target="_blank">vania.joloboff@inria.fr</a>>> wrote:<br>
<br>
    Hi<br>
<br>
    I have a generator that generates some, but not all of the source<br>
    files.<br>
    My understanding was that I should use add_custom_command for that<br>
<br>
    When I do<br>
    set(EXIST_SOURCES A.cc B.cc C.cc)<br>
    set(GEN_SOURCES X.cc Y.cc Z.cc)<br>
    add_custom_command(OUTPUT ${GEN_SOURCES}<br>
                           COMMAND generator<br>
                           MAIN_DEPENDENCY gendir/generator   )<br>
    set_property(SOURCE ${GEN_SOURCES} PROPERTY GENERATED )<br>
    add_library(mylib OBJECT "${EXIST_SOURCES} ${GEN_SOURCES}" )<br>
<br>
    I get error "Cannot find source file : X.cc"<br>
<br>
    So, I tried<br>
<br>
    set(EXIST_SOURCES A.cc B.cc C.cc)<br>
    set(GEN_SOURCES X.cc Y.cc Z.cc)<br>
    add_custom_target(generate<br>
                  COMMAND generator<br>
                  COMMENT "Generate"<br>
                  DEPENDS gendir/generator   )<br>
    set_property(SOURCE ${GEN_SOURCES} PROPERTY GENERATED )<br>
    add_library(mylib OBJECT "${EXIST_SOURCES} ${GEN_SOURCES}" )<br>
    add_dependencies(mylib generate)<br>
<br>
    I get same error "Cannot find source file : X.cc"<br>
<br>
    I just don't get it...<br>
<br>
    Vania<br>
<br>
    -- <br></div></div>
    Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a> <<a href="http://www.kitware.com" rel="noreferrer" target="_blank">http://www.kitware.com</a>><span class=""><br>
<br>
    Please keep messages on-topic and check the CMake FAQ at:<br>
    <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
    Kitware offers various services to support the CMake community.<br>
    For more information on each offering, please visit:<br>
<br>
    CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
    CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
    CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
    Visit other Kitware open-source projects at<br>
    <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
    Follow this link to subscribe/unsubscribe:<br>
    <a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
<br>
<br>
</span></blockquote>
<br>
</blockquote></div><br></div>