diff options
author | Alexey Karndshev <alexey@quobyte.com> | 2020-02-21 10:46:40 (GMT) |
---|---|---|
committer | Alexey Karandashev <reflectored@gmail.com> | 2020-04-06 14:58:10 (GMT) |
commit | 4559eb490a5e2099808db33c35ef19eab19d2d94 (patch) | |
tree | 7a0471e2212e1b09dc55abfb69dd3fb8aed5fcf2 /Modules/UseJava.cmake | |
parent | 25ca8e5ce5019c0fb8648f7408b864add6b19d83 (diff) | |
download | CMake-4559eb490a5e2099808db33c35ef19eab19d2d94.zip CMake-4559eb490a5e2099808db33c35ef19eab19d2d94.tar.gz CMake-4559eb490a5e2099808db33c35ef19eab19d2d94.tar.bz2 |
UseJava: clean class files from previous builds
If java_class_filelist exists, remove previous class files before building the
new ones. If java_sources content has changed, clean and rebuild the class
files of the target.
Fixes: #20377
Diffstat (limited to 'Modules/UseJava.cmake')
-rw-r--r-- | Modules/UseJava.cmake | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake index b668b9e..9177d16 100644 --- a/Modules/UseJava.cmake +++ b/Modules/UseJava.cmake @@ -597,7 +597,10 @@ function(add_jar _TARGET_NAME) # 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}) + set(CMAKE_CONFIGURABLE_FILE_CONTENT "${_JAVA_COMPILE_STRING}") + configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in" + "${_JAVA_SOURCES_FILE}" @ONLY) + unset(CMAKE_CONFIGURABLE_FILE_CONTENT) list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_SOURCES_FILE}") endif() if (_JAVA_COMPILE_FILELISTS) @@ -610,6 +613,10 @@ function(add_jar _TARGET_NAME) add_custom_command( # NOTE: this command generates an artificial dependency file OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME} + COMMAND ${CMAKE_COMMAND} + -DCMAKE_JAVA_CLASS_OUTPUT_PATH=${CMAKE_JAVA_CLASS_OUTPUT_PATH} + -DCMAKE_JAR_CLASSES_PREFIX="${CMAKE_JAR_CLASSES_PREFIX}" + -P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/UseJava/ClearClassFiles.cmake COMMAND ${Java_JAVAC_EXECUTABLE} ${CMAKE_JAVA_COMPILE_FLAGS} -classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}" @@ -617,7 +624,7 @@ function(add_jar _TARGET_NAME) ${_GENERATE_NATIVE_HEADERS} ${_JAVA_SOURCES_FILELISTS} COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME} - DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_FILELISTS} ${_JAVA_COMPILE_DEPENDS} + DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_FILELISTS} ${_JAVA_COMPILE_DEPENDS} ${_JAVA_SOURCES_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Building Java objects for ${_TARGET_NAME}.jar" ) |