diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index 5ffba66a77..dae6cb5d13 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -465,6 +465,7 @@ qt_copy_or_install(FILES cmake/QtTargetHelpers.cmake cmake/QtTestHelpers.cmake cmake/QtToolHelpers.cmake + cmake/QtJavaHelpers.cmake DESTINATION "${__GlobalConfig_install_dir}" ) diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 92b4e7e400..3cb614d8a9 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -477,6 +477,7 @@ include(QtTargetHelpers) include(QtTestHelpers) include(QtToolHelpers) include(QtHeadersClean) +include(QtJavaHelpers) # This sets up the scope finalizer mechanism. variable_watch(CMAKE_CURRENT_LIST_DIR qt_watch_current_list_dir) diff --git a/cmake/QtJavaHelpers.cmake b/cmake/QtJavaHelpers.cmake new file mode 100644 index 0000000000..f362cb3863 --- /dev/null +++ b/cmake/QtJavaHelpers.cmake @@ -0,0 +1,18 @@ +# This function can be used to compile java sources into a jar package. + +function(qt_internal_add_jar target) + + set(javac_target_version "${QT_ANDROID_JAVAC_TARGET}") + if (NOT javac_target_version) + set(javac_target_version "8") + endif() + + set(javac_source_version "${QT_ANDROID_JAVAC_SOURCE}") + if (NOT javac_source_version) + set(javac_source_version "8") + endif() + + set(CMAKE_JAVA_COMPILE_FLAGS -source "${javac_source_version}" -target "${javac_target_version}" -Xlint:unchecked -bootclasspath "${QT_ANDROID_JAR}") + add_jar(${ARGV}) + +endfunction() diff --git a/cmake/QtProcessConfigureArgs.cmake b/cmake/QtProcessConfigureArgs.cmake index eac9bff144..44ac0cc341 100644 --- a/cmake/QtProcessConfigureArgs.cmake +++ b/cmake/QtProcessConfigureArgs.cmake @@ -556,6 +556,8 @@ endif() translate_string_input(platform QT_QMAKE_TARGET_MKSPEC) translate_string_input(xplatform QT_QMAKE_TARGET_MKSPEC) translate_string_input(qpa_default_platform QT_QPA_DEFAULT_PLATFORM) +translate_string_input(android-javac-source QT_ANDROID_JAVAC_SOURCE) +translate_string_input(android-javac-target QT_ANDROID_JAVAC_TARGET) drop_input(make) drop_input(nomake) diff --git a/cmake/configure-cmake-mapping.md b/cmake/configure-cmake-mapping.md index 780bbebef4..5a102f8d0e 100644 --- a/cmake/configure-cmake-mapping.md +++ b/cmake/configure-cmake-mapping.md @@ -96,6 +96,8 @@ The effort of this is tracked in QTBUG-85373 and QTBUG-85349. | -android-ndk-host | | | | -android-abis | | | | -android-style-assets | | | +| -android-javac-source | -DQT_ANDROID_JAVAC_SOURCE=7 | Set the javac build source version. | +| -android-javac-target | -DQT_ANDROID_JAVAC_TARGET=7 | Set the javac build target version. | | -skip | -DBUILD_=OFF | | | -make | -DBUILD_TESTING=ON | A way to turn on tools explicitly is missing. | | | -DBUILD_EXAMPLES=ON | | diff --git a/qt_cmdline.cmake b/qt_cmdline.cmake index 711dc599c6..8c0f2c5257 100644 --- a/qt_cmdline.cmake +++ b/qt_cmdline.cmake @@ -36,6 +36,8 @@ qt_commandline_option(android-ndk-host TYPE string) qt_commandline_option(android-ndk-platform TYPE string) qt_commandline_option(android-sdk TYPE string) qt_commandline_option(android-style-assets TYPE boolean) +qt_commandline_option(android-javac-target TYPE string) +qt_commandline_option(android-javac-source TYPE string) qt_commandline_option(appstore-compliant TYPE boolean) qt_commandline_option(avx TYPE boolean) qt_commandline_option(avx2 TYPE boolean) diff --git a/src/android/jar/.prev_CMakeLists.txt b/src/android/jar/.prev_CMakeLists.txt index e09f318aac..bff97e90ef 100644 --- a/src/android/jar/.prev_CMakeLists.txt +++ b/src/android/jar/.prev_CMakeLists.txt @@ -18,7 +18,7 @@ set(java_sources src/org/qtproject/qt5/android//QtThread.java ) -add_jar(QtAndroid +qt_internal_add_jar(QtAndroid INCLUDE_JARS ${QT_ANDROID_JAR} SOURCES ${java_sources} OUTPUT_DIR "${QT_BUILD_DIR}/jar" diff --git a/src/android/jar/CMakeLists.txt b/src/android/jar/CMakeLists.txt index c8beeba96d..0fb666bcb3 100644 --- a/src/android/jar/CMakeLists.txt +++ b/src/android/jar/CMakeLists.txt @@ -19,7 +19,7 @@ set(java_sources src/org/qtproject/qt5/android/QtServiceDelegate.java # special case ) -add_jar(QtAndroid +qt_internal_add_jar(QtAndroid INCLUDE_JARS ${QT_ANDROID_JAR} SOURCES ${java_sources} OUTPUT_DIR "${QT_BUILD_DIR}/jar" diff --git a/src/network/android/jar/CMakeLists.txt b/src/network/android/jar/CMakeLists.txt index 48f3d35e6f..c2635ec666 100644 --- a/src/network/android/jar/CMakeLists.txt +++ b/src/network/android/jar/CMakeLists.txt @@ -4,7 +4,7 @@ set(java_sources src/org/qtproject/qt5/android/network/QtNetwork.java ) -add_jar(QtAndroidNetwork +qt_internal_add_jar(QtAndroidNetwork INCLUDE_JARS ${QT_ANDROID_JAR} SOURCES ${java_sources} OUTPUT_DIR "${QT_BUILD_DIR}/jar" diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 3bd6b8c8d8..48af2b7462 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -3532,7 +3532,7 @@ def write_jar(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> str: cm_fh, scope, "", ["JAVASOURCES"], indent=indent, header=f"set(java_sources\n", footer=")\n" ) - cm_fh.write(f"{spaces(indent)}add_jar({target}\n") + cm_fh.write(f"{spaces(indent)}qt_internal_add_jar({target}\n") cm_fh.write(f"{spaces(indent+1)}INCLUDE_JARS {android_sdk_jar}\n") cm_fh.write(f"{spaces(indent+1)}SOURCES ${{java_sources}}\n") cm_fh.write(f'{spaces(indent+1)}OUTPUT_DIR "${{QT_BUILD_DIR}}/{install_dir}"\n')