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