1 cmake_minimum_required (VERSION 2.6)
3 SET(CMAKE_VERBOSE_MAKEFILE 1)
5 IF("${hello_SOURCE_DIR}" STREQUAL "${hello_BINARY_DIR}")
6 MESSAGE("In Source, building Java using ADD_CUSTOM_COMMAND()")
7 SET(OLD_CUSTOM_COMMAND_WAY 1)
8 ELSE("${hello_SOURCE_DIR}" STREQUAL "${hello_BINARY_DIR}")
9 MESSAGE("Out of source, using built-in Java support")
10 SET(OLD_CUSTOM_COMMAND_WAY )
11 ENDIF("${hello_SOURCE_DIR}" STREQUAL "${hello_BINARY_DIR}")
13 IF(NOT OLD_CUSTOM_COMMAND_WAY)
15 INCLUDE_DIRECTORIES(${hello_SOURCE_DIR}
17 ADD_LIBRARY(hello A.java HelloWorld.java)
19 ELSE(NOT OLD_CUSTOM_COMMAND_WAY)
22 OUTPUT ${hello_BINARY_DIR}/A.class
23 MAIN_DEPENDENCY ${hello_SOURCE_DIR}/A.java
24 COMMAND ${CMAKE_Java_COMPILER} ARGS -classpath . -d ${hello_BINARY_DIR} ${hello_SOURCE_DIR}/A.java)
26 OUTPUT ${hello_BINARY_DIR}/HelloWorld.class
27 MAIN_DEPENDENCY ${hello_SOURCE_DIR}/HelloWorld.java
28 DEPENDS ${hello_BINARY_DIR}/A.class
29 COMMAND ${CMAKE_Java_COMPILER} ARGS -classpath . -d ${hello_BINARY_DIR} ${hello_SOURCE_DIR}/HelloWorld.java)
31 OUTPUT ${hello_BINARY_DIR}/hello.jar
32 DEPENDS ${hello_BINARY_DIR}/A.class ${hello_BINARY_DIR}/HelloWorld.class
33 COMMAND ${CMAKE_COMMAND}
34 ARGS -E chdir ${CMAKE_CURRENT_BINARY_DIR}
36 -cvf hello.jar *.class)
38 ADD_CUSTOM_TARGET(hello_jar ALL
39 DEPENDS ${hello_BINARY_DIR}/hello.jar)
41 ENDIF(NOT OLD_CUSTOM_COMMAND_WAY)