From 3a91ed4682f772fae49cc228cd8e1e6893ade700 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Fri, 3 Apr 2026 13:03:23 +0300
Subject: [PATCH 27/27] Meson: Use host_machine.system() to detect emscripten
 build

That replaces a compile test we had for the same purpose.

See RM #1881

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 meson.build | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/meson.build b/meson.build
index e2f93959d6..63aba5180c 100644
--- a/meson.build
+++ b/meson.build
@@ -243,23 +243,11 @@ if meson.is_cross_build()
   cross_inc_path = [cross_inc_str]
   cross_lib_path = [meson.get_external_property('cross_lib_path', '')]
   crosser = meson.get_external_property('crosser', false)
-
-  # emscripten build is always cross-build, so check it only here
-  if c_compiler.compiles(
-'''#ifndef __EMSCRIPTEN__
-  error fail
-#endif''',
-  name: 'emscripten')
-    emscripten = true
-  else
-    emscripten = false
-  endif
 else
   cross_inc_str = ''
   cross_inc_path = []
   cross_lib_path = []
   crosser = false
-  emscripten = false
 endif
 
 server_type = get_option('server')
@@ -723,7 +711,7 @@ int main(void) { int *var = nullptr; return 0; }''',
   pub_conf_data.set('FREECIV_HAVE_CXX_NULLPTR', 1)
 endif
 
-if emscripten
+if host_system == 'emscripten'
   icu_dep = []
   zlib_dep = []
   syslua = 'false'
@@ -884,7 +872,7 @@ if get_option('audio') == 'sdl2' or get_option('clients').contains('sdl2')
                     c_compiler.find_library('SDL2main', dirs: cross_lib_path),
                     dependency('SDL2')]
   else
-    if emscripten
+    if host_system == 'emscripten'
       emscripten_sdl2_args = [
         '-s', 'USE_SDL=2'
       ]
@@ -916,7 +904,7 @@ if get_option('audio') == 'sdl3' or get_option('clients').contains('sdl3')
     sdl3main_dep = [c_compiler.find_library('mingw32', dirs: cross_lib_path),
                     dependency('sdl3')]
   else
-    if emscripten
+    if host_system == 'emscripten'
       emscripten_sdl3_args = [
         '-s', 'USE_SDL=3'
       ]
@@ -960,7 +948,7 @@ endif
 if get_option('audio') != 'none'
   priv_conf_data.set('AUDIO_SDL', 1)
 
-  if emscripten
+  if host_system == 'emscripten'
     audio_dep = []
   elif get_option('audio') == 'sdl3'
     audio_sdl3_dep = dependency('sdl3-mixer')
@@ -1005,7 +993,7 @@ else
   gettext_dep = []
 endif
 
-if emscripten
+if host_system == 'emscripten'
   curl_dep = []
   m_dep = []
 else
@@ -1013,7 +1001,7 @@ else
   m_dep = c_compiler.find_library('m', dirs: cross_lib_path)
 endif
 
-if not emscripten
+if host_system != 'emscripten'
   if c_compiler.compiles(net_incl + '''
 #include <stddef.h>
 #include <curl/curl.h>
@@ -1027,7 +1015,7 @@ int main(void) { curl_mime *mime = curl_mime_init(NULL); }''',
   endif
 endif
 
-if not emscripten
+if host_system != 'emscripten'
   sqlite3_dep = c_compiler.find_library('sqlite3', dirs: cross_lib_path)
 else
   sqlite3_dep = []
@@ -1069,7 +1057,7 @@ if get_option('fcdb').contains('odbc')
 endif
 
 if fcdb
-  if emscripten
+  if host_system == 'emscripten'
     error('FCDB not supported on emscripten builds.')
   endif
   priv_conf_data.set('HAVE_FCDB', 1)
@@ -3975,7 +3963,7 @@ sdl2_gfx_cargs = []
 sdl2_image_dep = []
 sdl2_ttf_dep = []
 
-if not emscripten
+if host_system != 'emscripten'
   sdl2_gfx_dep = dependency('SDL2_gfx', required: false)
 
   if not sdl2_gfx_dep.found()
@@ -4112,7 +4100,7 @@ sdl3_gfx_cargs = []
 sdl3_image_dep = []
 sdl3_ttf_dep = []
 
-if not emscripten
+if host_system != 'emscripten'
   sdl3_gfx_inc = include_directories('dependencies')
 
   sdl3_image_dep = dependency('sdl3-image', required: false)
-- 
2.53.0

