Skip to content

Commit 589aece

Browse files
committed
Enhancement of WASI_SDK_PREFIX in toolchain files
No need to pass `WASI_SDK_PREFIX` value from the command line. Use `CMAKE_CURRENT_LIST_DIR` to assemble the value of `WASI_SDK_PREFIX` now.
1 parent 8d4dbb1 commit 589aece

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ includes/libraries/etc. The `--sysroot=...` option is not necessary if
8484
`WASI_SDK_PATH` is `/opt/wasi-sdk`. For troubleshooting, one can replace the
8585
`--sysroot` path with a manual build of [wasi-libc].
8686

87+
### Integrating with a CMake build system
88+
89+
Use a toolchain file to setup the *wasi-sdk* platform.
90+
91+
```
92+
$ cmake -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake ...
93+
```
94+
95+
or the *wasi-sdk-thread* platform
96+
97+
```
98+
$ cmake -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk-pthread.cmake ...
99+
```
100+
87101
## Notes for Autoconf
88102

89103
[Autoconf] 2.70 now [recognizes WASI].

wasi-sdk-pthread.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ else()
2121
set(WASI_HOST_EXE_SUFFIX "")
2222
endif()
2323

24+
# When building from source, WASI_SDK_PREFIX represents the generated directory
25+
if(NOT WASI_SDK_PREFIX)
26+
set(WASI_SDK_PREFIX ${CMAKE_CURRENT_LIST_DIR}/../../)
27+
endif()
28+
2429
set(CMAKE_C_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX})
2530
set(CMAKE_CXX_COMPILER ${WASI_SDK_PREFIX}/bin/clang++${WASI_HOST_EXE_SUFFIX})
2631
set(CMAKE_ASM_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX})

wasi-sdk.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ else()
1818
set(WASI_HOST_EXE_SUFFIX "")
1919
endif()
2020

21+
# When building from source, WASI_SDK_PREFIX represents the generated directory
22+
if(NOT WASI_SDK_PREFIX)
23+
set(WASI_SDK_PREFIX ${CMAKE_CURRENT_LIST_DIR}/../../)
24+
endif()
25+
2126
set(CMAKE_C_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX})
2227
set(CMAKE_CXX_COMPILER ${WASI_SDK_PREFIX}/bin/clang++${WASI_HOST_EXE_SUFFIX})
2328
set(CMAKE_ASM_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX})

0 commit comments

Comments
 (0)