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

Reply via email to