From e72806fb30dd9162aa1b05cb478ae51d1ecd27fa Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Fri, 31 Jul 2015 10:00:43 +0200 Subject: FindJava: Add support for idlj and jarsigner tools --- Help/release/dev/java-updates.rst | 5 +++ Modules/FindJava.cmake | 94 +++++++++++++++++++++++++++++---------- 2 files changed, 76 insertions(+), 23 deletions(-) create mode 100644 Help/release/dev/java-updates.rst diff --git a/Help/release/dev/java-updates.rst b/Help/release/dev/java-updates.rst new file mode 100644 index 0000000..94998eb --- /dev/null +++ b/Help/release/dev/java-updates.rst @@ -0,0 +1,5 @@ +java-updates +------------ + +* The :module:`FindJava` module learned to optionally find + the ``idlj`` and ``jarsigner`` tools. diff --git a/Modules/FindJava.cmake b/Modules/FindJava.cmake index 9e43174..9f87997 100644 --- a/Modules/FindJava.cmake +++ b/Modules/FindJava.cmake @@ -8,21 +8,34 @@ # include files and libraries are. The caller may set variable JAVA_HOME # to specify a Java installation prefix explicitly. # +# +# Specify one or more of the following components as you call this find module. See example below. +# +# :: +# +# Runtime = User just want to execute some Java byte-compiled +# Development = Development tools (java, javac, javah and javadoc), includes Runtime component +# IdlJ = idl compiler for Java +# JarSigner = signer tool for jar +# +# # This module sets the following result variables: # # :: # -# Java_JAVA_EXECUTABLE = the full path to the Java runtime -# Java_JAVAC_EXECUTABLE = the full path to the Java compiler -# Java_JAVAH_EXECUTABLE = the full path to the Java header generator -# Java_JAVADOC_EXECUTABLE = the full path to the Java documention generator -# Java_JAR_EXECUTABLE = the full path to the Java archiver -# Java_VERSION_STRING = Version of java found, eg. 1.6.0_12 -# Java_VERSION_MAJOR = The major version of the package found. -# Java_VERSION_MINOR = The minor version of the package found. -# Java_VERSION_PATCH = The patch version of the package found. -# Java_VERSION_TWEAK = The tweak version of the package found (after '_') -# Java_VERSION = This is set to: $major.$minor.$patch(.$tweak) +# Java_JAVA_EXECUTABLE = the full path to the Java runtime +# Java_JAVAC_EXECUTABLE = the full path to the Java compiler +# Java_JAVAH_EXECUTABLE = the full path to the Java header generator +# Java_JAVADOC_EXECUTABLE = the full path to the Java documention generator +# Java_IDLJ_EXECUTABLE = the full path to the Java idl compiler +# Java_JAR_EXECUTABLE = the full path to the Java archiver +# Java_JARSIGNER_EXECUTABLE = the full path to the Java jar signer +# Java_VERSION_STRING = Version of java found, eg. 1.6.0_12 +# Java_VERSION_MAJOR = The major version of the package found. +# Java_VERSION_MINOR = The minor version of the package found. +# Java_VERSION_PATCH = The patch version of the package found. +# Java_VERSION_TWEAK = The tweak version of the package found (after '_') +# Java_VERSION = This is set to: $major.$minor.$patch(.$tweak) # # # @@ -184,28 +197,61 @@ find_program(Java_JAVADOC_EXECUTABLE PATHS ${_JAVA_PATHS} ) +find_program(Java_IDLJ_EXECUTABLE + NAMES idlj + HINTS ${_JAVA_HINTS} + PATHS ${_JAVA_PATHS} +) + +find_program(Java_JARSIGNER_EXECUTABLE + NAMES jarsigner + HINTS ${_JAVA_HINTS} + PATHS ${_JAVA_PATHS} +) + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) if(Java_FIND_COMPONENTS) + set(_JAVA_REQUIRED_VARS) foreach(component ${Java_FIND_COMPONENTS}) # User just want to execute some Java byte-compiled - if(component STREQUAL "Runtime") - find_package_handle_standard_args(Java - REQUIRED_VARS Java_JAVA_EXECUTABLE - VERSION_VAR Java_VERSION - ) + If(component STREQUAL "Runtime") + list(APPEND _JAVA_REQUIRED_VARS Java_JAVA_EXECUTABLE) + if(Java_JAVA_EXECUTABLE) + set(Java_Runtime_FOUND TRUE) + endif() elseif(component STREQUAL "Development") - find_package_handle_standard_args(Java - REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE - Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE - VERSION_VAR Java_VERSION - ) + list(APPEND _JAVA_REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAVAC_EXECUTABLE + Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE) + if(Java_JAVA_EXECUTABLE AND Java_JAVAC_EXECUTABLE + AND Java_JAVAH_EXECUTABLE AND Java_JAVADOC_EXECUTABLE) + set(Java_Development_FOUND TRUE) + endif() + elseif(component STREQUAL "IdlJ") + list(APPEND _JAVA_REQUIRED_VARS Java_IDLJ_EXECUTABLE) + if(Java_IdlJ_EXECUTABLE) + set(Java_Extra_FOUND TRUE) + endif() + elseif(component STREQUAL "JarSigner") + list(APPEND _JAVA_REQUIRED_VARS Java_JARSIGNER_EXECUTABLE) + if(Java_IDLJ_EXECUTABLE) + set(Java_JarSigner_FOUND TRUE) + endif() else() message(FATAL_ERROR "Comp: ${component} is not handled") endif() - set(Java_${component}_FOUND TRUE) endforeach() + list (REMOVE_DUPLICATES _JAVA_REQUIRED_VARS) + find_package_handle_standard_args(Java + REQUIRED_VARS ${_JAVA_REQUIRED_VARS} HANDLE_COMPONENTS + VERSION_VAR Java_VERSION + ) + if(Java_FOUND) + foreach(component ${Java_FIND_COMPONENTS}) + set(Java_${component}_FOUND TRUE) + endforeach() + endif() else() - # Check for everything + # Check for Development find_package_handle_standard_args(Java REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE @@ -220,6 +266,8 @@ mark_as_advanced( Java_JAVAC_EXECUTABLE Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE + Java_IDLJ_EXECUTABLE + Java_JARSIGNER_EXECUTABLE ) # LEGACY -- cgit v0.12 From 3d287de4ea99718ffe2ac6b855c2786d67946be2 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Thu, 30 Jul 2015 11:17:04 +0200 Subject: UseJava: Teach add_jar to support file syntax for sources --- Help/release/dev/java-updates.rst | 4 ++++ Modules/UseJava.cmake | 34 +++++++++++++++++++++++++--------- Tests/CMakeLists.txt | 21 +++++++++++++++++---- Tests/Java/CMakeLists.txt | 4 ++++ 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 .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) -- cgit v0.12 From cc23f0e9d38fe3f880ada549af4e552fc13fc655 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Thu, 30 Jul 2015 11:19:24 +0200 Subject: UseJava: Teach install_jar new DESTINATION and COMPONENT options --- Help/release/dev/java-updates.rst | 4 +++ Modules/UseJava.cmake | 54 ++++++++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/Help/release/dev/java-updates.rst b/Help/release/dev/java-updates.rst index 2e5e184..b777807 100644 --- a/Help/release/dev/java-updates.rst +++ b/Help/release/dev/java-updates.rst @@ -7,3 +7,7 @@ java-updates * The :module:`UseJava` module ``add_jar`` function learned to support response files (e.g. ``@srcs.txt``) for source specification. + +* The :module:`UseJava` module ``install_jar`` function learned + new ``DESTINATION`` and ``COMPONENT`` options to specify + the corresponding :command:`install` command options. diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake index 0add8d2..c61591d 100644 --- a/Modules/UseJava.cmake +++ b/Modules/UseJava.cmake @@ -211,14 +211,16 @@ # # :: # -# install_jar(TARGET_NAME DESTINATION) +# install_jar(target_name destination) +# install_jar(target_name DESTINATION destination [COMPONENT component]) # # This command installs the TARGET_NAME files to the given DESTINATION. # It should be called in the same scope as add_jar() or it will fail. # # :: # -# install_jni_symlink(TARGET_NAME DESTINATION) +# install_jni_symlink(target_name destination) +# install_jni_symlink(target_name DESTINATION destination [COMPONENT component]) # # This command installs the TARGET_NAME JNI symlinks to the given # DESTINATION. It should be called in the same scope as add_jar() or it @@ -629,7 +631,26 @@ function(add_jar _TARGET_NAME) endfunction() -function(INSTALL_JAR _TARGET_NAME _DESTINATION) +function(INSTALL_JAR _TARGET_NAME) + if (ARGC EQUAL 2) + set (_DESTINATION ${ARGV1}) + else() + cmake_parse_arguments(_install_jar + "" + "DESTINATION;COMPONENT" + "" + ${ARGN}) + if (_install_jar_DESTINATION) + set (_DESTINATION ${_install_jar_DESTINATION}) + else() + message(SEND_ERROR "install_jar: ${_TARGET_NAME}: DESTINATION must be specified.") + endif() + + if (_install_jar_COMPONENT) + set (_COMPONENT COMPONENT ${_install_jar_COMPONENT}) + endif() + endif() + get_property(__FILES TARGET ${_TARGET_NAME} @@ -643,13 +664,33 @@ function(INSTALL_JAR _TARGET_NAME _DESTINATION) ${__FILES} DESTINATION ${_DESTINATION} + ${_COMPONENT} ) else () - message(SEND_ERROR "The target ${_TARGET_NAME} is not known in this scope.") + message(SEND_ERROR "install_jar: The target ${_TARGET_NAME} is not known in this scope.") endif () endfunction() -function(INSTALL_JNI_SYMLINK _TARGET_NAME _DESTINATION) +function(INSTALL_JNI_SYMLINK _TARGET_NAME) + if (ARGC EQUAL 2) + set (_DESTINATION ${ARGV1}) + else() + cmake_parse_arguments(_install_jni_symlink + "" + "DESTINATION;COMPONENT" + "" + ${ARGN}) + if (_install_jni_symlink_DESTINATION) + set (_DESTINATION ${_install_jni_symlink_DESTINATION}) + else() + message(SEND_ERROR "install_jni_symlink: ${_TARGET_NAME}: DESTINATION must be specified.") + endif() + + if (_install_jni_symlink_COMPONENT) + set (_COMPONENT COMPONENT ${_install_jni_symlink_COMPONENT}) + endif() + endif() + get_property(__SYMLINK TARGET ${_TARGET_NAME} @@ -663,9 +704,10 @@ function(INSTALL_JNI_SYMLINK _TARGET_NAME _DESTINATION) ${__SYMLINK} DESTINATION ${_DESTINATION} + ${_COMPONENT} ) else () - message(SEND_ERROR "The target ${_TARGET_NAME} is not known in this scope.") + message(SEND_ERROR "install_jni_symlink: The target ${_TARGET_NAME} is not known in this scope.") endif () endfunction() -- cgit v0.12