From 3fa2cda8a0239751fc52a3c01ad3f0da4b037a28 Mon Sep 17 00:00:00 2001 From: janbar Date: Tue, 6 Aug 2024 20:05:55 +0200 Subject: [PATCH] cleanup cmake project --- .../workflows/build_android_arm64_ndk22.yml | 4 - .github/workflows/build_android_x64_ndk22.yml | 4 - .github/workflows/build_android_x86_ndk22.yml | 4 - CMakeLists.txt | 110 +++++------ android/AddQtAndroidApk.cmake | 177 ++++++------------ android/linux-build-arm64-qt515.sh | 5 - android/linux-build-armv7-qt515.sh | 7 +- android/linux-build-x64-qt515.sh | 7 +- android/linux-build-x86-qt515.sh | 7 +- android/qtdeploy.json.in | 20 +- cmake/qtchooser.cmake | 38 ++++ 11 files changed, 162 insertions(+), 221 deletions(-) create mode 100644 cmake/qtchooser.cmake diff --git a/.github/workflows/build_android_arm64_ndk22.yml b/.github/workflows/build_android_arm64_ndk22.yml index 21cdb4e2..8448b9cf 100644 --- a/.github/workflows/build_android_arm64_ndk22.yml +++ b/.github/workflows/build_android_arm64_ndk22.yml @@ -58,17 +58,13 @@ jobs: -DCMAKE_TOOLCHAIN_FILE=${ANDROID_HOME}/ndk/22.1.7171670/build/cmake/android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=${ANDROID_HOME}/ndk/22.1.7171670/prebuilt/linux-x86_64/bin/make -DANDROID_ABI=arm64-v8a - -DANDROID_STL_PREFIX=llvm-libc++ - -DANDROID_STL_SHARED_LIBRARIES=c++_shared -DANDROID_SDK_MINVER=24 -DANDROID_SDK_TARGET=26 -DANDROID_NATIVE_API_LEVEL=24 -DQT_ANDROID_PLATFORM_LEVEL=29 -DQT_ANDROID_SDK_BUILDTOOLS_REVISION=29.0.2 - -DQT_ANDROID_TOOL_PREFIX=aarch64-linux-android -DQT_ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT} -DQT_ANDROID_NDK_ROOT=${ANDROID_HOME}/ndk/22.1.7171670 - -DQT_ANDROID_QT_ROOT=${Qt5_DIR} -DQt5_DIR=${Qt5_DIR}/lib/cmake/Qt5 -DQt5Core_DIR=${Qt5_DIR}/lib/cmake/Qt5Core -DQt5Gui_DIR=${Qt5_DIR}/lib/cmake/Qt5Gui diff --git a/.github/workflows/build_android_x64_ndk22.yml b/.github/workflows/build_android_x64_ndk22.yml index 1be5434a..ae419689 100644 --- a/.github/workflows/build_android_x64_ndk22.yml +++ b/.github/workflows/build_android_x64_ndk22.yml @@ -60,17 +60,13 @@ jobs: -DCMAKE_TOOLCHAIN_FILE=${ANDROID_HOME}/ndk/22.1.7171670/build/cmake/android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=${ANDROID_HOME}/ndk/22.1.7171670/prebuilt/linux-x86_64/bin/make -DANDROID_ABI=x86_64 - -DANDROID_STL_PREFIX=llvm-libc++ - -DANDROID_STL_SHARED_LIBRARIES=c++_shared -DANDROID_SDK_MINVER=24 -DANDROID_SDK_TARGET=26 -DANDROID_NATIVE_API_LEVEL=24 -DQT_ANDROID_PLATFORM_LEVEL=29 -DQT_ANDROID_SDK_BUILDTOOLS_REVISION=29.0.2 - -DQT_ANDROID_TOOL_PREFIX=x86_64-linux-android -DQT_ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT} -DQT_ANDROID_NDK_ROOT=${ANDROID_HOME}/ndk/22.1.7171670 - -DQT_ANDROID_QT_ROOT=${Qt5_DIR} -DQt5_DIR=${Qt5_DIR}/lib/cmake/Qt5 -DQt5Core_DIR=${Qt5_DIR}/lib/cmake/Qt5Core -DQt5Gui_DIR=${Qt5_DIR}/lib/cmake/Qt5Gui diff --git a/.github/workflows/build_android_x86_ndk22.yml b/.github/workflows/build_android_x86_ndk22.yml index f858a658..1243c152 100644 --- a/.github/workflows/build_android_x86_ndk22.yml +++ b/.github/workflows/build_android_x86_ndk22.yml @@ -58,17 +58,13 @@ jobs: -DCMAKE_TOOLCHAIN_FILE=${ANDROID_HOME}/ndk/22.1.7171670/build/cmake/android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=${ANDROID_HOME}/ndk/22.1.7171670/prebuilt/linux-x86_64/bin/make -DANDROID_ABI=x86 - -DANDROID_STL_PREFIX=llvm-libc++ - -DANDROID_STL_SHARED_LIBRARIES=c++_shared -DANDROID_SDK_MINVER=24 -DANDROID_SDK_TARGET=26 -DANDROID_NATIVE_API_LEVEL=24 -DQT_ANDROID_PLATFORM_LEVEL=29 -DQT_ANDROID_SDK_BUILDTOOLS_REVISION=29.0.2 - -DQT_ANDROID_TOOL_PREFIX=i686-linux-android -DQT_ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT} -DQT_ANDROID_NDK_ROOT=${ANDROID_HOME}/ndk/22.1.7171670 - -DQT_ANDROID_QT_ROOT=${Qt5_DIR} -DQt5_DIR=${Qt5_DIR}/lib/cmake/Qt5 -DQt5Core_DIR=${Qt5_DIR}/lib/cmake/Qt5Core -DQt5Gui_DIR=${Qt5_DIR}/lib/cmake/Qt5Gui diff --git a/CMakeLists.txt b/CMakeLists.txt index d2969770..4759afa1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,19 +94,28 @@ else() set(CMAKE_IGNORE_PATH "/opt/local/bin;/opt/local/include;/opt/local/lib") endif() -# Workaround for QTBUG-87863 before calling add_subirectory -find_package(Qt5 COMPONENTS Core REQUIRED) +set(QT_VERSION_PREFERRED "5" CACHE STRING "preferred Qt version" FORCE) +include(qtchooser) +if(NOT QT_FOUND) + message(FATAL_ERROR "Qt${QT_VERSION_PREFERRED} NOT found") +elseif(Qt5Core_VERSION VERSION_LESS 5.15.2) + message(FATAL_ERROR "Qt version not supported") +endif() add_subdirectory(backend) set(CMAKE_AUTOMOC ON) -find_package(Qt5Core REQUIRED) -find_package(Qt5Gui REQUIRED) -find_package(Qt5Qml REQUIRED) -find_package(Qt5Quick REQUIRED) - -set(QT_MIN_VERSION 5.15.0) -find_package(Qt5QuickControls2 ${QT_MIN_VERSION} REQUIRED) +find_package(Qt5 ${QT_VERSION} COMPONENTS + Core Gui Qml Quick QuickControls2 Widgets Xml Svg Network Sensors + Multimedia RemoteObjects Positioning REQUIRED) +if(UNIX AND NOT APPLE) + find_library(DBUS_LIBRARIES dbus-1) + if(DBUS_LIBRARIES) + find_package(Qt5 ${QT_VERSION} COMPONENTS DBus REQUIRED) + set(HAVE_DBUS 1) + message(STATUS "Enable DBus interfaces") + endif() +endif() if(ANDROID) find_package(Qt5AndroidExtras REQUIRED) @@ -119,15 +128,6 @@ elseif(UNIX AND NOT APPLE) endif() endif() -find_package(Qt5Widgets REQUIRED) -find_package(Qt5Xml REQUIRED) -find_package(Qt5Svg REQUIRED) -find_package(Qt5Network REQUIRED) -find_package(Qt5Sensors REQUIRED) -find_package(Qt5Multimedia REQUIRED) -find_package(Qt5RemoteObjects REQUIRED) -find_package(Qt5Positioning REQUIRED) - set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD 17) @@ -180,17 +180,13 @@ if(UNIX) endif() add_definitions(-DAPP_VERSION="${APP_VERSION}") +add_definitions(-DQT_STATICPLUGIN) -if(Qt5Core_VERSION VERSION_LESS 5.15.2) - message(FATAL_ERROR "Qt version not supported") -else() - qt5_add_resources(osmin-resources gui/osmin_controls2_515.qrc) -endif() +include_directories(${PROJECT_BINARY_DIR} ${LIBOSMSCOUT_INCLUDE_DIRS}) qt5_generate_repc(osmin_SOURCES src/servicemessenger.rep SOURCE) qt5_generate_repc(osmin_SOURCES src/servicemessenger.rep REPLICA) - -include_directories(${PROJECT_BINARY_DIR} ${LIBOSMSCOUT_INCLUDE_DIRS}) +qt5_add_resources(osmin-resources gui/osmin_controls2_515.qrc) if(ANDROID) add_library(osmin SHARED ${osmin_SOURCES} ${osmin_HEADERS} ${osmin-resources}) @@ -199,32 +195,21 @@ else() endif() target_link_libraries(osmin PRIVATE ${LIBOSMSCOUT_LIBRARIES}) - -add_definitions(-DQT_STATICPLUGIN) +target_link_libraries(osmin PRIVATE + Qt5::QuickControls2 Qt5::RemoteObjects Qt5::Positioning + Qt5::Qml Qt5::Quick Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Svg + Qt5::Network Qt5::Sensors Qt5::Multimedia Qt5::Core) if(ANDROID) add_definitions(-DDEVICE_MOBILE) add_definitions(-frtti) # dynamic_cast: https://github.com/android/ndk/issues/519 - target_link_libraries(osmin PRIVATE Qt5::QuickControls2 Qt5::AndroidExtras android log Qt5::RemoteObjects Qt5::Positioning - Qt5::Qml Qt5::Quick Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Svg Qt5::Network Qt5::Sensors Qt5::Multimedia Qt5::Core) -else() - if(BUILD_DEVICE_MOBILE) - add_definitions(-DDEVICE_MOBILE) - endif() - target_link_libraries(osmin PRIVATE Qt5::QuickControls2 Qt5::RemoteObjects Qt5::Positioning - Qt5::Qml Qt5::Quick Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Svg Qt5::Network Qt5::Sensors Qt5::Multimedia Qt5::Core) - if(HAVE_DBUS) - add_definitions(-DHAVE_DBUS) - target_link_libraries(osmin PRIVATE Qt5::DBus) - endif() -endif() - -if(ANDROID) + target_link_libraries(osmin PRIVATE Qt5::AndroidExtras android log) # Fix import of shared omp with android ndk rev 21 if(OpenMP_CXX_LIBRARIES MATCHES libomp.so) set(SHARED_LIBOMP ${OpenMP_CXX_LIBRARIES}) endif() add_dependencies(osmin ssl crypto) + include(android/AddQtAndroidApk.cmake) add_qt_android_apk(osmin-apk osmin NAME ${APP_NAME} @@ -233,11 +218,19 @@ if(ANDROID) PACKAGE_SOURCES ${PROJECT_SOURCE_DIR}/android/package-sources BUILDTOOLS_REVISION ${QT_ANDROID_SDK_BUILDTOOLS_REVISION} DEPENDS ssl crypto ${SHARED_LIBOMP} - PLUGINS ${PROJECT_SOURCE_DIR}/resources + ASSETS ${PROJECT_SOURCE_DIR}/resources KEYSTORE ${KEYSTORE_FILE} ${KEYSTORE_ALIAS} KEYSTORE_PASSWORD ${KEYSTORE_PASSWORD} ) else() + if(BUILD_DEVICE_MOBILE) + add_definitions(-DDEVICE_MOBILE) + endif() + if(HAVE_DBUS) + add_definitions(-DHAVE_DBUS) + target_link_libraries(osmin PRIVATE Qt5::DBus) + endif() + set_target_properties(osmin PROPERTIES OUTPUT_NAME "${EXEC}") install(TARGETS osmin RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) file(COPY "resources" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) @@ -245,21 +238,18 @@ else() DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/resources DESTINATION ${CMAKE_INSTALL_DATADIR}/${EXEC} ) + add_custom_target( + "run" + QML2_IMPORT_PATH=${CMAKE_BINARY_DIR}/backend/qml ${CMAKE_BINARY_DIR}/${EXEC} --debug + DEPENDS osmin + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY + ) + add_custom_target( + "uninstall" + ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake + ) endif() - -add_custom_target( - "run" - QML2_IMPORT_PATH=${CMAKE_BINARY_DIR}/backend/qml ${CMAKE_BINARY_DIR}/${EXEC} --debug - DEPENDS osmin - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} -) - -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY -) - -add_custom_target( - "uninstall" - ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake -) diff --git a/android/AddQtAndroidApk.cmake b/android/AddQtAndroidApk.cmake index 6749b2f4..ad83a0ac 100755 --- a/android/AddQtAndroidApk.cmake +++ b/android/AddQtAndroidApk.cmake @@ -7,17 +7,14 @@ cmake_minimum_required(VERSION 3.8.2) # env ANDROID_SDK The SDK root path # env ANDROID_NDK The NDK root path # env JAVA_HOME Path Java JRE supported by SDK +# # ANDROID_ABI "arm64-v8a" # ANDROID_NATIVE_API_LEVEL SDK API (i.e 24) # ANDROID_STL_PREFIX "llvm-libc++" -# QT_ANDROID_QT_ROOT The Qt root path # QT_ANDROID_PLATFORM_LEVEL SDK platform (i.e 29) -# QT_ANDROID_TOOL_PREFIX Build tools prefix ("aarch64-linux-android") -# [ANDROID_SDK_MINVER] = ANDROID_NATIVE_API_LEVEL -# [ANDROID_SDK_TARGET] = ANDROID_SDK_MINVER -# [ANDROID_STL_SHARED_LIBRARIES] = "c++_shared" (option for NDK <= r18) -# [QT_ANDROID_SDK_ROOT] = env ANDROID_SDK -# [QT_ANDROID_NDK_ROOT] = env ANDROID_NDK +# QT_ANDROID_ARCHITECTURE Architecture (i.e "aarch64-linux-android") +# ANDROID_SDK_MINVER Default ANDROID_NATIVE_API_LEVEL +# ANDROID_SDK_TARGET Default ANDROID_NATIVE_API_LEVEL # store the current source directory for future use set(QT_ANDROID_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}) @@ -34,12 +31,12 @@ if(NOT ANDROID) message(FATAL_ERROR "Trying to use the CMake Android package without the Android toolchain. Please use the provided toolchain (toolchain/android.toolchain.cmake)") endif() -# find the Qt root directory +# find the Qt directory if(NOT Qt5Core_DIR) find_package(Qt5Core REQUIRED) endif() -get_filename_component(QT_ANDROID_QT_ROOT "${Qt5Core_DIR}/../../.." ABSOLUTE) -message(STATUS "Found Qt for Android: ${QT_ANDROID_QT_ROOT}") +get_filename_component(QT_ANDROID_QT_DIR "${Qt5Core_DIR}/../../.." ABSOLUTE) +message(STATUS "Found Qt for Android: ${QT_ANDROID_QT_DIR}") # find the Android SDK if(NOT QT_ANDROID_SDK_ROOT) @@ -64,6 +61,22 @@ endif() string(REPLACE "\\" "/" QT_ANDROID_NDK_ROOT ${QT_ANDROID_NDK_ROOT}) # androiddeployqt doesn't like backslashes in paths message(STATUS "Found Android NDK: ${QT_ANDROID_NDK_ROOT}") +# find the Android architecture +if(NOT QT_ANDROID_ARCHITECTURE) + if("${ANDROID_ABI}" STREQUAL "arm64-v8a") + set(QT_ANDROID_ARCHITECTURE "aarch64-linux-android") + elseif("${ANDROID_ABI}" STREQUAL "armeabi-v7a") + set(QT_ANDROID_ARCHITECTURE "arm-linux-androideabi") + elseif("${ANDROID_ABI}" STREQUAL "x86_64") + set(QT_ANDROID_ARCHITECTURE "x86_64-linux-android") + elseif("${ANDROID_ABI}" STREQUAL "x86") + set(QT_ANDROID_ARCHITECTURE "i686-linux-android") + endif() + if(NOT QT_ANDROID_ARCHITECTURE) + message(FATAL_ERROR "Please set the QT_ANDROID_ARCHITECTURE CMake variable") + endif() +endif() + include(CMakeParseArguments) # define a macro to create an Android APK target @@ -73,28 +86,31 @@ include(CMakeParseArguments) # NAME "My App" # VERSION_CODE 12 # PACKAGE_NAME "org.mycompany.myapp" -# PACKAGE_SOURCES ${CMAKE_CURRENT_LIST_DIR}/my-android-sources +# PACKAGE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/package-sources # BUILDTOOLS_REVISION "23.0.3" # KEYSTORE ${CMAKE_CURRENT_LIST_DIR}/mykey.keystore myalias # KEYSTORE_PASSWORD xxxx # DEPENDS a_linked_target "path/to/a_linked_library.so" ... # PLUGINS "path/to/plugin" ... +# ASSETS "path/to/resources" ... # INSTALL #) # # list of bind variables for target qtdeploy.json +# QT_ANDROID_SDK_ROOT +# QT_ANDROID_NDK_ROOT +# QT_ANDROID_QT_DIR # QT_ANDROID_SDK_BUILDTOOLS_REVISION -# QT_ANDROID_SUPPORT_MULTI_ABI -# QT_ANDROID_ARCHITECTURES -# QT_ANDROID_APPLICATION_BINARY +# QT_ANDROID_ARCHITECTURE # QT_ANDROID_MANIFEST_TEMPLATE # QT_ANDROID_STL_PATH -# QT_ANDROID_USE_LLVM -# QT_ANDROID_TOOLCHAIN_PREFIX -# QT_ANDROID_TOOLCHAIN_VERSION # QT_ANDROID_PRE_COMMANDS -# ANDROID_USE_LLVM -# QT_ANDROID_APP_PATH + +# ANDROID_SDK_MINVER +# ANDROID_SDK_TARGET + +# QT_ANDROID_APP_TARGET +# QT_ANDROID_APP_BINARY # QT_ANDROID_APP_NAME # QT_ANDROID_APP_PACKAGE_NAME # QT_ANDROID_APP_VERSION_CODE @@ -102,25 +118,17 @@ include(CMakeParseArguments) # QT_ANDROID_APP_PACKAGE_SOURCE_ROOT # QT_ANDROID_APP_EXTRA_LIBS # QT_ANDROID_APP_EXTRA_PLUGINS -# QT_ANDROID_APP_BINARY_DIR # macro(add_qt_android_apk TARGET SOURCE_TARGET) # parse the macro arguments - cmake_parse_arguments(ARG "INSTALL" "NAME;VERSION_CODE;PACKAGE_NAME;PACKAGE_SOURCES;KEYSTORE_PASSWORD;BUILDTOOLS_REVISION" "DEPENDS;PLUGINS;KEYSTORE" ${ARGN}) + cmake_parse_arguments(ARG "INSTALL" "NAME;VERSION_CODE;PACKAGE_NAME;PACKAGE_SOURCES;KEYSTORE_PASSWORD;BUILDTOOLS_REVISION" "DEPENDS;PLUGINS;ASSETS;KEYSTORE" ${ARGN}) + + # target name + set(QT_ANDROID_APP_TARGET "$") # full file path to the app's main shared library set(QT_ANDROID_APP_PATH "$") - if(${Qt5Core_VERSION} VERSION_GREATER_EQUAL 5.14) - set(QT_ANDROID_SUPPORT_MULTI_ABI ON) - endif() - - if(QT_ANDROID_SUPPORT_MULTI_ABI) - # qtandroideploy will append by itself the ANDROID_ABI to the target name - set(QT_ANDROID_APPLICATION_BINARY "${SOURCE_TARGET}") - else() - set(QT_ANDROID_APPLICATION_BINARY ${QT_ANDROID_APP_PATH}) - endif() # define the application name if(ARG_NAME) @@ -139,8 +147,6 @@ macro(add_qt_android_apk TARGET SOURCE_TARGET) # set the Android SDK build-tools revision if(ARG_BUILDTOOLS_REVISION) set(QT_ANDROID_SDK_BUILDTOOLS_REVISION ${ARG_BUILDTOOLS_REVISION}) - else() - set(QT_ANDROID_SDK_BUILDTOOLS_REVISION "") endif() # get version code from arguments, or generate a fixed one if not provided @@ -166,77 +172,44 @@ macro(add_qt_android_apk TARGET SOURCE_TARGET) if(ARG_PACKAGE_SOURCES) if(EXISTS "${ARG_PACKAGE_SOURCES}/AndroidManifest.xml") # custom manifest provided, use the provided source package directly - set(QT_ANDROID_APP_PACKAGE_SOURCE_ROOT ${ARG_PACKAGE_SOURCES}) - elseif(EXISTS "${ARG_PACKAGE_SOURCES}/AndroidManifest.xml.in") - # custom manifest template provided - set(QT_ANDROID_MANIFEST_TEMPLATE "${ARG_PACKAGE_SOURCES}/AndroidManifest.xml.in") + set(QT_ANDROID_APP_PACKAGE_SOURCE_ROOT "${ARG_PACKAGE_SOURCES}") endif() endif() - # generate a source package directory if none was provided, or if we need to configure a manifest file + # generate a source package directory if we need to configure a manifest file if(NOT QT_ANDROID_APP_PACKAGE_SOURCE_ROOT) # create our own configured package directory in build dir set(QT_ANDROID_APP_PACKAGE_SOURCE_ROOT "${CMAKE_CURRENT_BINARY_DIR}/package") # create the manifest from the template file - if(NOT QT_ANDROID_MANIFEST_TEMPLATE) - set(QT_ANDROID_MANIFEST_TEMPLATE "${QT_ANDROID_SOURCE_DIR}/AndroidManifest.xml.in") - endif() + set(QT_ANDROID_MANIFEST_TEMPLATE "${QT_ANDROID_SOURCE_DIR}/AndroidManifest.xml.in") configure_file(${QT_ANDROID_MANIFEST_TEMPLATE} ${CMAKE_CURRENT_BINARY_DIR}/AndroidManifest.xml @ONLY) # define commands that will be added before the APK target build commands, to refresh the source package directory set(QT_ANDROID_PRE_COMMANDS ${QT_ANDROID_PRE_COMMANDS} - COMMAND ${CMAKE_COMMAND} -E remove_directory ${QT_ANDROID_APP_PACKAGE_SOURCE_ROOT}) # clean the destination directory - set(QT_ANDROID_PRE_COMMANDS ${QT_ANDROID_PRE_COMMANDS} COMMAND ${CMAKE_COMMAND} -E make_directory ${QT_ANDROID_APP_PACKAGE_SOURCE_ROOT}) # re-create it + COMMAND ${CMAKE_COMMAND} -E remove_directory "${QT_ANDROID_APP_PACKAGE_SOURCE_ROOT}") # clean the destination directory + set(QT_ANDROID_PRE_COMMANDS ${QT_ANDROID_PRE_COMMANDS} COMMAND ${CMAKE_COMMAND} -E make_directory "${QT_ANDROID_APP_PACKAGE_SOURCE_ROOT}") # re-create it + # deploy Qt translations + set(QT_ANDROID_PRE_COMMANDS ${QT_ANDROID_PRE_COMMANDS} COMMAND ${CMAKE_COMMAND} -E make_directory "${QT_ANDROID_APP_PACKAGE_SOURCE_ROOT}/assets/translations") + set(QT_ANDROID_PRE_COMMANDS ${QT_ANDROID_PRE_COMMANDS} COMMAND ${CMAKE_COMMAND} -E copy_directory "${QT_ANDROID_QT_DIR}/translations" "${QT_ANDROID_APP_PACKAGE_SOURCE_ROOT}/assets/translations") + # deploy assets if(ARG_PACKAGE_SOURCES) set(QT_ANDROID_PRE_COMMANDS ${QT_ANDROID_PRE_COMMANDS} COMMAND ${CMAKE_COMMAND} -E copy_directory ${ARG_PACKAGE_SOURCES} ${QT_ANDROID_APP_PACKAGE_SOURCE_ROOT}) # copy the user package endif() - set(QT_ANDROID_PRE_COMMANDS ${QT_ANDROID_PRE_COMMANDS} COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/AndroidManifest.xml ${QT_ANDROID_APP_PACKAGE_SOURCE_ROOT}/AndroidManifest.xml) # copy the generated manifest - endif() - - # newer NDK toolchains don't define ANDROID_STL_PREFIX anymore, - # so this is a fallback to the only supported value in recent versions - if(NOT ANDROID_STL_PREFIX) - if(ANDROID_STL MATCHES "^c\\+\\+_") - set(ANDROID_STL_PREFIX llvm-libc++) - endif() - endif() - if(NOT ANDROID_STL_PREFIX) - message(WARNING "Failed to determine ANDROID_STL_PREFIX value for ANDROID_STL=${ANDROID_STL}") - endif() - - if(QT_ANDROID_SUPPORT_MULTI_ABI) - # from Qt 5.14 qtandroideploy will find the correct stl. - set(QT_ANDROID_STL_PATH "${QT_ANDROID_NDK_ROOT}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs") - else() - # define the STL shared library path - # up until NDK r18, ANDROID_STL_SHARED_LIBRARIES is populated by the NDK's toolchain file - # since NDK r19, the only option for a shared STL library is libc++_shared - if(ANDROID_STL_SHARED_LIBRARIES) - list(GET ANDROID_STL_SHARED_LIBRARIES 0 STL_LIBRARY_NAME) # we can only give one to androiddeployqt - if(ANDROID_STL_PATH) - set(QT_ANDROID_STL_PATH "${ANDROID_STL_PATH}/libs/${ANDROID_ABI}/lib${STL_LIBRARY_NAME}.so") - else() - set(QT_ANDROID_STL_PATH "${QT_ANDROID_NDK_ROOT}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/lib${STL_LIBRARY_NAME}.so") - endif() - elseif(ANDROID_STL STREQUAL c++_shared) - set(QT_ANDROID_STL_PATH "${QT_ANDROID_NDK_ROOT}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/libc++_shared.so") - else() - message(WARNING "ANDROID_STL (${ANDROID_STL}) isn't a known shared stl library." - "You should consider setting ANDROID_STL to c++_shared (like Qt).") - set(QT_ANDROID_STL_PATH "${QT_ANDROID_NDK_ROOT}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/libc++_shared.so") + if(ARG_ASSETS) + foreach(ASSET_PATH ${ARG_ASSETS}) + get_filename_component(ASSET_NAME "${ASSET_PATH}" NAME) + set(QT_ANDROID_PRE_COMMANDS ${QT_ANDROID_PRE_COMMANDS} COMMAND ${CMAKE_COMMAND} -E make_directory ${QT_ANDROID_APP_PACKAGE_SOURCE_ROOT}/assets/${ASSET_NAME}) + set(QT_ANDROID_PRE_COMMANDS ${QT_ANDROID_PRE_COMMANDS} COMMAND ${CMAKE_COMMAND} -E copy_directory ${ASSET_PATH} ${QT_ANDROID_APP_PACKAGE_SOURCE_ROOT}/assets/${ASSET_NAME}) + endforeach() endif() + set(QT_ANDROID_PRE_COMMANDS ${QT_ANDROID_PRE_COMMANDS} COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/AndroidManifest.xml ${QT_ANDROID_APP_PACKAGE_SOURCE_ROOT}/AndroidManifest.xml) # copy the generated manifest endif() - # From Qt 5.14 qtandroideploy "target-architecture" is no longer valid in input file - # It have been replaced by "architectures": { "${ANDROID_ABI}": "${ANDROID_ABI}" } - # This allow to package multiple ABI in a single apk - # For now we only support single ABI build with this script (to ensure it work with Qt5.14 & Qt5.15) - if(QT_ANDROID_SUPPORT_MULTI_ABI) - set(QT_ANDROID_ARCHITECTURES "\"${ANDROID_ABI}\":\"${ANDROID_ABI}\"") - endif() + # define the STL library path + set(QT_ANDROID_STL_PATH "${QT_ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}/sysroot/usr/lib/") - # set the list of dependant libraries + # set the list of dependant libraries (android-extra-libs) if(ARG_DEPENDS) foreach(LIB ${ARG_DEPENDS}) if(TARGET ${LIB}) @@ -249,13 +222,10 @@ macro(add_qt_android_apk TARGET SOURCE_TARGET) set(EXTRA_LIBS "${LIB}") endif() endforeach() - set(QT_ANDROID_APP_EXTRA_LIBS "\"android-extra-libs\": \"${EXTRA_LIBS}\",") + set(QT_ANDROID_APP_EXTRA_LIBS "${EXTRA_LIBS}") endif() - # deploy Qt translations - set(EXTRA_PLUGINS "${QT_ANDROID_QT_ROOT}/translations") - - # set the list of dependant plugins + # set the list of dependant plugins (android-extra-plugins) if(ARG_PLUGINS) foreach(PLUGIN ${ARG_PLUGINS}) if(EXTRA_PLUGINS) @@ -265,30 +235,7 @@ macro(add_qt_android_apk TARGET SOURCE_TARGET) endif() endforeach() endif() - set(QT_ANDROID_APP_EXTRA_PLUGINS "\"android-extra-plugins\": \"${EXTRA_PLUGINS}\",") - - # set some toolchain variables used by androiddeployqt; - # unfortunately, Qt tries to build paths from these variables although - # these full paths are already available in the toochain file, so we have - # to parse them. - # also determine whether to use the gcc- or llvm/clang- toolchain; - # note that ANDROID_TOOLCHAIN value (set by the NDK's toolchain file) says - # whether llvm/clang or gcc is used, but this will not be used. - string(REGEX MATCH "${ANDROID_NDK}/toolchains/llvm/prebuilt/.*" ANDROID_USE_LLVM_PARSED ${ANDROID_TOOLCHAIN_ROOT}) - if(ANDROID_USE_LLVM_PARSED) - set(QT_ANDROID_USE_LLVM "true") - set(QT_ANDROID_TOOLCHAIN_PREFIX "llvm") - set(QT_ANDROID_TOOLCHAIN_VERSION "") - else() - set(QT_ANDROID_USE_LLVM "false") - string(REGEX MATCH "${ANDROID_NDK}/toolchains/(.*)-(.*)/prebuilt/.*" ANDROID_TOOLCHAIN_PARSED ${ANDROID_TOOLCHAIN_ROOT}) - if(ANDROID_TOOLCHAIN_PARSED) - set(QT_ANDROID_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1}) - set(QT_ANDROID_TOOLCHAIN_VERSION ${CMAKE_MATCH_2}) - else() - message(FATAL_ERROR "Failed to parse ANDROID_TOOLCHAIN_ROOT to get toolchain prefix and version") - endif() - endif() + set(QT_ANDROID_APP_EXTRA_PLUGINS "${EXTRA_PLUGINS}") # make sure that the output directory for the Android package exists set(QT_ANDROID_APP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_TARGET}-${ANDROID_ABI}) @@ -343,7 +290,7 @@ macro(add_qt_android_apk TARGET SOURCE_TARGET) COMMAND ${CMAKE_COMMAND} -E remove_directory ${QT_ANDROID_APP_BINARY_DIR}/libs/${ANDROID_ABI} COMMAND ${CMAKE_COMMAND} -E make_directory ${QT_ANDROID_APP_BINARY_DIR}/libs/${ANDROID_ABI} COMMAND ${CMAKE_COMMAND} -E copy ${QT_ANDROID_APP_PATH} ${QT_ANDROID_APP_BINARY_DIR}/libs/${ANDROID_ABI} - COMMAND ${QT_ANDROID_QT_ROOT}/bin/androiddeployqt + COMMAND ${QT_ANDROID_QT_DIR}/bin/androiddeployqt --output ${QT_ANDROID_APP_BINARY_DIR} --input ${CMAKE_CURRENT_BINARY_DIR}/qtdeploy.json --gradle diff --git a/android/linux-build-arm64-qt515.sh b/android/linux-build-arm64-qt515.sh index 7038ca3f..aaa75746 100755 --- a/android/linux-build-arm64-qt515.sh +++ b/android/linux-build-arm64-qt515.sh @@ -13,17 +13,13 @@ cmake .. -B $BUILD_DIR -DCMAKE_SYSTEM_NAME=Android \ -DCMAKE_MAKE_PROGRAM=$ANDROID_NDK/prebuilt/linux-x86_64/bin/make \ -DCMAKE_BUILD_TYPE=Release \ -DANDROID_ABI="arm64-v8a" \ --DANDROID_STL_PREFIX="llvm-libc++" \ --DANDROID_STL_SHARED_LIBRARIES="c++_shared" \ -DANDROID_SDK_MINVER=24 \ -DANDROID_SDK_TARGET=26 \ -DANDROID_NATIVE_API_LEVEL=24 \ -DQT_ANDROID_SDK_BUILDTOOLS_REVISION="29.0.2" \ -DQT_ANDROID_PLATFORM_LEVEL=29 \ --DQT_ANDROID_TOOL_PREFIX="aarch64-linux-android" \ -DQT_ANDROID_SDK_ROOT=$ANDROID_SDK \ -DQT_ANDROID_NDK_ROOT=$ANDROID_NDK \ --DQT_ANDROID_QT_ROOT=$QT_DIR \ -DQt5_DIR=$QT_DIR/lib/cmake/Qt5 \ -DQt5Core_DIR=$QT_DIR/lib/cmake/Qt5Core \ -DQt5Gui_DIR=$QT_DIR/lib/cmake/Qt5Gui \ @@ -43,4 +39,3 @@ cmake .. -B $BUILD_DIR -DCMAKE_SYSTEM_NAME=Android \ $@ [ $? -eq 0 ] && cmake --build $BUILD_DIR --parallel 8 - diff --git a/android/linux-build-armv7-qt515.sh b/android/linux-build-armv7-qt515.sh index 76855d55..bb7b7c8b 100755 --- a/android/linux-build-armv7-qt515.sh +++ b/android/linux-build-armv7-qt515.sh @@ -13,17 +13,13 @@ cmake .. -B $BUILD_DIR -DCMAKE_SYSTEM_NAME=Android \ -DCMAKE_MAKE_PROGRAM=$ANDROID_NDK/prebuilt/linux-x86_64/bin/make \ -DCMAKE_BUILD_TYPE=Release \ -DANDROID_ABI="armeabi-v7a" \ --DANDROID_STL_PREFIX="llvm-libc++" \ --DANDROID_STL_SHARED_LIBRARIES="c++_shared" \ -DANDROID_SDK_MINVER=24 \ -DANDROID_SDK_TARGET=26 \ -DANDROID_NATIVE_API_LEVEL=24 \ --DQT_ANDROID_PLATFORM_LEVEL=29 \ -DQT_ANDROID_SDK_BUILDTOOLS_REVISION="29.0.2" \ --DQT_ANDROID_TOOL_PREFIX="arm-linux-androideabi" \ +-DQT_ANDROID_PLATFORM_LEVEL=29 \ -DQT_ANDROID_SDK_ROOT=$ANDROID_SDK \ -DQT_ANDROID_NDK_ROOT=$ANDROID_NDK \ --DQT_ANDROID_QT_ROOT=$QT_DIR \ -DQt5_DIR=$QT_DIR/lib/cmake/Qt5 \ -DQt5Core_DIR=$QT_DIR/lib/cmake/Qt5Core \ -DQt5Gui_DIR=$QT_DIR/lib/cmake/Qt5Gui \ @@ -43,4 +39,3 @@ cmake .. -B $BUILD_DIR -DCMAKE_SYSTEM_NAME=Android \ $@ [ $? -eq 0 ] && cmake --build $BUILD_DIR --parallel 8 - diff --git a/android/linux-build-x64-qt515.sh b/android/linux-build-x64-qt515.sh index 9c69c7ba..27a0f568 100755 --- a/android/linux-build-x64-qt515.sh +++ b/android/linux-build-x64-qt515.sh @@ -13,17 +13,13 @@ cmake .. -B $BUILD_DIR -DCMAKE_SYSTEM_NAME=Android \ -DCMAKE_MAKE_PROGRAM=$ANDROID_NDK/prebuilt/linux-x86_64/bin/make \ -DCMAKE_BUILD_TYPE=Debug \ -DANDROID_ABI="x86_64" \ --DANDROID_STL_PREFIX="llvm-libc++" \ --DANDROID_STL_SHARED_LIBRARIES="c++_shared" \ -DANDROID_SDK_MINVER=24 \ -DANDROID_SDK_TARGET=26 \ -DANDROID_NATIVE_API_LEVEL=24 \ --DQT_ANDROID_PLATFORM_LEVEL=29 \ -DQT_ANDROID_SDK_BUILDTOOLS_REVISION="29.0.2" \ --DQT_ANDROID_TOOL_PREFIX="x86_64-linux-android" \ +-DQT_ANDROID_PLATFORM_LEVEL=29 \ -DQT_ANDROID_SDK_ROOT=$ANDROID_SDK \ -DQT_ANDROID_NDK_ROOT=$ANDROID_NDK \ --DQT_ANDROID_QT_ROOT=$QT_DIR \ -DQt5_DIR=$QT_DIR/lib/cmake/Qt5 \ -DQt5Core_DIR=$QT_DIR/lib/cmake/Qt5Core \ -DQt5Gui_DIR=$QT_DIR/lib/cmake/Qt5Gui \ @@ -43,4 +39,3 @@ cmake .. -B $BUILD_DIR -DCMAKE_SYSTEM_NAME=Android \ $@ [ $? -eq 0 ] && cmake --build $BUILD_DIR --parallel 8 - diff --git a/android/linux-build-x86-qt515.sh b/android/linux-build-x86-qt515.sh index 469c88d5..01b3b7c9 100755 --- a/android/linux-build-x86-qt515.sh +++ b/android/linux-build-x86-qt515.sh @@ -13,17 +13,13 @@ cmake .. -B $BUILD_DIR -DCMAKE_SYSTEM_NAME=Android \ -DCMAKE_MAKE_PROGRAM=$ANDROID_NDK/prebuilt/linux-x86_64/bin/make \ -DCMAKE_BUILD_TYPE=Debug \ -DANDROID_ABI="x86" \ --DANDROID_STL_PREFIX="llvm-libc++" \ --DANDROID_STL_SHARED_LIBRARIES="c++_shared" \ -DANDROID_SDK_MINVER=24 \ -DANDROID_SDK_TARGET=26 \ -DANDROID_NATIVE_API_LEVEL=24 \ --DQT_ANDROID_PLATFORM_LEVEL=29 \ -DQT_ANDROID_SDK_BUILDTOOLS_REVISION="29.0.2" \ --DQT_ANDROID_TOOL_PREFIX="i686-linux-android" \ +-DQT_ANDROID_PLATFORM_LEVEL=29 \ -DQT_ANDROID_SDK_ROOT=$ANDROID_SDK \ -DQT_ANDROID_NDK_ROOT=$ANDROID_NDK \ --DQT_ANDROID_QT_ROOT=$QT_DIR \ -DQt5_DIR=$QT_DIR/lib/cmake/Qt5 \ -DQt5Core_DIR=$QT_DIR/lib/cmake/Qt5Core \ -DQt5Gui_DIR=$QT_DIR/lib/cmake/Qt5Gui \ @@ -43,4 +39,3 @@ cmake .. -B $BUILD_DIR -DCMAKE_SYSTEM_NAME=Android \ $@ [ $? -eq 0 ] && cmake --build $BUILD_DIR --parallel 8 - diff --git a/android/qtdeploy.json.in b/android/qtdeploy.json.in index 5def6137..0c584936 100755 --- a/android/qtdeploy.json.in +++ b/android/qtdeploy.json.in @@ -1,22 +1,20 @@ { "description": "This file is to be read by androiddeployqt", - "qt": "@QT_ANDROID_QT_ROOT@", + "qt": "@QT_ANDROID_QT_DIR@", "sdk": "@QT_ANDROID_SDK_ROOT@", - "ndk": "@QT_ANDROID_NDK_ROOT@", "sdkBuildToolsRevision": "@QT_ANDROID_SDK_BUILDTOOLS_REVISION@", - "toolchain-prefix": "@QT_ANDROID_TOOLCHAIN_PREFIX@", - "tool-prefix": "@QT_ANDROID_TOOL_PREFIX@", - "toolchain-version": "@QT_ANDROID_TOOLCHAIN_VERSION@", + "ndk": "@QT_ANDROID_NDK_ROOT@", + "toolchain-prefix": "llvm", + "tool-prefix": "llvm", "ndk-host": "@ANDROID_NDK_HOST_SYSTEM_NAME@", - "architectures": { @QT_ANDROID_ARCHITECTURES@ }, - "target-architecture": "@ANDROID_ABI@", - "application-binary": "@QT_ANDROID_APPLICATION_BINARY@", + "architectures": { "@ANDROID_ABI@": "@QT_ANDROID_ARCHITECTURE@" }, + "android-min-sdk-version": "@ANDROID_SDK_MINVER@", + "android-target-sdk-version": "@ANDROID_SDK_TARGET@", + "application-binary": "@QT_ANDROID_APP_TARGET@", "android-package": "@QT_ANDROID_APP_PACKAGE_NAME@", "android-app-name": "@QT_ANDROID_APP_NAME@", "qml-root-path": "@CMAKE_SOURCE_DIR@", "stdcpp-path": "@QT_ANDROID_STL_PATH@", - "useLLVM": "@QT_ANDROID_USE_LLVM@", - @QT_ANDROID_APP_EXTRA_LIBS@ - @QT_ANDROID_APP_EXTRA_PLUGINS@ + "android-extra-libs": "@QT_ANDROID_APP_EXTRA_LIBS@", "android-package-source-directory": "@QT_ANDROID_APP_PACKAGE_SOURCE_ROOT@" } diff --git a/cmake/qtchooser.cmake b/cmake/qtchooser.cmake new file mode 100644 index 00000000..34c5e873 --- /dev/null +++ b/cmake/qtchooser.cmake @@ -0,0 +1,38 @@ +# +# Select QT version preferred +# +set(QT5_VERSION_MATCH 5.15) +set(QT6_VERSION_MATCH 6) + +if (QT_VERSION_PREFERRED AND QT_VERSION_PREFERRED EQUAL 5) + message(STATUS "Try loading Qt5 (explicitly preferred)...") + set(QT_DEFAULT_MAJOR_VERSION 5) + find_package(Qt5 ${QT5_VERSION_MATCH} COMPONENTS Core QUIET) + if(Qt5_FOUND) + message(STATUS "Choosing Qt5, since explicitly preferred") + set(QT_FOUND 1) + set(QT_VERSION_MAJOR 5) + set(QT_VERSION ${QT5_VERSION_MATCH}) + else () + message(STATUS "Qt5 NOT found") + endif() +elseif (QT_VERSION_PREFERRED AND QT_VERSION_PREFERRED EQUAL 6) + message(STATUS "Try loading preferred Qt6 (explicitly preferred)...") + set(QT_DEFAULT_MAJOR_VERSION 6) + find_package(Qt6 ${QT6_VERSION_MATCH} COMPONENTS Core QUIET) + if(Qt6_FOUND) + message(STATUS "Choosing Qt6, since explicitly preferred") + set(QT_FOUND 1) + set(QT_VERSION_MAJOR 6) + set(QT_VERSION ${QT6_VERSION_MATCH}) + else () + message(STATUS "Qt6 NOT found") + endif() +endif() + +if(QT_FOUND) + message(STATUS "Qt version used: ${QT_VERSION}") + option(QT_QML_DEBUG "Build with QML debugger support" OFF) + mark_as_advanced(QT_QML_DEBUG) +endif () +