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 <joerg.bornemann@qt.io>
This commit is contained in:
Alexandru Croitor 2021-09-27 12:27:23 +02:00
parent 5d840f0f7a
commit 2ed267c820
4 changed files with 31 additions and 5 deletions

View File

@ -43,11 +43,7 @@ function(qt_auto_detect_wasm)
message(STATUS message(STATUS
"Emscripten ${EMCC_VERSION} toolchain file detected at ${CMAKE_TOOLCHAIN_FILE}") "Emscripten ${EMCC_VERSION} toolchain file detected at ${CMAKE_TOOLCHAIN_FILE}")
else() else()
message(FATAL_ERROR __qt_internal_show_error_no_emscripten_toolchain_file_found_when_building_qt()
"Cannot find the toolchain file Emscripten.cmake. "
"Please specify the toolchain file with -DCMAKE_TOOLCHAIN_FILE=<file> "
"or provide a path to a valid emscripten installation via the EMSDK "
"environment variable.")
endif() endif()
qt_internal_ensure_static_qt_config() qt_internal_ensure_static_qt_config()

View File

@ -53,3 +53,19 @@ function(__qt_internal_get_emcc_recommended_version out_var)
set(QT_EMCC_RECOMMENDED_VERSION "2.0.14") set(QT_EMCC_RECOMMENDED_VERSION "2.0.14")
set(${out_var} "${QT_EMCC_RECOMMENDED_VERSION}" PARENT_SCOPE) set(${out_var} "${QT_EMCC_RECOMMENDED_VERSION}" PARENT_SCOPE)
endfunction() 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=<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=<file> "
"or provide a path to a valid emscripten installation via the EMSDK "
"environment variable.")
endfunction()

View File

@ -235,14 +235,25 @@ if(DEFINED ENV{EMSDK} AND NOT \"\$ENV{EMSDK}\" STREQUAL \"\")
\"\${__qt_toolchain_emroot_path}\" _qt_candidate_emscripten_toolchain_path) \"\${__qt_toolchain_emroot_path}\" _qt_candidate_emscripten_toolchain_path)
set(__qt_chainload_toolchain_file \"\${_qt_candidate_emscripten_toolchain_path}\") set(__qt_chainload_toolchain_file \"\${_qt_candidate_emscripten_toolchain_path}\")
endif() 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() endif()
string(REPLACE ";" "\n" init_additional_used_variables string(REPLACE ";" "\n" init_additional_used_variables
"${init_additional_used_variables}") "${init_additional_used_variables}")
string(REPLACE ";" "\n" init_vcpkg "${init_vcpkg}") string(REPLACE ";" "\n" init_vcpkg "${init_vcpkg}")
string(REPLACE ";" "\n" init_platform "${init_platform}") string(REPLACE ";" "\n" init_platform "${init_platform}")
string(REPLACE "LITERAL_SEMICOLON" ";" 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() qt_compute_relative_path_from_cmake_config_dir_to_prefix()
configure_file( configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/qt.toolchain.cmake.in" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/qt.toolchain.cmake.in"

View File

@ -43,10 +43,13 @@ if(__qt_chainload_toolchain_file)
"'${__qt_chainload_toolchain_file}' does not exist.") "'${__qt_chainload_toolchain_file}' does not exist.")
else() else()
include("${__qt_chainload_toolchain_file}") include("${__qt_chainload_toolchain_file}")
set(__qt_chainload_toolchain_file_included TRUE)
endif() endif()
unset(__qt_chainload_toolchain_file) unset(__qt_chainload_toolchain_file)
endif() endif()
@init_post_chainload_toolchain@
# Compute dynamically the Qt installation prefix from the location of this file. This allows # 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. # the usage of the toolchain file when the Qt installation is relocated.
get_filename_component(QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX get_filename_component(QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX