UseJava: Teach add_jar to support file syntax for sources
This commit is contained in:
parent
e72806fb30
commit
3d287de4ea
|
@ -3,3 +3,7 @@ java-updates
|
||||||
|
|
||||||
* The :module:`FindJava` module learned to optionally find
|
* The :module:`FindJava` module learned to optionally find
|
||||||
the ``idlj`` and ``jarsigner`` tools.
|
the ``idlj`` and ``jarsigner`` tools.
|
||||||
|
|
||||||
|
* The :module:`UseJava` module ``add_jar`` function learned
|
||||||
|
to support response files (e.g. ``@srcs.txt``) for source
|
||||||
|
specification.
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
#
|
#
|
||||||
# This command creates a <target_name>.jar. It compiles the given
|
# This command creates a <target_name>.jar. It compiles the given
|
||||||
# source files (source) and adds the given resource files (resource) to
|
# 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
|
# 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.
|
# compiling the java sources and also to the dependencies of the target.
|
||||||
# INCLUDE_JARS also accepts other target names created by add_jar. For
|
# 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_CLASS_FILES)
|
||||||
set(_JAVA_COMPILE_FILES)
|
set(_JAVA_COMPILE_FILES)
|
||||||
|
set(_JAVA_COMPILE_FILELISTS)
|
||||||
set(_JAVA_DEPENDS)
|
set(_JAVA_DEPENDS)
|
||||||
set(_JAVA_COMPILE_DEPENDS)
|
set(_JAVA_COMPILE_DEPENDS)
|
||||||
set(_JAVA_RESOURCE_FILES)
|
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_PATH ${_JAVA_SOURCE_FILE} PATH)
|
||||||
get_filename_component(_JAVA_FULL ${_JAVA_SOURCE_FILE} ABSOLUTE)
|
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_BINARY_PATH ${_add_jar_OUTPUT_DIR} ${_JAVA_FULL})
|
||||||
file(RELATIVE_PATH _JAVA_REL_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${_JAVA_FULL})
|
file(RELATIVE_PATH _JAVA_REL_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${_JAVA_FULL})
|
||||||
string(LENGTH ${_JAVA_REL_BINARY_PATH} _BIN_LEN)
|
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 "")
|
file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (_JAVA_COMPILE_FILES)
|
if (_JAVA_COMPILE_FILES OR _JAVA_COMPILE_FILELISTS)
|
||||||
# Create the list of files to compile.
|
set (_JAVA_SOURCES_FILELISTS)
|
||||||
set(_JAVA_SOURCES_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_sources)
|
|
||||||
string(REPLACE ";" "\"\n\"" _JAVA_COMPILE_STRING "\"${_JAVA_COMPILE_FILES}\"")
|
if (_JAVA_COMPILE_FILES)
|
||||||
file(WRITE ${_JAVA_SOURCES_FILE} ${_JAVA_COMPILE_STRING})
|
# 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
|
# Compile the java files and create a list of class files
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
|
@ -506,9 +522,9 @@ function(add_jar _TARGET_NAME)
|
||||||
${CMAKE_JAVA_COMPILE_FLAGS}
|
${CMAKE_JAVA_COMPILE_FLAGS}
|
||||||
-classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}"
|
-classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}"
|
||||||
-d ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
|
-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}
|
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}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
COMMENT "Building Java objects for ${_TARGET_NAME}.jar"
|
COMMENT "Building Java objects for ${_TARGET_NAME}.jar"
|
||||||
)
|
)
|
||||||
|
|
|
@ -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
|
if(JNI_H AND EXISTS "${JNI_H}") # in case jni.h is a broken symlink
|
||||||
file(READ "${JNI_H}" JNI_FILE)
|
file(READ "${JNI_H}" JNI_FILE)
|
||||||
if("${JNI_FILE}" MATCHES "JDK1_2")
|
if("${JNI_FILE}" MATCHES "JDK1_2")
|
||||||
add_test(Java ${CMAKE_CTEST_COMMAND}
|
add_test(Java.Jar ${CMAKE_CTEST_COMMAND}
|
||||||
--build-and-test
|
--build-and-test
|
||||||
"${CMake_SOURCE_DIR}/Tests/Java"
|
"${CMake_SOURCE_DIR}/Tests/Java"
|
||||||
"${CMake_BINARY_DIR}/Tests/Java"
|
"${CMake_BINARY_DIR}/Tests/JavaJar"
|
||||||
${build_generator_args}
|
${build_generator_args}
|
||||||
--build-project hello
|
--build-project hello
|
||||||
|
--build-target hello
|
||||||
--build-two-config
|
--build-two-config
|
||||||
--build-run-dir "${CMake_BINARY_DIR}/Tests/Java/"
|
--build-run-dir "${CMake_BINARY_DIR}/Tests/JavaJar/"
|
||||||
--build-options ${build_options}
|
--build-options ${build_options}
|
||||||
--test-command ${JAVA_RUNTIME} -classpath hello.jar HelloWorld)
|
--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()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -7,3 +7,7 @@ find_package(Java COMPONENTS Development)
|
||||||
include (UseJava)
|
include (UseJava)
|
||||||
|
|
||||||
add_jar(hello A.java HelloWorld.java)
|
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)
|
||||||
|
|
Loading…
Reference in New Issue