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 "Compiling test.java"<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"><<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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>
<div class="im"> ${PROJECT_BINARY_DIR}/test.java<br>
DEPENDS ${PROJECT_BINARY_DIR}/test.java<br>
</div> 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>
<div class="im"><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; fi<br>
><br>
</div>> The syntax of *if* differs between different shells. So I wanted to<br>
<div class="im">> 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>
</div>> <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>
<div class="im">> > Hello,<br>
> ><br>
> > Is there anyway that cmake could figure out the shell (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 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>
</div>> --<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 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>