diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index 8cc19ac030..a7484a3435 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -303,6 +303,7 @@ set(__public_cmake_helpers cmake/QtPublicFinalizerHelpers.cmake cmake/QtPublicPluginHelpers.cmake cmake/QtPublicTargetHelpers.cmake + cmake/QtPublicToolHelpers.cmake cmake/QtPublicWalkLibsHelpers.cmake cmake/QtPublicFindPackageHelpers.cmake cmake/QtPublicDependencyHelpers.cmake diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index d267f560c1..b411c6031a 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -545,6 +545,7 @@ include(QtPublicTargetHelpers) include(QtPublicWalkLibsHelpers) include(QtPublicFindPackageHelpers) include(QtPublicDependencyHelpers) +include(QtPublicToolHelpers) # TODO: This block provides support for old variables. It should be removed once # we remove all references to these variables in other Qt module repos. diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in index 752655c21e..dd39ff648e 100644 --- a/cmake/QtConfig.cmake.in +++ b/cmake/QtConfig.cmake.in @@ -91,6 +91,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/QtPublicTargetHelpers.cmake") include("${CMAKE_CURRENT_LIST_DIR}/QtPublicWalkLibsHelpers.cmake") include("${CMAKE_CURRENT_LIST_DIR}/QtPublicFindPackageHelpers.cmake") include("${CMAKE_CURRENT_LIST_DIR}/QtPublicDependencyHelpers.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/QtPublicToolHelpers.cmake") if(NOT DEFINED QT_CMAKE_EXPORT_NAMESPACE) set(QT_CMAKE_EXPORT_NAMESPACE @QT_CMAKE_EXPORT_NAMESPACE@) diff --git a/cmake/QtPublicToolHelpers.cmake b/cmake/QtPublicToolHelpers.cmake new file mode 100644 index 0000000000..8705a9e293 --- /dev/null +++ b/cmake/QtPublicToolHelpers.cmake @@ -0,0 +1,43 @@ +# The function returns location of the imported 'tool', returns an empty string if tool is not +# imported. +function(__qt_internal_get_tool_imported_location out_var tool) + unset(${out_var}) + if("${tool}" MATCHES "^Qt[0-9]?::.+$") + # The tool target has namespace already + set(target ${tool}) + else() + set(target ${QT_CMAKE_EXPORT_NAMESPACE}::${tool}) + endif() + + if(NOT TARGET ${target}) + message(FATAL_ERROR "${target} is not a target.") + endif() + + get_target_property(is_imported ${target} IMPORTED) + if(NOT is_imported) + set(${out_var} "" PARENT_SCOPE) + return() + endif() + + get_target_property(configs ${target} IMPORTED_CONFIGURATIONS) + list(TRANSFORM configs PREPEND _) + # Well-known configuration types + list(APPEND + _RELWITHDEBINFO + _RELEASE + _MINSIZEREL + _DEBUG + ) + list(REMOVE_DUPLICATES configs) + # Look for the default empty configuration type at the first place. + list(PREPEND configs "") + + foreach(config ${configs}) + get_target_property(${out_var} ${target} "IMPORTED_LOCATION${config}") + if(${out_var}) + break() + endif() + endforeach() + + set(${out_var} "${${out_var}}" PARENT_SCOPE) +endfunction() diff --git a/src/corelib/Qt6AndroidMacros.cmake b/src/corelib/Qt6AndroidMacros.cmake index 56faedb121..3313975022 100644 --- a/src/corelib/Qt6AndroidMacros.cmake +++ b/src/corelib/Qt6AndroidMacros.cmake @@ -17,6 +17,35 @@ function(_qt_internal_android_get_sdk_build_tools_revision out_var) set(${out_var} "${android_build_tools_latest}" PARENT_SCOPE) endfunction() +# The function appends to the 'out_var' a 'json_property' that contains the 'tool' path. If 'tool' +# target or its IMPORTED_LOCATION are not found the function displays warning, but is not failing +# at the project configuring phase. +function(_qt_internal_add_tool_to_android_deployment_settings out_var tool json_property target) + unset(tool_binary_path) + __qt_internal_get_tool_imported_location(tool_binary_path ${tool}) + if("${tool_binary_path}" STREQUAL "") + # Fallback search for the tool in host bin and host libexec directories + find_program(tool_binary_path + NAMES ${tool} ${tool}.exe + PATHS + "${QT_HOST_PATH}/${QT6_HOST_INFO_BINDIR}" + "${QT_HOST_PATH}/${QT6_HOST_INFO_LIBEXECDIR}" + NO_DEFAULT_PATH + ) + if(NOT tool_binary_path) + message(WARNING "Unable to locate ${tool}. Android package deployment of ${target}" + " target can be incomplete. Make sure the host Qt has ${tool} installed.") + return() + endif() + endif() + + file(TO_CMAKE_PATH "${tool_binary_path}" tool_binary_path) + string(APPEND ${out_var} + " \"${json_property}\" : \"${tool_binary_path}\",\n") + + set(${out_var} "${${out_var}}" PARENT_SCOPE) +endfunction() + # Generate the deployment settings json file for a cmake target. function(qt6_android_generate_deployment_settings target) # Information extracted from mkspecs/features/android/android_deployment_settings.prf @@ -241,13 +270,7 @@ function(qt6_android_generate_deployment_settings target) " \"qml-importscanner-binary\" : \"${qml_importscanner_binary_path_native}\",\n") # Override rcc binary path - set(rcc_binary_path "${QT_HOST_PATH}/${QT6_HOST_INFO_LIBEXECDIR}/rcc") - if (WIN32) - string(APPEND rcc_binary_path ".exe") - endif() - file(TO_CMAKE_PATH "${rcc_binary_path}" rcc_binary_path_native) - string(APPEND file_contents - " \"rcc-binary\" : \"${rcc_binary_path_native}\",\n") + _qt_internal_add_tool_to_android_deployment_settings(file_contents rcc "rcc-binary" "${target}") # Extra prefix paths foreach(prefix IN LISTS CMAKE_FIND_ROOT_PATH)