summaryrefslogtreecommitdiffstats
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
parente72806fb30dd9162aa1b05cb478ae51d1ecd27fa (diff)
downloadCMake-3d287de4ea99718ffe2ac6b855c2786d67946be2.zip
CMake-3d287de4ea99718ffe2ac6b855c2786d67946be2.tar.gz
CMake-3d287de4ea99718ffe2ac6b855c2786d67946be2.tar.bz2
UseJava: Teach add_jar to support file syntax for sources
-rw-r--r--Help/release/dev/java-updates.rst4
-rw-r--r--Modules/UseJava.cmake34
-rw-r--r--Tests/CMakeLists.txt21
-rw-r--r--Tests/Java/CMakeLists.txt4
4 files changed, 50 insertions, 13 deletions
diff --git a/Help/release/dev/java-updates.rst b/Help/release/dev/java-updates.rst
index 94998eb..2e5e184 100644
--- a/Help/release/dev/java-updates.rst
+++ b/Help/release/dev/java-updates.rst
@@ -3,3 +3,7 @@ java-updates
* The :module:`FindJava` module learned to optionally find
the ``idlj`` and ``jarsigner`` tools.
+
+* The :module:`UseJava` module ``add_jar`` function learned
+ to support response files (e.g. ``@srcs.txt``) for source
+ specification.
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"
)
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index d95a5f4..5781a9e 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -3008,17 +3008,30 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
if(JNI_H AND EXISTS "${JNI_H}") # in case jni.h is a broken symlink
file(READ "${JNI_H}" JNI_FILE)
if("${JNI_FILE}" MATCHES "JDK1_2")
- add_test(Java ${CMAKE_CTEST_COMMAND}
+ add_test(Java.Jar ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/Java"
- "${CMake_BINARY_DIR}/Tests/Java"
+ "${CMake_BINARY_DIR}/Tests/JavaJar"
${build_generator_args}
--build-project hello
+ --build-target hello
--build-two-config
- --build-run-dir "${CMake_BINARY_DIR}/Tests/Java/"
+ --build-run-dir "${CMake_BINARY_DIR}/Tests/JavaJar/"
--build-options ${build_options}
--test-command ${JAVA_RUNTIME} -classpath hello.jar HelloWorld)
- list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Java")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaJar")
+ add_test(Java.JarSourceList ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Java"
+ "${CMake_BINARY_DIR}/Tests/JavaJarSourceList"
+ ${build_generator_args}
+ --build-project hello
+ --build-target hello2
+ --build-two-config
+ --build-run-dir "${CMake_BINARY_DIR}/Tests/JavaJarSourceList/"
+ --build-options ${build_options}
+ --test-command ${JAVA_RUNTIME} -classpath hello2.jar HelloWorld)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaJarSourceList")
endif()
endif()
endif()
diff --git a/Tests/Java/CMakeLists.txt b/Tests/Java/CMakeLists.txt
index 6a69a24..e1bcf3c 100644
--- a/Tests/Java/CMakeLists.txt
+++ b/Tests/Java/CMakeLists.txt
@@ -7,3 +7,7 @@ find_package(Java COMPONENTS Development)
include (UseJava)
add_jar(hello A.java HelloWorld.java)
+
+# use listing file to specify sources
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/java_fileslist "A.java\nHelloWorld.java\n")
+add_jar(hello2 @${CMAKE_CURRENT_BINARY_DIR}/java_fileslist)