summaryrefslogtreecommitdiffstats
path: root/cmake/QtAutoDetect.cmake
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2021-07-02 08:58:55 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2021-07-02 15:05:32 +0200
commitc72b7b8e5e530fbd03b704380940f5fa86e5341d (patch)
tree3c390b39b9c6ad7f22981f2366aae0031b3300cf /cmake/QtAutoDetect.cmake
parent87201ff7122fda45e069c0ca32a16e5ef4e0ceb9 (diff)
Revert "Make toolchain inspection more robust"
This reverts commit 7c62caa3555d247be569102d8f01b3e7ae362b8a. Certain toolchain files cannot be read in CMake script mode with CMake versions >= 3.20. For example, the vcpkg toolchain file overrides add_executable, and that fails with CMake 3.20: CMake Error at D:/dev_tools/vcpkg/scripts/buildsystems/vcpkg.cmake:662 (function): Built-in flow control command "add_executable" cannot be overridden. Pick-to: 6.2 Fixes: QTBUG-93627 Change-Id: Ib6e6352dff50b9684dcf81401d138e27e16292c3 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake/QtAutoDetect.cmake')
-rw-r--r--cmake/QtAutoDetect.cmake37
1 files changed, 4 insertions, 33 deletions
diff --git a/cmake/QtAutoDetect.cmake b/cmake/QtAutoDetect.cmake
index 6a94515e60..8c5cca0ecf 100644
--- a/cmake/QtAutoDetect.cmake
+++ b/cmake/QtAutoDetect.cmake
@@ -72,37 +72,6 @@ function(qt_auto_detect_cmake_generator)
endif()
endfunction()
-# Peek into CMAKE_TOOLCHAIN_FILE before it is actually loaded.
-#
-# Usage:
-# qt_autodetect_read_toolchain_file(tcf VARIABLES CMAKE_SYSTEM_NAME)
-# if(tcf_CMAKE_SYSTEM_NAME STREQUAL "Android")
-# ...we have detected Android
-# endif()
-#
-function(qt_auto_detect_read_toolchain_file prefix)
- cmake_parse_arguments(arg "" "" "VARIABLES" ${ARGN})
- set(script_path "${CMAKE_CURRENT_LIST_DIR}/QtLoadFilePrintVars.cmake")
- execute_process(
- COMMAND "${CMAKE_COMMAND}" "-DIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
- "-DVARIABLES=${arg_VARIABLES}" -P "${script_path}"
- RESULT_VARIABLE exit_code
- OUTPUT_VARIABLE output
- ERROR_VARIABLE ignore)
- if(NOT exit_code EQUAL 0)
- message(FATAL_ERROR "Executing CMake script ${script_path} failed with code ${exit_code}.")
- endif()
- string(REGEX REPLACE "^.*---QtLoadFilePrintVars---\n" "" output "${output}")
- string(REPLACE ";" "\;" output "${output}")
- string(REPLACE "\n" ";" output "${output}")
- foreach(line IN LISTS output)
- string(REGEX MATCH "-- ([^ ]+) (.*)" m "${line}")
- if(CMAKE_MATCH_1 IN_LIST arg_VARIABLES)
- set(${prefix}_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" PARENT_SCOPE)
- endif()
- endforeach()
-endfunction()
-
function(qt_auto_detect_android)
# Auto-detect NDK root
if(NOT DEFINED ANDROID_NDK_ROOT AND DEFINED ANDROID_SDK_ROOT)
@@ -151,8 +120,10 @@ function(qt_auto_detect_android)
endif()
if(DEFINED CMAKE_TOOLCHAIN_FILE AND NOT DEFINED QT_AUTODETECT_ANDROID)
- qt_auto_detect_read_toolchain_file(tcf VARIABLES CMAKE_SYSTEM_NAME)
- if(tcf_CMAKE_SYSTEM_NAME STREQUAL "Android")
+
+ file(READ ${CMAKE_TOOLCHAIN_FILE} toolchain_file_content OFFSET 0 LIMIT 80)
+ string(FIND "${toolchain_file_content}" "The Android Open Source Project" find_result REVERSE)
+ if (NOT ${find_result} EQUAL -1)
set(android_detected TRUE)
else()
set(android_detected FALSE)