From 2ed267c82015f5eab7fe65aad6553eb0d6bb338d Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 27 Sep 2021 12:27:23 +0200 Subject: CMake: Show error in user projects if wasm toolchain file not found Rather than fail with obscure can't find Qt packages errors when the Webassembly CMake toolchain file can not be found, error out with a clear error on how to ensure it is found. Pick-to: 6.2 Task-number: QTBUG-96843 Change-Id: I0f34cdcde05efb25c93017f3fd365186335ed52c Reviewed-by: Joerg Bornemann --- cmake/QtAutoDetect.cmake | 6 +----- cmake/QtPublicWasmToolchainHelpers.cmake | 16 ++++++++++++++++ cmake/QtToolchainHelpers.cmake | 11 +++++++++++ cmake/qt.toolchain.cmake.in | 3 +++ 4 files changed, 31 insertions(+), 5 deletions(-) (limited to 'cmake') diff --git a/cmake/QtAutoDetect.cmake b/cmake/QtAutoDetect.cmake index ba25377abe..128a882b8d 100644 --- a/cmake/QtAutoDetect.cmake +++ b/cmake/QtAutoDetect.cmake @@ -43,11 +43,7 @@ function(qt_auto_detect_wasm) message(STATUS "Emscripten ${EMCC_VERSION} toolchain file detected at ${CMAKE_TOOLCHAIN_FILE}") else() - message(FATAL_ERROR - "Cannot find the toolchain file Emscripten.cmake. " - "Please specify the toolchain file with -DCMAKE_TOOLCHAIN_FILE= " - "or provide a path to a valid emscripten installation via the EMSDK " - "environment variable.") + __qt_internal_show_error_no_emscripten_toolchain_file_found_when_building_qt() endif() qt_internal_ensure_static_qt_config() diff --git a/cmake/QtPublicWasmToolchainHelpers.cmake b/cmake/QtPublicWasmToolchainHelpers.cmake index 53d74e0234..8d0d9efdc9 100644 --- a/cmake/QtPublicWasmToolchainHelpers.cmake +++ b/cmake/QtPublicWasmToolchainHelpers.cmake @@ -53,3 +53,19 @@ function(__qt_internal_get_emcc_recommended_version out_var) set(QT_EMCC_RECOMMENDED_VERSION "2.0.14") set(${out_var} "${QT_EMCC_RECOMMENDED_VERSION}" PARENT_SCOPE) endfunction() + +function(__qt_internal_show_error_no_emscripten_toolchain_file_found_when_building_qt) + message(FATAL_ERROR + "Cannot find the toolchain file Emscripten.cmake. " + "Please specify the toolchain file with -DCMAKE_TOOLCHAIN_FILE= " + "or provide a path to a valid emscripten installation via the EMSDK " + "environment variable.") +endfunction() + +function(__qt_internal_show_error_no_emscripten_toolchain_file_found_when_using_qt) + message(FATAL_ERROR + "Cannot find the toolchain file Emscripten.cmake. " + "Please specify the toolchain file with -DQT_CHAINLOAD_TOOLCHAIN_FILE= " + "or provide a path to a valid emscripten installation via the EMSDK " + "environment variable.") +endfunction() diff --git a/cmake/QtToolchainHelpers.cmake b/cmake/QtToolchainHelpers.cmake index 863a3af8c3..e7bf2eda56 100644 --- a/cmake/QtToolchainHelpers.cmake +++ b/cmake/QtToolchainHelpers.cmake @@ -235,14 +235,25 @@ if(DEFINED ENV{EMSDK} AND NOT \"\$ENV{EMSDK}\" STREQUAL \"\") \"\${__qt_toolchain_emroot_path}\" _qt_candidate_emscripten_toolchain_path) set(__qt_chainload_toolchain_file \"\${_qt_candidate_emscripten_toolchain_path}\") endif() +") + list(APPEND init_post_chainload_toolchain " +if(NOT __qt_chainload_toolchain_file_included) + __qt_internal_show_error_no_emscripten_toolchain_file_found_when_using_qt() +endif() ") endif() string(REPLACE ";" "\n" init_additional_used_variables "${init_additional_used_variables}") string(REPLACE ";" "\n" init_vcpkg "${init_vcpkg}") + string(REPLACE ";" "\n" init_platform "${init_platform}") string(REPLACE "LITERAL_SEMICOLON" ";" init_platform "${init_platform}") + + string(REPLACE ";" "\n" init_post_chainload_toolchain "${init_post_chainload_toolchain}") + string(REPLACE "LITERAL_SEMICOLON" ";" init_post_chainload_toolchain + "${init_post_chainload_toolchain}") + qt_compute_relative_path_from_cmake_config_dir_to_prefix() configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/qt.toolchain.cmake.in" diff --git a/cmake/qt.toolchain.cmake.in b/cmake/qt.toolchain.cmake.in index 9a8019a3da..38a7431620 100644 --- a/cmake/qt.toolchain.cmake.in +++ b/cmake/qt.toolchain.cmake.in @@ -43,10 +43,13 @@ if(__qt_chainload_toolchain_file) "'${__qt_chainload_toolchain_file}' does not exist.") else() include("${__qt_chainload_toolchain_file}") + set(__qt_chainload_toolchain_file_included TRUE) endif() unset(__qt_chainload_toolchain_file) endif() +@init_post_chainload_toolchain@ + # Compute dynamically the Qt installation prefix from the location of this file. This allows # the usage of the toolchain file when the Qt installation is relocated. get_filename_component(QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX -- cgit v1.2.3