Skip to content

Commit b5e75e1

Browse files
compnerdgrynspan
andauthored
build: add a shim for older CMake (#1664)
WASI was introduced into CMake as a platform in 3.31. For older CMake versions, we add a shim to allow cleanly supporting this platform. Co-authored-by: Jonathan Grynspan <[email protected]>
1 parent 9a2eff1 commit b5e75e1

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ set(SWT_SOURCE_ROOT_DIR ${CMAKE_SOURCE_DIR})
2424
project(SwiftTesting
2525
LANGUAGES CXX Swift)
2626

27+
if(CMAKE_VERSION VERSION_LESS 3.31)
28+
if(CMAKE_SYSTEM_NAME STREQUAL "Generic" AND CMAKE_SYSTEM_PROCESSOR MATCHES "wasm32")
29+
set(CMAKE_SYSTEM_NAME WASI)
30+
set(WASI 1)
31+
endif()
32+
endif()
33+
2734
if(NOT APPLE)
28-
if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
35+
if(NOT WASI)
2936
find_package(dispatch CONFIG)
3037
endif()
3138
find_package(Foundation CONFIG)

cmake/modules/shared/CompilerSettings.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if(NOT APPLE)
4242
add_compile_definitions("SWT_NO_SNAPSHOT_TYPES")
4343
add_compile_definitions("SWT_NO_FOUNDATION_FILE_COORDINATION")
4444
endif()
45-
if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
45+
if(WASI)
4646
add_compile_definitions("SWT_NO_DYNAMIC_LINKING")
4747
add_compile_definitions("SWT_NO_PIPES")
4848
endif()
@@ -60,7 +60,7 @@ if(SWT_TESTING_LIBRARY_VERSION)
6060
add_compile_definitions("$<$<COMPILE_LANGUAGE:CXX>:SWT_TESTING_LIBRARY_VERSION=\"${SWT_TESTING_LIBRARY_VERSION}\">")
6161
endif()
6262

63-
if((NOT BUILD_SHARED_LIBS) AND (NOT CMAKE_SYSTEM_NAME STREQUAL WASI))
63+
if((NOT BUILD_SHARED_LIBS) AND NOT WASI)
6464
# When building a static library, Interop is not supported at this time
6565
add_compile_definitions("SWT_NO_INTEROP")
6666
endif()

0 commit comments

Comments
 (0)