<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">&lt;<a href="mailto:david.cole@kitware.com">david.cole@kitware.com</a>&gt;</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 &lt;<a href="mailto:ajay@csc.lsu.edu">ajay@csc.lsu.edu</a>&gt; wrote:<br>

&gt; add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test.class<br>
&gt;  COMMAND ${JAVAC_COMPILER} -d ${PROJECT_BINARY_DIR}<br>
&gt;    ${PROJECT_BINARY_DIR}/test.java<br>
&gt;  DEPENDS ${PROJECT_BINARY_DIR}/test.java<br>
&gt;  COMMENT &quot;Compiling test.java&quot;<br>
&gt;  VERBATIM)<br>
&gt;<br>
&gt; add_custom_target(compile-test-java<br>
&gt;  DEPENDS ${PROJECT_BINARY_DIR}/test.class)<br>
&gt;<br>
&gt; I tried this. It builds as expected initially. But when I change test.java<br>
&gt; and run<br>
&gt; make, it is not re-compiled.<br>
&gt;<br>
&gt; It looks like test.java is a generated file, so depending on how you<br>
&gt; generate it, you also need to set the GENERATED source file property to<br>
&gt; TRUE in order for this to work.<br>
&gt;<br>
&gt; test.java is not a generated file. I am modifying it manually and trying to<br>
&gt; build.<br>
&gt;<br>
&gt; Thanks<br>
&gt; Ajay<br>
&gt;<br>
&gt; On Tue, Mar 6, 2012 at 7:43 AM, Michael Wild &lt;<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; That&#39;s the wrong way to go about things. Rather than putting the COMMAND<br>
&gt;&gt; in the custom target, put it in a add_custom_command() call and make the<br>
&gt;&gt; custom target DEPENDS on it. Then you let the build system handle the<br>
&gt;&gt; dependencies. E.g. like this:<br>
&gt;&gt;<br>
&gt;&gt; find_program(JAVAC_COMPILER javac PATH_SUFFIXES bin ENV JAVA_HOME)<br>
&gt;&gt;<br>
&gt;&gt; add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test.class<br>
&gt;&gt;  COMMAND ${JAVAC_COMPILER} -d ${PROJECT_BINARY_DIR}<br>
&gt;&gt;    ${PROJECT_BINARY_DIR}/test.java<br>
&gt;&gt;  DEPENDS ${PROJECT_BINARY_DIR}/test.java<br>
&gt;&gt;  COMMENT &quot;Compiling test.java&quot;<br>
&gt;&gt;  VERBATIM)<br>
&gt;&gt;<br>
&gt;&gt; add_custom_target(compile-test-java<br>
&gt;&gt;  DEPENDS ${PROJECT_BINARY_DIR}/test.class)<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; It looks like test.java is a generated file, so depending on how you<br>
&gt;&gt; generate it, you also need to set the GENERATED source file property to<br>
&gt;&gt; TRUE in order for this to work.<br>
&gt;&gt;<br>
&gt;&gt; HTH<br>
&gt;&gt;<br>
&gt;&gt; Michael<br>
&gt;&gt;<br>
&gt;&gt; On 03/06/2012 04:27 PM, Ajay Panyala wrote:<br>
&gt;&gt; &gt; That is because I have a custom target like<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; ADD_CUSTOM_TARGET(testc ALL<br>
&gt;&gt; &gt;   COMMAND java ${PROJECT_BINARY_DIR}/test.java<br>
&gt;&gt; &gt;   DEPENDS ${PROJECT_BINARY_DIR}/test.java<br>
&gt;&gt; &gt; )<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I want to build test.java only if it has been changed.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Since custom targets are always out-of-date, I wanted to have the<br>
&gt;&gt; &gt; command inside the custom target like<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; COMMAND if( test.java has not been modified ) then java build/test.java;<br>
&gt;&gt; &gt; fi<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; The syntax of *if* differs between different shells. So I wanted to<br>
&gt;&gt; &gt; check for<br>
&gt;&gt; &gt; the shell first and use the appropriate IF syntax.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thanks<br>
&gt;&gt; &gt; Ajay<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Mon, Mar 5, 2012 at 11:03 PM, Eric Noulard &lt;<a href="mailto:eric.noulard@gmail.com">eric.noulard@gmail.com</a><br>
&gt;&gt; &gt; &lt;mailto:<a href="mailto:eric.noulard@gmail.com">eric.noulard@gmail.com</a>&gt;&gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;     2012/3/6 Ajay Panyala &lt;<a href="mailto:ajay@csc.lsu.edu">ajay@csc.lsu.edu</a> &lt;mailto:<a href="mailto:ajay@csc.lsu.edu">ajay@csc.lsu.edu</a>&gt;&gt;:<br>
&gt;&gt; &gt;     &gt; Hello,<br>
&gt;&gt; &gt;     &gt;<br>
&gt;&gt; &gt;     &gt; Is there anyway that cmake could figure out the shell<br>
&gt;&gt; &gt; (bash,csh,..)<br>
&gt;&gt; &gt;     &gt; that is being use when cmake is invoked on the command line ?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;     May be you can check $ENV{SHELL} ?<br>
&gt;&gt; &gt;     Why would you like to do that?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;     Usually when using CMake one tries to avoid shell/command<br>
&gt;&gt; &gt; interpreter<br>
&gt;&gt; &gt;     dependency??<br>
&gt;&gt; &gt;     --<br>
&gt;&gt; &gt;     Erk<br>
&gt;&gt; &gt;     Le gouvernement représentatif n&#39;est pas la démocratie --<br>
&gt;&gt; &gt;     <a href="http://www.le-message.org" target="_blank">http://www.le-message.org</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; --<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Visit other Kitware open-source projects at<br>
&gt;&gt; &gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Please keep messages on-topic and check the CMake FAQ at:<br>
&gt;&gt; &gt; <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Follow this link to subscribe/unsubscribe:<br>
&gt;&gt; &gt; <a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt;<br>
&gt;&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;&gt;<br>
&gt;&gt; Visit other Kitware open-source projects at<br>
&gt;&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;&gt;<br>
&gt;&gt; Please keep messages on-topic and check the CMake FAQ at:<br>
&gt;&gt; <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
&gt;&gt;<br>
&gt;&gt; Follow this link to subscribe/unsubscribe:<br>
&gt;&gt; <a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt;<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the CMake FAQ at:<br>
&gt; <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <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>