diff options
author | Brad King <brad.king@kitware.com> | 2020-04-07 11:58:17 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-04-07 11:58:30 (GMT) |
commit | a4c873fc5dc5eb503fa608450a4dc571a76df37d (patch) | |
tree | 6fda8764b9fd3b3dd9791706678d8b90661a207b | |
parent | 38f293efabdb6fc876be02bb65f63826a3ec003b (diff) | |
parent | 4559eb490a5e2099808db33c35ef19eab19d2d94 (diff) | |
download | CMake-a4c873fc5dc5eb503fa608450a4dc571a76df37d.zip CMake-a4c873fc5dc5eb503fa608450a4dc571a76df37d.tar.gz CMake-a4c873fc5dc5eb503fa608450a4dc571a76df37d.tar.bz2 |
Merge topic 'UseJava-clean-stale'
4559eb490a UseJava: clean class files from previous builds
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Leonid Pospelov <pospelovlm@yandex.ru>
Merge-request: !4381
-rw-r--r-- | Modules/UseJava.cmake | 11 | ||||
-rw-r--r-- | Modules/UseJava/ClearClassFiles.cmake | 17 |
2 files changed, 26 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" ) diff --git a/Modules/UseJava/ClearClassFiles.cmake b/Modules/UseJava/ClearClassFiles.cmake new file mode 100644 index 0000000..f3115c6 --- /dev/null +++ b/Modules/UseJava/ClearClassFiles.cmake @@ -0,0 +1,17 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# This script deletes compiled Java class files. + +if(CMAKE_JAVA_CLASS_OUTPUT_PATH) + if(EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist") + file(STRINGS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist" classes) + list(TRANSFORM classes PREPEND "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/") + if(classes) + file(REMOVE ${classes}) + message(STATUS "Clean class files from previous build") + endif() + endif() +else() + message(FATAL_ERROR "Can't find CMAKE_JAVA_CLASS_OUTPUT_PATH") +endif() |