From 4e5fc66c04bddfc8a62e978716b0b57e9e468aaf Mon Sep 17 00:00:00 2001
From: Simon Hausmann <simon.hausmann@qt.io>
Date: Wed, 28 Aug 2019 15:01:23 +0200
Subject: [PATCH] Fix architecture detection with WASM builds

This is a simple mis-understanding between try_compile assuming interest
in the launching part of the thing we try to compile and our
architecture test being interested in the binary.

Change-Id: Ie972b662b6f34699f566649bb2c1e29da35b58c3
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
---
 cmake/QtBaseConfigureTests.cmake | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/cmake/QtBaseConfigureTests.cmake b/cmake/QtBaseConfigureTests.cmake
index ffa5019ca0..34e4e6e6f1 100644
--- a/cmake/QtBaseConfigureTests.cmake
+++ b/cmake/QtBaseConfigureTests.cmake
@@ -3,9 +3,20 @@ function(run_config_test_architecture)
     set(qt_base_configure_tests_vars_to_export)
     # Test architecture
     set(_arch_file "${CMAKE_CURRENT_BINARY_DIR}/architecture_test")
+    set(saved_executable_suffix "${CMAKE_EXECUTABLE_SUFFIX}")
+
+    # With emscripten the application entry point is a .js file (to be run with node for example), but the
+    # real "data" is in the .wasm file, so that's where we need to look for the ABI, etc. information.
+    if (EMSCRIPTEN)
+        set(CMAKE_EXECUTABLE_SUFFIX ".wasm")
+    endif()
+
     try_compile(_arch_result "${CMAKE_CURRENT_BINARY_DIR}"
         "${CMAKE_CURRENT_SOURCE_DIR}/config.tests/arch/arch.cpp"
         COPY_FILE "${_arch_file}")
+
+    set(CMAKE_EXECUTABLE_SUFFIX "${saved_executable_suffix}")
+
     if (NOT _arch_result)
         message(FATAL_ERROR "Failed to compile architecture detection file.")
     endif()