<div>Yes, the CMAKE_CURRENT_BINARY_DIR is the same as PROJECT_BINARY_DIR.<br></div><div>It works for me now. The depends file (test.java) is actually copied over to the build directory</div><div>before compiling it (the copy command was not shown in the previous email).</div>
<div><br></div><div>I changed </div><div><br></div><div>DEPENDS ${PROJECT_BINARY_DIR}/test.java</div><div><br></div><div>to</div><div><br></div><div>DEPENDS ${PROJECT_SOURCE_DIR}/test.java</div><div><br></div><div>And it works as expected - that is recompiles test.java only if it was modified.</div>
<div><br></div><div>Thanks</div><div>Ajay</div><br><div class="gmail_quote">On Tue, Mar 6, 2012 at 11:44 AM, David Cole <span dir="ltr"><<a href="mailto:david.cole@kitware.com">david.cole@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">On Tue, Mar 6, 2012 at 1:22 PM, Ajay Panyala <<a href="mailto:ajay@csc.lsu.edu">ajay@csc.lsu.edu</a>> wrote:<br>
> add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test.class<br>
> COMMAND ${JAVAC_COMPILER} -d ${PROJECT_BINARY_DIR}<br>
> ${PROJECT_BINARY_DIR}/test.java<br>
> DEPENDS ${PROJECT_BINARY_DIR}/test.java<br>
> COMMENT "Compiling test.java"<br>
> VERBATIM)<br>
><br>
> add_custom_target(compile-test-java<br>
> DEPENDS ${PROJECT_BINARY_DIR}/test.class)<br>
><br>
> I tried this. It builds as expected initially. But when I change test.java<br>
> and run<br>
> make, it is not re-compiled.<br>
><br>
> It looks like test.java is a generated file, so depending on how you<br>
> generate it, you also need to set the GENERATED source file property to<br>
> TRUE in order for this to work.<br>
><br>
> test.java is not a generated file. I am modifying it manually and trying to<br>
> build.<br>
><br>
> Thanks<br>
> Ajay<br>
><br>
> On Tue, Mar 6, 2012 at 7:43 AM, Michael Wild <<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a>> wrote:<br>
>><br>
>> That's the wrong way to go about things. Rather than putting the COMMAND<br>
>> in the custom target, put it in a add_custom_command() call and make the<br>
>> custom target DEPENDS on it. Then you let the build system handle the<br>
>> dependencies. E.g. like this:<br>
>><br>
>> find_program(JAVAC_COMPILER javac PATH_SUFFIXES bin ENV JAVA_HOME)<br>
>><br>
>> add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test.class<br>
>> COMMAND ${JAVAC_COMPILER} -d ${PROJECT_BINARY_DIR}<br>
>> ${PROJECT_BINARY_DIR}/test.java<br>
>> DEPENDS ${PROJECT_BINARY_DIR}/test.java<br>
>> COMMENT "Compiling test.java"<br>
>> VERBATIM)<br>
>><br>
>> add_custom_target(compile-test-java<br>
>> DEPENDS ${PROJECT_BINARY_DIR}/test.class)<br>
>><br>
>><br>
>> It looks like test.java is a generated file, so depending on how you<br>
>> generate it, you also need to set the GENERATED source file property to<br>
>> TRUE in order for this to work.<br>
>><br>
>> HTH<br>
>><br>
>> Michael<br>
>><br>
>> On 03/06/2012 04:27 PM, Ajay Panyala wrote:<br>
>> > That is because I have a custom target like<br>
>> ><br>
>> > ADD_CUSTOM_TARGET(testc ALL<br>
>> > COMMAND java ${PROJECT_BINARY_DIR}/test.java<br>
>> > DEPENDS ${PROJECT_BINARY_DIR}/test.java<br>
>> > )<br>
>> ><br>
>> > I want to build test.java only if it has been changed.<br>
>> ><br>
>> > Since custom targets are always out-of-date, I wanted to have the<br>
>> > command inside the custom target like<br>
>> ><br>
>> > COMMAND if( test.java has not been modified ) then java build/test.java;<br>
>> > fi<br>
>> ><br>
>> > The syntax of *if* differs between different shells. So I wanted to<br>
>> > check for<br>
>> > the shell first and use the appropriate IF syntax.<br>
>> ><br>
>> ><br>
>> > Thanks<br>
>> > Ajay<br>
>> ><br>
>> ><br>
>> > On Mon, Mar 5, 2012 at 11:03 PM, Eric Noulard <<a href="mailto:eric.noulard@gmail.com">eric.noulard@gmail.com</a><br>
>> > <mailto:<a href="mailto:eric.noulard@gmail.com">eric.noulard@gmail.com</a>>> wrote:<br>
>> ><br>
>> > 2012/3/6 Ajay Panyala <<a href="mailto:ajay@csc.lsu.edu">ajay@csc.lsu.edu</a> <mailto:<a href="mailto:ajay@csc.lsu.edu">ajay@csc.lsu.edu</a>>>:<br>
>> > > Hello,<br>
>> > ><br>
>> > > Is there anyway that cmake could figure out the shell<br>
>> > (bash,csh,..)<br>
>> > > that is being use when cmake is invoked on the command line ?<br>
>> ><br>
>> > May be you can check $ENV{SHELL} ?<br>
>> > Why would you like to do that?<br>
>> ><br>
>> > Usually when using CMake one tries to avoid shell/command<br>
>> > interpreter<br>
>> > dependency??<br>
>> > --<br>
>> > Erk<br>
>> > Le gouvernement représentatif n'est pas la démocratie --<br>
>> > <a href="http://www.le-message.org" target="_blank">http://www.le-message.org</a><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> ><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<br>
>> > <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:<br>
>> > <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>
>><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<br>
>> <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:<br>
>> <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>
><br>
><br>
><br>
><br>
><br>
><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<br>
> <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:<br>
> <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>
<br>
<br>
</div></div>Is CMAKE_CURRENT_BINARY_DIR the same as PROJECT_BINARY_DIR?<br>
<br>
You have one listed as the OUTPUT file and the other listed as the<br>
location of the DEPENDS file...<br>
</blockquote></div><br><br clear="all"><br><br>