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