Merge topic 'use-java-INCLUDE_JARS'
8a2fca8
UseJava.cmake: require explicit request to include jars
This commit is contained in:
commit
9852d8f42b
|
@ -3,11 +3,19 @@
|
|||
# has already been loaded. See FindJava.cmake for information on how to
|
||||
# load Java into your CMake project.
|
||||
#
|
||||
# add_jar(TARGET_NAME SRC1 SRC2 .. SRCN RCS1 RCS2 .. RCSN)
|
||||
# add_jar(target_name
|
||||
# [SOURCES] source1 [source2 ...] [resource1 ...]
|
||||
# [INCLUDE_JARS jar1 [jar2 ...]]
|
||||
# )
|
||||
#
|
||||
# This command creates a <TARGET_NAME>.jar. It compiles the given source
|
||||
# files (SRC) and adds the given resource files (RCS) to the jar file.
|
||||
# If only resource files are given then just a jar file is created.
|
||||
# This command creates a <target_name>.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 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 backwards compatibility, jar files
|
||||
# listed as sources are ignored (as they have been since the first version of
|
||||
# this module).
|
||||
#
|
||||
# Additional instructions:
|
||||
# To add compile flags to the target you can set these flags with
|
||||
|
@ -190,6 +198,8 @@
|
|||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
|
||||
|
||||
function (__java_copy_file src dest comment)
|
||||
add_custom_command(
|
||||
OUTPUT ${dest}
|
||||
|
@ -205,7 +215,10 @@ set(_JAVA_CLASS_FILELIST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaClassFilelist.c
|
|||
set(_JAVA_SYMLINK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaSymlinks.cmake)
|
||||
|
||||
function(add_jar _TARGET_NAME)
|
||||
set(_JAVA_SOURCE_FILES ${ARGN})
|
||||
|
||||
cmake_parse_arguments(_add_jar "" "" "SOURCES;INCLUDE_JARS" ${ARGN})
|
||||
|
||||
set(_JAVA_SOURCE_FILES ${_add_jar_SOURCES} ${_add_jar_UNPARSED_ARGUMENTS})
|
||||
|
||||
if (NOT DEFINED CMAKE_JAVA_TARGET_OUTPUT_DIR)
|
||||
set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
@ -265,14 +278,7 @@ function(add_jar _TARGET_NAME)
|
|||
get_filename_component(_JAVA_PATH ${_JAVA_SOURCE_FILE} PATH)
|
||||
get_filename_component(_JAVA_FULL ${_JAVA_SOURCE_FILE} ABSOLUTE)
|
||||
|
||||
if (TARGET ${_JAVA_SOURCE_FILE})
|
||||
get_target_property(_JAVA_JAR_PATH ${_JAVA_SOURCE_FILE} JAR_FILE)
|
||||
set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${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_SOURCE_FILE})
|
||||
list(APPEND _JAVA_COMPILE_DEPENDS ${_JAVA_SOURCE_FILE})
|
||||
|
||||
elseif (_JAVA_EXT MATCHES ".java")
|
||||
if (_JAVA_EXT MATCHES ".java")
|
||||
file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${CMAKE_JAVA_TARGET_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)
|
||||
|
@ -292,10 +298,7 @@ function(add_jar _TARGET_NAME)
|
|||
OR _JAVA_EXT MATCHES ".war"
|
||||
OR _JAVA_EXT MATCHES ".ear"
|
||||
OR _JAVA_EXT MATCHES ".sar")
|
||||
set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_SOURCE_FILE}")
|
||||
list(APPEND CMAKE_JAVA_INCLUDE_PATH ${_JAVA_SOURCE_FILE})
|
||||
list(APPEND _JAVA_DEPENDS ${_JAVA_SOURCE_FILE})
|
||||
list(APPEND _JAVA_COMPILE_DEPENDS ${_JAVA_SOURCE_FILE})
|
||||
# Ignored for backward compatibility
|
||||
|
||||
elseif (_JAVA_EXT STREQUAL "")
|
||||
list(APPEND CMAKE_JAVA_INCLUDE_PATH ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}} ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}_CLASSPATH})
|
||||
|
@ -309,6 +312,25 @@ function(add_jar _TARGET_NAME)
|
|||
endif ()
|
||||
endforeach()
|
||||
|
||||
foreach(_JAVA_INCLUDE_JAR ${_add_jar_INCLUDE_JARS})
|
||||
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}")
|
||||
list(APPEND CMAKE_JAVA_INCLUDE_PATH ${_JAVA_JAR_PATH})
|
||||
list(APPEND _JAVA_DEPENDS ${_JAVA_INCLUDE_JAR})
|
||||
list(APPEND _JAVA_COMPILE_DEPENDS ${_JAVA_INCLUDE_JAR})
|
||||
else ()
|
||||
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}")
|
||||
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 "")
|
||||
|
|
Loading…
Reference in New Issue