diff --git a/emcmake.py b/emcmake.py index f23c247f26e5e..b16f565c1c87d 100755 --- a/emcmake.py +++ b/emcmake.py @@ -35,7 +35,10 @@ def has_substr(args, substr): if not has_substr(args, '-DCMAKE_CROSSCOMPILING_EMULATOR'): node_js = config.NODE_JS[0] - args.append(f'-DCMAKE_CROSSCOMPILING_EMULATOR={node_js}') + # In order to allow cmake to run code built with pthreads we need to pass some extra flags to node. + # Note that we also need --experimental-wasm-bulk-memory which is true by default and hence not added here + # See https://github.com/emscripten-core/emscripten/issues/15522 + args.append(f'-DCMAKE_CROSSCOMPILING_EMULATOR={node_js};--experimental-wasm-threads') # On Windows specify MinGW Makefiles or ninja if we have them and no other # toolchain was specified, to keep CMake from pulling in a native Visual diff --git a/tests/test_other.py b/tests/test_other.py index d415155f83d7a..c30abdaeb095b 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -721,6 +721,10 @@ def test_cmake_static_lib(self, custom): else: self.assertTrue(building.is_ar('libstatic_lib.a')) + # Tests that cmake functions which require evaluation via the node runtime run properly with pthreads + def test_cmake_pthreads(self): + self.run_process([EMCMAKE, 'cmake', '-DCMAKE_C_FLAGS=-pthread', test_file('cmake/target_js')]) + # Tests that the CMake variable EMSCRIPTEN_VERSION is properly provided to user CMake scripts def test_cmake_emscripten_version(self): self.run_process([EMCMAKE, 'cmake', test_file('cmake/emscripten_version')])