<div>I use cmake version 2.8.3.<br></div><div><br></div><div>If I use CMakeLists from your previous reply, it avoids overwriting files when X=0.</div><div>I have attached the output of your script. </div><div><br></div><div>
It works for my CMakeLists as well now. What I did now is </div><div><font color="#888888"><br></font></div><div><font color="#333333">if(${GrammarSource}/test.g IS_NEWER_THAN ${PROJECT_BINARY_DIR}/test.g)</font></div><div>
<font color="#333333">    ADD_CUSTOM_TARGET(...)</font><font color="#333333"><br></font></div><div><font color="#333333">    ADD_CUSTOM_COMMAND(...)</font><font color="#333333"><br></font></div><div><font color="#333333">   </font></div>
<div><font color="#333333">i.e I am totally avoiding the process of rebuilding the test.g file and copying the generated files to build/parser </font></div><div><font color="#333333"><strong>IF</strong> test.g has not been modified.<br>
</font></div><div><font color="#888888"><br>
</font><br> Thank you very much</div><div>Ajay</div><div><br></div><div><div>PS: Could you set up your e-mail client so that it marks quoted<br>
    text in some way? Currently, one can&#39;t distinguish between<br>
    the lines you are writing and the lines written by others.<br><br></div><div>Sorry. I did not realize that. I use gmail and when I checked my sent emails,</div><div>quoted text appears to be clearly marked. Is the quoted text in this email marked properly.</div>
</div><br><div class="gmail_quote">On Sun, Mar 4, 2012 at 4:05 PM, Michael Hertling <span dir="ltr">&lt;<a href="mailto:mhertling@online.de" target="_blank">mhertling@online.de</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On 03/04/2012 08:02 PM, Ajay Panyala wrote:<br>
&gt; The following project is a boiled-down version of yours but doesn&#39;t<br>
&gt; need any programs except for CMake - that&#39;s what I actually meant<br>
&gt; with &quot;minimal but complete&quot; as I don&#39;t have the org.antlr.Tool<br>
&gt; Java program:<br>
&gt;<br>
&gt; I am sorry. I was mainly trying to cleanup the big CMakeLists file<br>
&gt; I had and removed about 10 different targets - all of which were<br>
&gt; rebuilt because the 5 files (test*.*) were overwritten.<br>
&gt;<br>
&gt; If you want to try running the test project on your system<br>
&gt;<br>
&gt; test.g is at <a href="http://pastie.org/private/agzor3ibzoa5pom6q31qq" target="_blank">http://pastie.org/private/agzor3ibzoa5pom6q31qq</a><br>
&gt;<br>
&gt; org.antlr.Tool is at <a href="http://www.antlr.org/download/antlr-3.4-complete.jar" target="_blank">www.antlr.org/download/antlr-3.4-complete.jar</a><br>
&gt;<br>
&gt; After configuration, you can run the target by &quot;make X=0&quot; and check the<br>
&gt; timestamps by &quot;ls -l --full-time test.tokens parser src&quot;. Issuing &quot;make<br>
&gt; X=0&quot; again reveals that the copied files aren&#39;t rewritten as it happens<br>
&gt; after &quot;make X=1&quot;. Thus, AFAICS, everything works as expected. Could you<br>
&gt; check if the above-noted example also works on your system?<br>
&gt;<br>
&gt; It does not work. The files are still overwritten.<br>
<br>
</div>Could you run the following shell script in a build tree configured<br>
with the CMakeLists.txt from my previous reply and post the output?<br>
<br>
# check.sh:<br>
make X=0 2&gt;&amp;1 &gt; /dev/null<br>
echo &quot;After make X=0 (1):&quot;<br>
echo &quot;-------------------&quot;<br>
echo &quot;&quot;<br>
ls --full-time test.tokens src parser<br>
echo -ne &quot;\n\n&quot;<br>
sleep 3<br>
make X=0 2&gt;&amp;1 &gt; /dev/null<br>
echo &quot;After make X=0 (2):&quot;<br>
echo &quot;-------------------&quot;<br>
echo &quot;&quot;<br>
ls --full-time test.tokens src parser<br>
echo -ne &quot;\n\n&quot;<br>
sleep 3<br>
make X=1 2&gt;&amp;1 &gt; /dev/null<br>
echo &quot;After make X=1:&quot;<br>
echo &quot;---------------&quot;<br>
echo &quot;&quot;<br>
ls --full-time test.tokens src parser<br>
# End of check.sh<br>
<br>
BTW, which CMake version do you use?<br>
<br>
Regards,<br>
<font color="#888888"><br>
Michael<br>
</font><br>
PS: Could you set up your e-mail client so that it marks quoted<br>
    text in some way? Currently, one can&#39;t distinguish between<br>
    the lines you are writing and the lines written by others.<br>
<div><div><br>
&gt; What exactly does not work with your example? You wrote:<br>
&gt;<br>
&gt;&gt;&gt;&gt; I have 4 cmake -E copy_if_different commands, one for each file.<br>
&gt;&gt;&gt;&gt; Only the last file is not copied (if similar). [...]<br>
&gt;<br>
&gt; Does this mean that the last file out of four - in fact, your example<br>
&gt; handles five files - is not copied *although* the source file and the<br>
&gt; destination file are different, i.e. similar but not equal?<br>
&gt;<br>
&gt; Yes the file test.tokens is not copied overwritten since they are<br>
&gt; exactly (diff) similar files. This is the case with the other 4 files as<br>
&gt; well,<br>
&gt; but they are still copied over and rewritten.<br>
&gt;<br>
&gt;<br>
&gt; You wrote further:<br>
&gt;<br>
&gt;&gt;&gt;&gt; [...] The others are copied<br>
&gt;&gt;&gt;&gt; even if they are the same.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I verfied that they are the same with a diff.<br>
&gt;<br>
&gt; Does this mean that source files are copied *although* they are equal<br>
&gt; to their respective destination file? How do you determine that they<br>
&gt; have been copied? Do you check the timestamps? With --full-time?<br>
&gt;<br>
&gt; Yes, I do check with ls -l --full-time. Except test.tokens, all the other<br>
&gt; files<br>
&gt; are copied over (rewritten) even though they are exactly the same (diff<br>
&gt; same I mean).<br>
&gt;<br>
&gt; This is what is confusing me about the behavior of copy_if_different.<br>
&gt; that is why it works only with test.tokens and not others.<br>
&gt;<br>
&gt; PS: Does org.antlr.Tool write to the source tree? If so: Don&#39;t do that.<br>
&gt;<br>
&gt; Yes, it generates the files in the source dir itself (where test.g is<br>
&gt; present)<br>
&gt; I now modified CMakeLists to copy test.g to the project build folder and<br>
&gt; run it there. The new CMakeLists is at<br>
&gt;<br>
&gt; <a href="http://pastie.org/private/p1yi0l8so9cqimqlywfmhw" target="_blank">http://pastie.org/private/p1yi0l8so9cqimqlywfmhw</a><br>
&gt;<br>
&gt;<br>
&gt; Thank You<br>
&gt; Ajay<br>
&gt;<br>
&gt; On Sun, Mar 4, 2012 at 12:52 AM, Michael Hertling &lt;<a href="mailto:mhertling@online.de" target="_blank">mhertling@online.de</a>&gt;wrote:<br>
&gt;<br>
&gt;&gt; On 03/04/2012 01:06 AM, Ajay Panyala wrote:<br>
&gt;&gt;&gt; Please provide a minimal but complete example for this issue.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Please find it in the following link<br>
&gt;&gt;&gt; <a href="http://pastie.org/private/pd13u33s9xpfihf2dbzc1q" target="_blank">http://pastie.org/private/pd13u33s9xpfihf2dbzc1q</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;&gt; The following project is a boiled-down version of yours but doesn&#39;t<br>
&gt;&gt; need any programs except for CMake - that&#39;s what I actually meant<br>
&gt;&gt; with &quot;minimal but complete&quot; as I don&#39;t have the org.antlr.Tool<br>
&gt;&gt; Java program:<br>
&gt;&gt;<br>
&gt;&gt; CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)<br>
&gt;&gt; PROJECT(P NONE)<br>
&gt;&gt; SET(CMAKE_VERBOSE_MAKEFILE ON)<br>
&gt;&gt;<br>
&gt;&gt; SET(GrammarSource ${PROJECT_BINARY_DIR}/src)<br>
&gt;&gt; FILE(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/src)<br>
&gt;&gt;<br>
&gt;&gt; ADD_CUSTOM_TARGET(GrammarBuild ALL<br>
&gt;&gt;    COMMAND ${CMAKE_COMMAND} -E echo &quot;\${X}&quot;<br>
&gt;&gt;        &gt; ${GrammarSource}/testLexer.h<br>
&gt;&gt;    COMMAND ${CMAKE_COMMAND} -E echo &quot;\${X}&quot;<br>
&gt;&gt;        &gt; ${GrammarSource}/testLexer.c<br>
&gt;&gt;    COMMAND ${CMAKE_COMMAND} -E echo &quot;\${X}&quot;<br>
&gt;&gt;        &gt; ${GrammarSource}/testParser.h<br>
&gt;&gt;    COMMAND ${CMAKE_COMMAND} -E echo &quot;\${X}&quot;<br>
&gt;&gt;        &gt; ${GrammarSource}/testParser.c<br>
&gt;&gt;    COMMAND ${CMAKE_COMMAND} -E echo &quot;\${X}&quot;<br>
&gt;&gt;        &gt; ${PROJECT_BINARY_DIR}/test.tokens<br>
&gt;&gt; )<br>
&gt;&gt;<br>
&gt;&gt; ADD_CUSTOM_COMMAND(TARGET GrammarBuild POST_BUILD<br>
&gt;&gt;    COMMAND ${CMAKE_COMMAND} -E copy_if_different<br>
&gt;&gt;        ${GrammarSource}/testLexer.h<br>
&gt;&gt;        ${PROJECT_BINARY_DIR}/parser/testLexer.h<br>
&gt;&gt;    COMMAND ${CMAKE_COMMAND} -E copy_if_different<br>
&gt;&gt;        ${GrammarSource}/testLexer.c<br>
&gt;&gt;        ${PROJECT_BINARY_DIR}/parser/testLexer.c<br>
&gt;&gt;    COMMAND ${CMAKE_COMMAND} -E copy_if_different<br>
&gt;&gt;        ${GrammarSource}/testParser.h<br>
&gt;&gt;        ${PROJECT_BINARY_DIR}/parser/testParser.h<br>
&gt;&gt;    COMMAND ${CMAKE_COMMAND} -E copy_if_different<br>
&gt;&gt;        ${GrammarSource}/testParser.c<br>
&gt;&gt;        ${PROJECT_BINARY_DIR}/parser/testParser.c<br>
&gt;&gt;    COMMAND ${CMAKE_COMMAND} -E copy_if_different<br>
&gt;&gt;        ${PROJECT_BINARY_DIR}/test.tokens<br>
&gt;&gt;        ${PROJECT_BINARY_DIR}/parser/test.tokens<br>
&gt;&gt; )<br>
&gt;&gt;<br>
&gt;&gt; After configuration, you can run the target by &quot;make X=0&quot; and check the<br>
&gt;&gt; timestamps by &quot;ls -l --full-time test.tokens parser src&quot;. Issuing &quot;make<br>
&gt;&gt; X=0&quot; again reveals that the copied files aren&#39;t rewritten as it happens<br>
&gt;&gt; after &quot;make X=1&quot;. Thus, AFAICS, everything works as expected. Could you<br>
&gt;&gt; check if the above-noted example also works on your system?<br>
&gt;&gt;<br>
&gt;&gt; What exactly does not work with your example? You wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; I have 4 cmake -E copy_if_different commands, one for each file.<br>
&gt;&gt;&gt;&gt;&gt; Only the last file is not copied (if similar). [...]<br>
&gt;&gt;<br>
&gt;&gt; Does this mean that the last file out of four - in fact, your example<br>
&gt;&gt; handles five files - is not copied *although* the source file and the<br>
&gt;&gt; destination file are different, i.e. similar but not equal?<br>
&gt;&gt;<br>
&gt;&gt; You wrote further:<br>
&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; [...] The others are copied<br>
&gt;&gt;&gt;&gt;&gt; even if they are the same.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; I verfied that they are the same with a diff.<br>
&gt;&gt;<br>
&gt;&gt; Does this mean that source files are copied *although* they are equal<br>
&gt;&gt; to their respective destination file? How do you determine that they<br>
&gt;&gt; have been copied? Do you check the timestamps? With --full-time?<br>
&gt;&gt;<br>
&gt;&gt; Regards,<br>
&gt;&gt;<br>
&gt;&gt; Michael<br>
&gt;&gt;<br>
&gt;&gt; PS: Does org.antlr.Tool write to the source tree? If so: Don&#39;t do that.<br>
&gt;&gt;<br>
&gt;&gt;&gt; On Sat, Mar 3, 2012 at 3:54 PM, Michael Hertling &lt;<a href="mailto:mhertling@online.de" target="_blank">mhertling@online.de</a><br>
&gt;&gt;&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; On 03/04/2012 12:14 AM, Ajay Panyala wrote:<br>
&gt;&gt;&gt;&gt;&gt; No, it wouldn&#39;t; check it out:<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; % touch a<br>
&gt;&gt;&gt;&gt;&gt; % rm -f b<br>
&gt;&gt;&gt;&gt;&gt; % ls b<br>
&gt;&gt;&gt;&gt;&gt; ls: cannot access b: No such file or directory<br>
&gt;&gt;&gt;&gt;&gt; % cmake -E copy_if_different a b<br>
&gt;&gt;&gt;&gt;&gt; % ls b<br>
&gt;&gt;&gt;&gt;&gt; b<br>
&gt;&gt;&gt;&gt;&gt; % cksum a b<br>
&gt;&gt;&gt;&gt;&gt; 4294967295 0 a<br>
&gt;&gt;&gt;&gt;&gt; 4294967295 0 b<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; It works with one file, but I have 4 files that are generated.<br>
&gt;&gt;&gt;&gt;&gt; I have 4 cmake -E copy_if_different commands, one for each file.<br>
&gt;&gt;&gt;&gt;&gt; Only the last file is not copied (if similar). The others are copied<br>
&gt;&gt;&gt;&gt;&gt; even if they are the same.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; I verfied that they are the same with a diff.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; Any idea what might be happening here ?<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Please provide a minimal but complete example for this issue.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Regards,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Michael<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; On Sat, Mar 3, 2012 at 2:47 PM, Michael Hertling &lt;<a href="mailto:mhertling@online.de" target="_blank">mhertling@online.de</a><br>
&gt;&gt;&gt;&gt;&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; On 03/03/2012 10:36 PM, Ajay Panyala wrote:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Try &quot;cmake -E copy_if_different ...&quot;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; cmake -E copy_if_different build/test1.c build/tests/test1.c<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; That would work when make is run atleast once.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; When running make for the 1st time test1.c was never<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; copied to build/tests before. So I would be comparing a file with<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; another non-existant file and that would result in an error halting<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; the make process.<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; No, it wouldn&#39;t; check it out:<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; % touch a<br>
&gt;&gt;&gt;&gt;&gt;&gt; % rm -f b<br>
&gt;&gt;&gt;&gt;&gt;&gt; % ls b<br>
&gt;&gt;&gt;&gt;&gt;&gt; ls: cannot access b: No such file or directory<br>
&gt;&gt;&gt;&gt;&gt;&gt; % cmake -E copy_if_different a b<br>
&gt;&gt;&gt;&gt;&gt;&gt; % ls b<br>
&gt;&gt;&gt;&gt;&gt;&gt; b<br>
&gt;&gt;&gt;&gt;&gt;&gt; % cksum a b<br>
&gt;&gt;&gt;&gt;&gt;&gt; 4294967295 0 a<br>
&gt;&gt;&gt;&gt;&gt;&gt; 4294967295 0 b<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; Regards,<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; Michael<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; On Sat, Mar 3, 2012 at 1:20 PM, Hendrik Sattler &lt;<br>
&gt;&gt;&gt;&gt; <a href="mailto:post@hendrik-sattler.de" target="_blank">post@hendrik-sattler.de</a><br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Am Samstag, 3. März 2012, 21:41:49 schrieb Ajay Panyala:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I have a custom target which runs a command to generate<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; a C source file say test1.c<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ADD_CUSTOM_TARGET(TestGen ALL<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; COMMAND genExec ${PROJECT_SOURCE_DIR}/Main.java<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; DEPENDS ${PROJECT_SOURCE_DIR}/Main.java<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; )<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; And I have a custom command that moves the generated *test1.c *<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to a new directory inside the build directory.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ADD_CUSTOM_COMMAND(<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; TARGET TestGen<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; POST_BUILD<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; COMMAND mv<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ARGS ${PROJECT_BINARY_DIR}/test1.c ${PROJECT_BINARY_DIR}/tests/<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; )<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Each time I run make, the custom target is run (since custom<br>
&gt;&gt; targets<br>
&gt;&gt;&gt;&gt;&gt;&gt; are<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; always<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; out-of-date). But I want to avoid moving the new test1.c generated<br>
&gt;&gt;&gt;&gt; each<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; time if build/test1.c is the same as build/tests/test1.c since<br>
&gt;&gt; there<br>
&gt;&gt;&gt;&gt;&gt;&gt; are<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; other targets<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; like add_executable and add_library later in the CMakelists file<br>
&gt;&gt; that<br>
&gt;&gt;&gt;&gt;&gt;&gt; are<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;  re-built<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; each time since they depend on test1.c<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Try &quot;cmake -E copy_if_different ...&quot;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; HS<br>
--<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><br clear="all"><br><br>