summaryrefslogtreecommitdiffstats
path: root/Modules/UseJava.cmake
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@sap.com>2015-07-30 09:17:04 (GMT)
committerBrad King <brad.king@kitware.com>2015-08-04 15:19:43 (GMT)
commit3d287de4ea99718ffe2ac6b855c2786d67946be2 (patch)
treeda8f2e5214ad8710a04d6170653ce03ee712bc95 /Modules/UseJava.cmake
parente72806fb30dd9162aa1b05cb478ae51d1ecd27fa (diff)
downloadCMake-3d287de4ea99718ffe2ac6b855c2786d67946be2.zip
CMake-3d287de4ea99718ffe2ac6b855c2786d67946be2.tar.gz
CMake-3d287de4ea99718ffe2ac6b855c2786d67946be2.tar.bz2
UseJava: Teach add_jar to support file syntax for sources
Diffstat (limited to 'Modules/UseJava.cmake')
-rw-r--r--Modules/UseJava.cmake34
1 files changed, 25 insertions, 9 deletions
diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake
index 5eb0ca8..0add8d2 100644
--- a/Modules/UseJava.cmake
+++ b/Modules/UseJava.cmake
@@ -21,7 +21,8 @@
#
# This command creates a <target_name>.jar. It compiles the given
# source files (source) and adds the given resource files (resource) to
-# the jar file. If only resource files are given then just a jar file
+# the jar file. Source files can be java files or listing files
+# (prefixed by '@'). If only resource files are given then just a jar file
# is created. The list of include jars are added to the classpath when
# compiling the java sources and also to the dependencies of the target.
# INCLUDE_JARS also accepts other target names created by add_jar. For
@@ -423,6 +424,7 @@ function(add_jar _TARGET_NAME)
set(_JAVA_CLASS_FILES)
set(_JAVA_COMPILE_FILES)
+ set(_JAVA_COMPILE_FILELISTS)
set(_JAVA_DEPENDS)
set(_JAVA_COMPILE_DEPENDS)
set(_JAVA_RESOURCE_FILES)
@@ -433,7 +435,11 @@ function(add_jar _TARGET_NAME)
get_filename_component(_JAVA_PATH ${_JAVA_SOURCE_FILE} PATH)
get_filename_component(_JAVA_FULL ${_JAVA_SOURCE_FILE} ABSOLUTE)
- if (_JAVA_EXT MATCHES ".java")
+ if (_JAVA_SOURCE_FILE MATCHES "^@(.+)$")
+ get_filename_component(_JAVA_FULL ${CMAKE_MATCH_1} ABSOLUTE)
+ list(APPEND _JAVA_COMPILE_FILELISTS ${_JAVA_FULL})
+
+ elseif (_JAVA_EXT MATCHES ".java")
file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${_add_jar_OUTPUT_DIR} ${_JAVA_FULL})
file(RELATIVE_PATH _JAVA_REL_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${_JAVA_FULL})
string(LENGTH ${_JAVA_REL_BINARY_PATH} _BIN_LEN)
@@ -492,11 +498,21 @@ function(add_jar _TARGET_NAME)
file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "")
endif()
- if (_JAVA_COMPILE_FILES)
- # Create the list of files to compile.
- set(_JAVA_SOURCES_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_sources)
- string(REPLACE ";" "\"\n\"" _JAVA_COMPILE_STRING "\"${_JAVA_COMPILE_FILES}\"")
- file(WRITE ${_JAVA_SOURCES_FILE} ${_JAVA_COMPILE_STRING})
+ if (_JAVA_COMPILE_FILES OR _JAVA_COMPILE_FILELISTS)
+ set (_JAVA_SOURCES_FILELISTS)
+
+ if (_JAVA_COMPILE_FILES)
+ # Create the list of files to compile.
+ set(_JAVA_SOURCES_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_sources)
+ string(REPLACE ";" "\"\n\"" _JAVA_COMPILE_STRING "\"${_JAVA_COMPILE_FILES}\"")
+ file(WRITE ${_JAVA_SOURCES_FILE} ${_JAVA_COMPILE_STRING})
+ list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_SOURCES_FILE}")
+ endif()
+ if (_JAVA_COMPILE_FILELISTS)
+ foreach (_JAVA_FILELIST IN LISTS _JAVA_COMPILE_FILELISTS)
+ list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_FILELIST}")
+ endforeach()
+ endif()
# Compile the java files and create a list of class files
add_custom_command(
@@ -506,9 +522,9 @@ function(add_jar _TARGET_NAME)
${CMAKE_JAVA_COMPILE_FLAGS}
-classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}"
-d ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
- @${_JAVA_SOURCES_FILE}
+ ${_JAVA_SOURCES_FILELISTS}
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
- DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_DEPENDS}
+ DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_FILELISTS} ${_JAVA_COMPILE_DEPENDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building Java objects for ${_TARGET_NAME}.jar"
)