|
| 1 | +From 1f62d2ee7b53240134e30d0044ec11f94c628928 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Yuta Saito < [email protected]> |
| 3 | +Date: Thu, 19 Sep 2024 04:16:20 +0000 |
| 4 | +Subject: [PATCH] CMake: Fix accidental variable expansion of `WASI` |
| 5 | + |
| 6 | +CMake recently introduced a new variable `WASI` to check if the target |
| 7 | +platform is WASI (https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9659). |
| 8 | +However, the change led to `WASI` being expanded as a variable, which |
| 9 | +is not what we want in checking the platform name. |
| 10 | + |
| 11 | +To have compatibility with older and newer versions of CMake, we should |
| 12 | +quote the string `WASI` to prevent it from being expanded as a variable. |
| 13 | +--- |
| 14 | + CMakeLists.txt | 8 ++++---- |
| 15 | + Sources/CoreFoundation/CMakeLists.txt | 2 +- |
| 16 | + Sources/_CFXMLInterface/CMakeLists.txt | 2 +- |
| 17 | + 3 files changed, 6 insertions(+), 6 deletions(-) |
| 18 | + |
| 19 | +diff --git a/CMakeLists.txt b/CMakeLists.txt |
| 20 | +index 196262ad..fa842040 100644 |
| 21 | +--- a/CMakeLists.txt |
| 22 | ++++ b/CMakeLists.txt |
| 23 | +@@ -65,7 +65,7 @@ if(BUILD_SHARED_LIBS) |
| 24 | + endif() |
| 25 | + |
| 26 | + set(FOUNDATION_BUILD_NETWORKING_default ON) |
| 27 | +-if(CMAKE_SYSTEM_NAME STREQUAL WASI) |
| 28 | ++if(CMAKE_SYSTEM_NAME STREQUAL "WASI") |
| 29 | + # Networking is not supported on WASI |
| 30 | + set(FOUNDATION_BUILD_NETWORKING_default OFF) |
| 31 | + endif() |
| 32 | +@@ -134,7 +134,7 @@ endif() |
| 33 | + # System dependencies |
| 34 | + |
| 35 | + # We know libdispatch is always unavailable on WASI |
| 36 | +-if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI) |
| 37 | ++if(NOT CMAKE_SYSTEM_NAME STREQUAL "WASI") |
| 38 | + find_package(LibRT) |
| 39 | + find_package(dispatch CONFIG) |
| 40 | + if(NOT dispatch_FOUND) |
| 41 | +@@ -171,7 +171,7 @@ list(APPEND _Foundation_common_build_flags |
| 42 | + "-Wno-switch" |
| 43 | + "-fblocks") |
| 44 | + |
| 45 | +-if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI) |
| 46 | ++if(NOT CMAKE_SYSTEM_NAME STREQUAL "WASI") |
| 47 | + list(APPEND _Foundation_common_build_flags |
| 48 | + "-DDEPLOYMENT_ENABLE_LIBDISPATCH" |
| 49 | + "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS") |
| 50 | +@@ -207,7 +207,7 @@ list(APPEND _Foundation_swift_build_flags |
| 51 | + "-Xfrontend" |
| 52 | + "-require-explicit-sendable") |
| 53 | + |
| 54 | +-if(CMAKE_SYSTEM_NAME STREQUAL WASI) |
| 55 | ++if(CMAKE_SYSTEM_NAME STREQUAL "WASI") |
| 56 | + # Enable wasi-libc emulation features |
| 57 | + set(WASI_EMULATION_DEFS _WASI_EMULATED_MMAN _WASI_EMULATED_SIGNAL _WASI_EMULATED_PROCESS_CLOCKS) |
| 58 | + foreach(def ${WASI_EMULATION_DEFS}) |
| 59 | +diff --git a/Sources/CoreFoundation/CMakeLists.txt b/Sources/CoreFoundation/CMakeLists.txt |
| 60 | +index 7ae617b4..9afac9e9 100644 |
| 61 | +--- a/Sources/CoreFoundation/CMakeLists.txt |
| 62 | ++++ b/Sources/CoreFoundation/CMakeLists.txt |
| 63 | +@@ -119,7 +119,7 @@ target_link_libraries(CoreFoundation |
| 64 | + _FoundationICU |
| 65 | + dispatch) |
| 66 | + |
| 67 | +-if(CMAKE_SYSTEM_NAME STREQUAL WASI) |
| 68 | ++if(CMAKE_SYSTEM_NAME STREQUAL "WASI") |
| 69 | + # On WASI, we use vendored BlocksRuntime instead of the one from libdispatch |
| 70 | + add_subdirectory(BlockRuntime) |
| 71 | + # Add BlocksRuntime object library to CoreFoundation static archive |
| 72 | +diff --git a/Sources/_CFXMLInterface/CMakeLists.txt b/Sources/_CFXMLInterface/CMakeLists.txt |
| 73 | +index 9cfe63cd..80c75205 100644 |
| 74 | +--- a/Sources/_CFXMLInterface/CMakeLists.txt |
| 75 | ++++ b/Sources/_CFXMLInterface/CMakeLists.txt |
| 76 | +@@ -32,7 +32,7 @@ target_link_libraries(_CFXMLInterface PRIVATE |
| 77 | + dispatch |
| 78 | + LibXml2::LibXml2) |
| 79 | + |
| 80 | +-if(CMAKE_SYSTEM_NAME STREQUAL WASI) |
| 81 | ++if(CMAKE_SYSTEM_NAME STREQUAL "WASI") |
| 82 | + target_link_libraries(_CFXMLInterface PRIVATE BlocksRuntime) |
| 83 | + endif() |
| 84 | + |
| 85 | +-- |
| 86 | +2.46.0 |
| 87 | + |
0 commit comments