summaryrefslogtreecommitdiffstats
path: root/config/cmake
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2016-09-15 18:32:01 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2016-09-15 18:32:01 (GMT)
commit04634520cf0ee5ef0b9ef145822083b7b7eced2a (patch)
tree5a51f5871889452c0f524272380d4ac5e92c51bf /config/cmake
parent052efd9bde06ea2427beffd3ea493cbc53a17608 (diff)
downloadhdf5-04634520cf0ee5ef0b9ef145822083b7b7eced2a.zip
hdf5-04634520cf0ee5ef0b9ef145822083b7b7eced2a.tar.gz
hdf5-04634520cf0ee5ef0b9ef145822083b7b7eced2a.tar.bz2
Update CMake java functions
Diffstat (limited to 'config/cmake')
-rw-r--r--config/cmake/FindJNI.cmake31
-rw-r--r--config/cmake/UseJava.cmake175
2 files changed, 189 insertions, 17 deletions
diff --git a/config/cmake/FindJNI.cmake b/config/cmake/FindJNI.cmake
index 440a9889..9105f3d 100644
--- a/config/cmake/FindJNI.cmake
+++ b/config/cmake/FindJNI.cmake
@@ -63,7 +63,7 @@ macro(java_append_library_directories _var)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
set(_java_libarch "ppc64" "ppc")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
- set(_java_libarch "ppc")
+ set(_java_libarch "ppc" "ppc64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
# Both flavours can run on the same processor
set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "sparc" "sparcv9")
@@ -92,10 +92,14 @@ macro(java_append_library_directories _var)
if(_path MATCHES "{libarch}")
foreach(_libarch ${_java_libarch})
string(REPLACE "{libarch}" "${_libarch}" _newpath "${_path}")
- list(APPEND ${_var} "${_newpath}")
+ if(EXISTS ${_newpath})
+ list(APPEND ${_var} "${_newpath}")
+ endif()
endforeach()
else()
- list(APPEND ${_var} "${_path}")
+ if(EXISTS ${_path})
+ list(APPEND ${_var} "${_path}")
+ endif()
endif()
endforeach()
endmacro()
@@ -161,6 +165,10 @@ JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
/usr/lib/jvm/default-java/jre/lib/{libarch}
/usr/lib/jvm/default-java/jre/lib
/usr/lib/jvm/default-java/lib
+ # Ubuntu specific paths for default JVM
+ /usr/lib/jvm/java-8-openjdk-{libarch}/jre/lib/{libarch} # Ubuntu 15.10
+ /usr/lib/jvm/java-7-openjdk-{libarch}/jre/lib/{libarch} # Ubuntu 15.10
+ /usr/lib/jvm/java-6-openjdk-{libarch}/jre/lib/{libarch} # Ubuntu 15.10
# OpenBSD specific paths for default JVM
/usr/local/jdk-1.7.0/jre/lib/{libarch}
/usr/local/jre-1.7.0/lib/{libarch}
@@ -191,6 +199,9 @@ list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
+)
+
+JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_INCLUDE_DIRECTORIES
${_JAVA_HOME}/include
/usr/include
/usr/java/include
@@ -209,6 +220,9 @@ list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES
/usr/lib/jvm/java-7-openjdk-amd64/include
/usr/lib64/jvm/java-7-openjdk/include
/usr/lib64/jvm/java-7-openjdk-amd64/include
+ /usr/lib/jvm/java-8-openjdk-{libarch}/include # ubuntu 15.10
+ /usr/lib/jvm/java-7-openjdk-{libarch}/include # ubuntu 15.10
+ /usr/lib/jvm/java-6-openjdk-{libarch}/include # ubuntu 15.10
/usr/local/share/java/include
/usr/lib/j2sdk1.4-sun/include
/usr/lib/j2sdk1.5-sun/include
@@ -290,7 +304,8 @@ find_path(JAVA_INCLUDE_PATH jni.h
${JAVA_AWT_INCLUDE_DIRECTORIES}
)
-find_path(JAVA_INCLUDE_PATH2 jni_md.h
+find_path(JAVA_INCLUDE_PATH2 NAMES jni_md.h jniport.h
+ PATHS
${JAVA_INCLUDE_PATH}
${JAVA_INCLUDE_PATH}/darwin
${JAVA_INCLUDE_PATH}/win32
@@ -300,6 +315,7 @@ find_path(JAVA_INCLUDE_PATH2 jni_md.h
${JAVA_INCLUDE_PATH}/solaris
${JAVA_INCLUDE_PATH}/hp-ux
${JAVA_INCLUDE_PATH}/alpha
+ ${JAVA_INCLUDE_PATH}/aix
)
find_path(JAVA_AWT_INCLUDE_PATH jawt.h
@@ -316,8 +332,11 @@ endif()
#include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
INCLUDE (FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(JNI DEFAULT_MSG JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
- JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(JNI DEFAULT_MSG JAVA_AWT_LIBRARY
+ JAVA_JVM_LIBRARY
+ JAVA_INCLUDE_PATH
+ JAVA_INCLUDE_PATH2
+ JAVA_AWT_INCLUDE_PATH)
mark_as_advanced(
JAVA_AWT_LIBRARY
diff --git a/config/cmake/UseJava.cmake b/config/cmake/UseJava.cmake
index 9b2b1e0..354cfc1 100644
--- a/config/cmake/UseJava.cmake
+++ b/config/cmake/UseJava.cmake
@@ -169,7 +169,7 @@
#
# ::
#
-# The add_jar() functions sets some target properties. You can get these
+# The add_jar() function sets some target properties. You can get these
# properties with the
# get_property(TARGET <target_name> PROPERTY <propery_name>)
# command.
@@ -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>]
@@ -324,7 +355,7 @@
# that allow your Java and C code to interact.
#
# There are two main signatures for create_javah. The first signature
-# returns generated files throught variable specified by GENERATED_FILES option:
+# returns generated files through variable specified by GENERATED_FILES option:
#
# ::
#
@@ -389,14 +420,36 @@ include(CMakeParseArguments)
function (__java_copy_file src dest comment)
add_custom_command(
OUTPUT ${dest}
- COMMAND cmake -E copy_if_different
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
ARGS ${src}
${dest}
DEPENDS ${src}
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)
@@ -467,7 +522,7 @@ function(add_jar _TARGET_NAME)
endif()
foreach (JAVA_INCLUDE_DIR ${CMAKE_JAVA_INCLUDE_PATH})
- set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${JAVA_INCLUDE_DIR}")
+ string(APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_FLAG_SEP}${JAVA_INCLUDE_DIR}")
endforeach()
set(CMAKE_JAVA_CLASS_OUTPUT_PATH "${_add_jar_OUTPUT_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir")
@@ -539,7 +594,7 @@ function(add_jar _TARGET_NAME)
if (TARGET ${_JAVA_INCLUDE_JAR})
get_target_property(_JAVA_JAR_PATH ${_JAVA_INCLUDE_JAR} JAR_FILE)
if (_JAVA_JAR_PATH)
- set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_JAR_PATH}")
+ string(APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_JAR_PATH}")
list(APPEND CMAKE_JAVA_INCLUDE_PATH ${_JAVA_JAR_PATH})
list(APPEND _JAVA_DEPENDS ${_JAVA_INCLUDE_JAR})
list(APPEND _JAVA_COMPILE_DEPENDS ${_JAVA_INCLUDE_JAR})
@@ -547,18 +602,13 @@ function(add_jar _TARGET_NAME)
message(SEND_ERROR "add_jar: INCLUDE_JARS target ${_JAVA_INCLUDE_JAR} is not a jar")
endif ()
else ()
- set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_INCLUDE_JAR}")
+ string(APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_INCLUDE_JAR}")
list(APPEND CMAKE_JAVA_INCLUDE_PATH "${_JAVA_INCLUDE_JAR}")
list(APPEND _JAVA_DEPENDS "${_JAVA_INCLUDE_JAR}")
list(APPEND _JAVA_COMPILE_DEPENDS "${_JAVA_INCLUDE_JAR}")
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(
@@ -1348,3 +1410,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()