summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-06-09 13:18:17 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2016-06-09 13:18:17 (GMT)
commit5aa89a1ae0554c8bf428d079a0a716e9254e516f (patch)
tree671eaf97f597eacf6ca7b88a31c41be81f3245f2 /Modules
parent39699947589e96b59d7f56d9c0b1dcb1bef27f8a (diff)
parent0bd91ad4058c006bb67b48801e1877e8a893ef4d (diff)
downloadCMake-5aa89a1ae0554c8bf428d079a0a716e9254e516f.zip
CMake-5aa89a1ae0554c8bf428d079a0a716e9254e516f.tar.gz
CMake-5aa89a1ae0554c8bf428d079a0a716e9254e516f.tar.bz2
Merge topic 'java-export-targets'
0bd91ad4 UseJava: Fix race condition creating java class list 89df91b9 Help: Add notes for topic 'java-export-targets' 95d84369 Tests: Add test for exported JARs 5341c0d8 UseJava: Add infrastructure to export targets d91ec044 Tests/Java: Clean up style of Java test code
Diffstat (limited to 'Modules')
-rw-r--r--Modules/UseJava.cmake163
-rw-r--r--Modules/javaTargets.cmake.in39
2 files changed, 197 insertions, 5 deletions
diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake
index 7b3416e..cf9c2d7 100644
--- a/Modules/UseJava.cmake
+++ b/Modules/UseJava.cmake
@@ -217,6 +217,19 @@
# 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.
#
+# Target Properties:
+#
+# ::
+#
+# The install_jar() function sets the INSTALL_DESTINATION target property
+# on jars so installed. This property holds the DESTINATION as described
+# above, and is used by install_jar_exports(). You can get this property
+# with the
+# get_property(TARGET <target_name> PROPERTY INSTALL_DESTINATION)
+# command.
+#
+#
+#
# ::
#
# install_jni_symlink(target_name destination)
@@ -228,6 +241,24 @@
#
# ::
#
+# install_jar_exports(TARGETS jar1 [jar2 ...]
+# FILE export_filename
+# DESTINATION destination [COMPONENT component])
+#
+# This command installs a target export file export_filename for the named jar
+# targets to the given DESTINATION. Its function is similar to that of
+# install(EXPORTS).
+#
+# ::
+#
+# export_jars(TARGETS jar1 [jar2 ...]
+# FILE export_filename)
+#
+# This command writes a target export file export_filename for the named jar
+# targets. Its function is similar to that of export().
+#
+# ::
+#
# create_javadoc(<VAR>
# PACKAGES pkg1 [pkg2 ...]
# [SOURCEPATH <sourcepath>]
@@ -396,7 +427,29 @@ function (__java_copy_file src dest comment)
COMMENT ${comment})
endfunction ()
+function(__java_lcat VAR)
+ foreach(_line ${ARGN})
+ set(${VAR} "${${VAR}}${_line}\n")
+ endforeach()
+
+ set(${VAR} "${${VAR}}" PARENT_SCOPE)
+endfunction()
+
+function(__java_export_jar VAR TARGET PATH)
+ get_target_property(_jarpath ${TARGET} JAR_FILE)
+ get_filename_component(_jarname ${_jarpath} NAME)
+ __java_lcat(${VAR}
+ "# Create imported target ${TARGET}"
+ "add_custom_target(${TARGET})"
+ "set_target_properties(${TARGET} PROPERTIES"
+ " JAR_FILE \"${PATH}/${_jarname}\")"
+ ""
+ )
+ set(${VAR} "${${VAR}}" PARENT_SCOPE)
+endfunction()
+
# define helper scripts
+set(_JAVA_EXPORT_TARGETS_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/javaTargets.cmake.in)
set(_JAVA_CLASS_FILELIST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaClassFilelist.cmake)
set(_JAVA_SYMLINK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaSymlinks.cmake)
@@ -435,6 +488,8 @@ function(add_jar _TARGET_NAME)
if (NOT DEFINED _add_jar_OUTPUT_DIR)
set(_add_jar_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
+ else()
+ get_filename_component(_add_jar_OUTPUT_DIR ${_add_jar_OUTPUT_DIR} ABSOLUTE)
endif()
if (_add_jar_ENTRY_POINT)
@@ -554,11 +609,6 @@ function(add_jar _TARGET_NAME)
endif ()
endforeach()
- # create an empty java_class_filelist
- if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist)
- file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "")
- endif()
-
if (_JAVA_COMPILE_FILES OR _JAVA_COMPILE_FILELISTS)
set (_JAVA_SOURCES_FILELISTS)
@@ -598,6 +648,11 @@ function(add_jar _TARGET_NAME)
DEPENDS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
+ else ()
+ # create an empty java_class_filelist
+ if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist)
+ file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "")
+ endif()
endif ()
# create the jar file
@@ -716,6 +771,13 @@ function(INSTALL_JAR _TARGET_NAME)
PROPERTY
INSTALL_FILES
)
+ set_property(
+ TARGET
+ ${_TARGET_NAME}
+ PROPERTY
+ INSTALL_DESTINATION
+ ${_DESTINATION}
+ )
if (__FILES)
install(
@@ -1288,3 +1350,94 @@ function (create_javah)
set (${_create_javah_GENERATED_FILES} ${_output_files} PARENT_SCOPE)
endif()
endfunction()
+
+function(export_jars)
+ # Parse and validate arguments
+ cmake_parse_arguments(_export_jars
+ ""
+ "FILE"
+ "TARGETS"
+ ${ARGN}
+ )
+ if (NOT _export_jars_FILE)
+ message(SEND_ERROR "export_jars: FILE must be specified.")
+ endif()
+ if (NOT _export_jars_TARGETS)
+ message(SEND_ERROR "export_jars: TARGETS must be specified.")
+ endif()
+
+ # Set content of generated exports file
+ string(REPLACE ";" " " __targets__ "${_export_jars_TARGETS}")
+ set(__targetdefs__ "")
+ foreach(_target ${_export_jars_TARGETS})
+ get_target_property(_jarpath ${_target} JAR_FILE)
+ get_filename_component(_jarpath ${_jarpath} PATH)
+ __java_export_jar(__targetdefs__ ${_target} "${_jarpath}")
+ endforeach()
+
+ # Generate exports file
+ configure_file(
+ ${_JAVA_EXPORT_TARGETS_SCRIPT}
+ ${_export_jars_FILE}
+ @ONLY
+ )
+endfunction()
+
+function(install_jar_exports)
+ # Parse and validate arguments
+ cmake_parse_arguments(_install_jar_exports
+ ""
+ "FILE;DESTINATION;COMPONENT"
+ "TARGETS"
+ ${ARGN}
+ )
+ if (NOT _install_jar_exports_FILE)
+ message(SEND_ERROR "install_jar_exports: FILE must be specified.")
+ endif()
+ if (NOT _install_jar_exports_DESTINATION)
+ message(SEND_ERROR "install_jar_exports: DESTINATION must be specified.")
+ endif()
+ if (NOT _install_jar_exports_TARGETS)
+ message(SEND_ERROR "install_jar_exports: TARGETS must be specified.")
+ endif()
+
+ if (_install_jar_exports_COMPONENT)
+ set (_COMPONENT COMPONENT ${_install_jar_exports_COMPONENT})
+ endif()
+
+ # Determine relative path from installed export file to install prefix
+ if(IS_ABSOLUTE ${_install_jar_exports_DESTINATION})
+ file(RELATIVE_PATH _relpath
+ ${_install_jar_exports_DESTINATION}
+ ${CMAKE_INSTALL_PREFIX}
+ )
+ else()
+ file(RELATIVE_PATH _relpath
+ ${CMAKE_INSTALL_PREFIX}/${_install_jar_exports_DESTINATION}
+ ${CMAKE_INSTALL_PREFIX}
+ )
+ endif()
+
+ # Set up unique location for generated exports file
+ string(SHA256 _hash "${_install_jar_exports_DESTINATION}")
+ set(_tmpdir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/JavaExports/${_hash})
+
+ # Set content of generated exports file
+ string(REPLACE ";" " " __targets__ "${_install_jar_exports_TARGETS}")
+ set(__targetdefs__ "set(_prefix \${CMAKE_CURRENT_LIST_DIR}/${_relpath})\n\n")
+ foreach(_target ${_install_jar_exports_TARGETS})
+ get_target_property(_dir ${_target} INSTALL_DESTINATION)
+ __java_export_jar(__targetdefs__ ${_target} "\${_prefix}/${_dir}")
+ endforeach()
+ __java_lcat(__targetdefs__ "\nunset(_prefix)")
+
+ # Generate and install exports file
+ configure_file(
+ ${_JAVA_EXPORT_TARGETS_SCRIPT}
+ ${_tmpdir}/${_install_jar_exports_FILE}
+ @ONLY
+ )
+ install(FILES ${_tmpdir}/${_install_jar_exports_FILE}
+ DESTINATION ${_install_jar_exports_DESTINATION}
+ ${_COMPONENT})
+endfunction()
diff --git a/Modules/javaTargets.cmake.in b/Modules/javaTargets.cmake.in
new file mode 100644
index 0000000..c5f9c78
--- /dev/null
+++ b/Modules/javaTargets.cmake.in
@@ -0,0 +1,39 @@
+cmake_minimum_required(VERSION 2.8)
+cmake_policy(PUSH)
+cmake_policy(VERSION 2.8)
+
+#----------------------------------------------------------------
+# Generated CMake Java target import file.
+#----------------------------------------------------------------
+
+# Protect against multiple inclusion, which would fail when already imported targets are added once more.
+set(_targetsDefined)
+set(_targetsNotDefined)
+set(_expectedTargets)
+foreach(_expectedTarget @__targets__@)
+ list(APPEND _expectedTargets ${_expectedTarget})
+ if(TARGET ${_expectedTarget})
+ list(APPEND _targetsDefined ${_expectedTarget})
+ else()
+ list(APPEND _targetsNotDefined ${_expectedTarget})
+ endif()
+endforeach()
+if("%${_targetsDefined}" STREQUAL "%${_expectedTargets}")
+ unset(_targetsDefined)
+ unset(_targetsNotDefined)
+ unset(_expectedTargets)
+ cmake_policy(POP)
+ return()
+endif()
+if(NOT "${_targetsDefined}" STREQUAL "")
+ message(FATAL_ERROR
+ "Some (but not all) targets in this export set were already defined.\n"
+ "Targets Defined: ${_targetsDefined}\n"
+ "Targets not yet defined: ${_targetsNotDefined}\n")
+endif()
+unset(_targetsDefined)
+unset(_targetsNotDefined)
+unset(_expectedTargets)
+
+@__targetdefs__@
+cmake_policy(POP)