diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/UseJava.cmake | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake index a5f8a08..120a54c 100644 --- a/Modules/UseJava.cmake +++ b/Modules/UseJava.cmake @@ -23,7 +23,8 @@ Creating And Installing JARs [VERSION <version>] [OUTPUT_NAME <name>] [OUTPUT_DIR <dir>] - [GENERATE_NATIVE_HEADERS <target> [DESTINATION <dir>]] + [GENERATE_NATIVE_HEADERS <target> + [DESTINATION (<dir>|INSTALL <dir> [BUILD <dir>])]] ) This command creates a ``<target_name>.jar``. It compiles the given @@ -37,7 +38,7 @@ For backwards compatibility, jar files listed as sources are ignored (as they have been since the first version of this module). .. versionadded:: 3.4 - Support fot response files (prefixed by ``@``) in the ``SOURCES`` list. + Support for response files (prefixed by ``@``) in the ``SOURCES`` list. The default ``OUTPUT_DIR`` can also be changed by setting the variable ``CMAKE_JAVA_TARGET_OUTPUT_DIR``. @@ -52,6 +53,12 @@ The default ``OUTPUT_DIR`` can also be changed by setting the variable ``GENERATE_NATIVE_HEADERS`` option requires, at least, version 1.8 of the JDK. +.. versionadded:: 3.20 + ``DESTINATION`` sub-option now supports the possibility to specify different + output directories for ``BUILD`` and ``INSTALL`` steps. This is required to + export the interface target generated by ``GENERATE_NATIVE_HEADERS`` option. + If ``BUILD`` directory is not specified, a default directory will be used. + The ``add_jar()`` function sets the following target properties on ``<target_name>``: @@ -66,6 +73,11 @@ The ``add_jar()`` function sets the following target properties on The directory where the class files can be found. For example to use them with ``javah``. +.. versionadded:: 3.20 + The target generated by option ``GENERATE_NATIVE_HEADERS`` has the property + ``NATIVE_HEADERS_DIRECTORY`` which specify the directory holding the native + headers. + .. code-block:: cmake install_jar(<target_name> <destination>) @@ -217,6 +229,18 @@ native headers can then be used to compile C/C++ sources with the add_library(bar bar.cpp) target_link_libraries(bar PRIVATE foo-native) +.. versionadded:: 3.20 + It is now possible to export the target generated by + ``GENERATE_NATIVE_HEADERS`` option. + + .. code-block:: cmake + + add_jar(foo foo.java GENERATE_NATIVE_HEADERS foo-native + DESTINATION INSTALL include) + install(TARGETS foo-native EXPORT native) + install(DIRECTORY "$<TARGET_PROPERTY:foo-native,NATIVE_HEADERS_DIRECTORY>/" + DESTINATION include) + install(EXPORT native DESTINATION /to/export NAMESPACE foo) Finding JARs ^^^^^^^^^^^^ @@ -493,7 +517,10 @@ function(add_jar _TARGET_NAME) if (Java_VERSION VERSION_LESS 1.8) message (FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS is not supported with this version of Java.") endif() - cmake_parse_arguments (_add_jar_GENERATE_NATIVE_HEADERS "" "DESTINATION" "" ${_add_jar_GENERATE_NATIVE_HEADERS}) + + unset (_GENERATE_NATIVE_HEADERS_OUTPUT_DESC) + + cmake_parse_arguments (_add_jar_GENERATE_NATIVE_HEADERS "" "" "DESTINATION" ${_add_jar_GENERATE_NATIVE_HEADERS}) if (NOT _add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS) message (FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: missing required argument.") endif() @@ -504,11 +531,30 @@ function(add_jar _TARGET_NAME) endif() if (NOT _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION) set (_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir/native_headers") + else() + list (LENGTH _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION length) + if (NOT length EQUAL 1) + cmake_parse_arguments (_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION "" "BUILD;INSTALL" "" "${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION}") + if (_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_UNPARSED_ARGUMENTS) + message (FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: DESTINATION: ${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_UNPARSED_ARGUMENTS}: unexpected argument(s).") + endif() + if (NOT _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_INSTALL) + message (FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: DESTINATION: INSTALL sub-option is required.") + endif() + if (NOT _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_BUILD) + set(_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_BUILD "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir/native_headers") + endif() + set(_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION "${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_BUILD}") + set(_GENERATE_NATIVE_HEADERS_OUTPUT_DESC "$<BUILD_INTERFACE:${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_BUILD}>" "$<INSTALL_INTERFACE:${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_INSTALL}>") + endif() endif() set (_GENERATE_NATIVE_HEADERS_TARGET ${_add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS}) set (_GENERATE_NATIVE_HEADERS_OUTPUT_DIR "${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION}") set (_GENERATE_NATIVE_HEADERS -h "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}") + if(NOT _GENERATE_NATIVE_HEADERS_OUTPUT_DESC) + set(_GENERATE_NATIVE_HEADERS_OUTPUT_DESC "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}") + endif() endif() if (LIBRARY_OUTPUT_PATH) @@ -762,8 +808,9 @@ function(add_jar _TARGET_NAME) # create an INTERFACE library encapsulating include directory for generated headers add_library (${_GENERATE_NATIVE_HEADERS_TARGET} INTERFACE) target_include_directories (${_GENERATE_NATIVE_HEADERS_TARGET} INTERFACE - "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}" + "${_GENERATE_NATIVE_HEADERS_OUTPUT_DESC}" ${JNI_INCLUDE_DIRS}) + set_property(TARGET ${_GENERATE_NATIVE_HEADERS_TARGET} PROPERTY NATIVE_HEADERS_DIRECTORY "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}") # this INTERFACE library depends on jar generation add_dependencies (${_GENERATE_NATIVE_HEADERS_TARGET} ${_TARGET_NAME}) |