add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test.class<br>
  COMMAND ${JAVAC_COMPILER} -d ${PROJECT_BINARY_DIR}<br>
<div class="im">    ${PROJECT_BINARY_DIR}/test.java<br>
  DEPENDS ${PROJECT_BINARY_DIR}/test.java<br>
</div>  COMMENT &quot;Compiling test.java&quot;<br>
  VERBATIM)<br>
<br>
add_custom_target(compile-test-java<br><div>
  DEPENDS ${PROJECT_BINARY_DIR}/test.class)<br></div><div><br></div><div>I tried this. It builds as expected initially. But when I change test.java and run</div><div>make, it is not re-compiled.</div><div><br></div><div>
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.</div><div><br></div><div>test.java is not a generated file. I am modifying it manually and trying to build.</div><div><br></div><div>Thanks</div><div>Ajay</div><br><div class="gmail_quote">
On Tue, Mar 6, 2012 at 7:43 AM, Michael Wild <span dir="ltr">&lt;<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
That&#39;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>
<div class="im">    ${PROJECT_BINARY_DIR}/test.java<br>
  DEPENDS ${PROJECT_BINARY_DIR}/test.java<br>
</div>  COMMENT &quot;Compiling test.java&quot;<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>
<div class="im"><br>
On 03/06/2012 04:27 PM, Ajay Panyala wrote:<br>
&gt; That is because I have a custom target like<br>
&gt;<br>
&gt; ADD_CUSTOM_TARGET(testc ALL<br>
&gt;   COMMAND java ${PROJECT_BINARY_DIR}/test.java<br>
&gt;   DEPENDS ${PROJECT_BINARY_DIR}/test.java<br>
&gt; )<br>
&gt;<br>
&gt; I want to build test.java only if it has been changed.<br>
&gt;<br>
&gt; Since custom targets are always out-of-date, I wanted to have the<br>
&gt; command inside the custom target like<br>
&gt;<br>
&gt; COMMAND if( test.java has not been modified ) then java build/test.java; fi<br>
&gt;<br>
</div>&gt; The syntax of *if* differs between different shells. So I wanted to<br>
<div class="im">&gt; check for<br>
&gt; the shell first and use the appropriate IF syntax.<br>
&gt;<br>
&gt;<br>
&gt; Thanks<br>
&gt; Ajay<br>
&gt;<br>
&gt;<br>
&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>
</div>&gt; &lt;mailto:<a href="mailto:eric.noulard@gmail.com">eric.noulard@gmail.com</a>&gt;&gt; wrote:<br>
&gt;<br>
&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>
<div class="im">&gt;     &gt; Hello,<br>
&gt;     &gt;<br>
&gt;     &gt; Is there anyway that cmake could figure out the shell (bash,csh,..)<br>
&gt;     &gt; that is being use when cmake is invoked on the command line ?<br>
&gt;<br>
&gt;     May be you can check $ENV{SHELL} ?<br>
&gt;     Why would you like to do that?<br>
&gt;<br>
&gt;     Usually when using CMake one tries to avoid shell/command interpreter<br>
&gt;     dependency??<br>
&gt;     --<br>
&gt;     Erk<br>
&gt;     Le gouvernement représentatif n&#39;est pas la démocratie --<br>
&gt;     <a href="http://www.le-message.org" target="_blank">http://www.le-message.org</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div>&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 <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: <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>
<font color="#888888"><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>
</font></blockquote></div><br><br clear="all"><br><br>