Skip to content
This repository was archived by the owner on Aug 22, 2022. It is now read-only.

Commit e5ed748

Browse files
authored
Update CMake toolchain file for Windows and CMAKE_AR (#297)
1. Use exe suffix to find clang on Windows 2. Only set the tools if they are not already overridden (for some reason this is required for CMAKE_AR and CMAKE_RANLIB to work). 3. Pass --target by default for proper auto-detection of the target platform.
1 parent 1fb5405 commit e5ed748

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/build.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,9 +1168,6 @@ def CompilerRT():
11681168
'-DCMAKE_TOOLCHAIN_FILE=' +
11691169
os.path.join(INSTALL_DIR, 'wasm_standalone.cmake'),
11701170
'-DCMAKE_C_COMPILER_WORKS=ON',
1171-
# TODO: why doesn't setting CMAKE_AR in the toolchain file work?
1172-
'-DCMAKE_AR=' + os.path.join(INSTALL_BIN, 'llvm-ar'),
1173-
'-DCMAKE_RANLIB=' + os.path.join(INSTALL_BIN, 'llvm-ranlib'),
11741171
'-DCOMPILER_RT_BAREMETAL_BUILD=On',
11751172
'-DCOMPILER_RT_BUILD_XRAY=OFF',
11761173
'-DCOMPILER_RT_INCLUDE_TESTS=OFF',

src/wasm_standalone.cmake

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,28 @@ set(CMAKE_SYSTEM_PROCESSOR wasm32)
99
set(triple wasm32-unknown-unknown-wasm)
1010

1111
set(WASM_SDKROOT ${CMAKE_CURRENT_LIST_DIR})
12-
set(CMAKE_C_COMPILER ${WASM_SDKROOT}/bin/clang)
13-
set(CMAKE_CXX_COMPILER ${WASM_SDKROOT}/bin/clang++)
14-
set(CMAKE_AR ${WASM_SDKROOT}/bin/llvm-ar)
15-
set(CMAKE_RANLIB ${WASM_SDKROOT}/bin/llvm-ranlib)
12+
13+
if (CMAKE_HOST_WIN32)
14+
set(EXE_SUFFIX ".exe")
15+
else()
16+
set(EXE_SUFFIX "")
17+
endif()
18+
if ("${CMAKE_C_COMPILER}" STREQUAL "")
19+
set(CMAKE_C_COMPILER ${WASM_SDKROOT}/bin/clang${EXE_SUFFIX})
20+
endif()
21+
if ("${CMAKE_CXX_COMPILER}" STREQUAL "")
22+
set(CMAKE_CXX_COMPILER ${WASM_SDKROOT}/bin/clang++${EXE_SUFFIX})
23+
endif()
24+
if ("${CMAKE_AR}" STREQUAL "")
25+
set(CMAKE_AR ${WASM_SDKROOT}/bin/llvm-ar${EXE_SUFFIX} CACHE FILEPATH "llvm ar")
26+
endif()
27+
if ("${CMAKE_RANLIB}" STREQUAL "")
28+
set(CMAKE_RANLIB ${WASM_SDKROOT}/bin/llvm-ranlib${EXE_SUFFIX} CACHE FILEPATH "llvm ranlib")
29+
endif()
1630
set(CMAKE_C_COMPILER_TARGET ${triple})
1731
set(CMAKE_CXX_COMPILER_TARGET ${triple})
32+
set(CMAKE_C_FLAGS --target=${triple})
33+
set(CMAKE_CXX_FLAGS --target=${triple})
1834

1935
set(CMAKE_SYSROOT ${WASM_SDKROOT}/sysroot)
2036
set(CMAKE_STAGING_PREFIX ${WASM_SDKROOT}/sysroot)

0 commit comments

Comments
 (0)