Skip to content

Commit e058742

Browse files
committed
[openmp][wasm] Inform CMake of a new WebAssembly target
This change touches CMake files only. It sets up a new `LIBOMP_ARCH` option--`wasm32`--and provides a handy `WASM` shortcut variable for internal CMake use like other targets do. This also disables shared library support (WebAssembly expects a static one) and the `LIBOMPTARGET` functionality when targeting WebAssembly.
1 parent 07fee05 commit e058742

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

openmp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ set(ENABLE_LIBOMPTARGET ON)
9494
# Since the device plugins are only supported on Linux anyway,
9595
# there is no point in trying to compile libomptarget on other OSes.
9696
# 32-bit systems are not supported either.
97-
if (APPLE OR WIN32 OR NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
97+
if (APPLE OR WIN32 OR WASM OR NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
9898
set(ENABLE_LIBOMPTARGET OFF)
9999
endif()
100100

openmp/runtime/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if(${OPENMP_STANDALONE_BUILD})
3030
# If adding a new architecture, take a look at cmake/LibompGetArchitecture.cmake
3131
libomp_get_architecture(LIBOMP_DETECTED_ARCH)
3232
set(LIBOMP_ARCH ${LIBOMP_DETECTED_ARCH} CACHE STRING
33-
"The architecture to build for (x86_64/i386/arm/ppc64/ppc64le/aarch64/mic/mips/mips64/riscv64/loongarch64/ve/s390x).")
33+
"The architecture to build for (x86_64/i386/arm/ppc64/ppc64le/aarch64/mic/mips/mips64/riscv64/loongarch64/ve/s390x/wasm32).")
3434
# Should assertions be enabled? They are on by default.
3535
set(LIBOMP_ENABLE_ASSERTIONS TRUE CACHE BOOL
3636
"enable assertions?")
@@ -67,6 +67,8 @@ else() # Part of LLVM build
6767
set(LIBOMP_ARCH ve)
6868
elseif(LIBOMP_NATIVE_ARCH MATCHES "s390x")
6969
set(LIBOMP_ARCH s390x)
70+
elseif(LIBOMP_NATIVE_ARCH MATCHES "wasm")
71+
set(LIBOMP_ARCH wasm32)
7072
else()
7173
# last ditch effort
7274
libomp_get_architecture(LIBOMP_ARCH)
@@ -87,7 +89,7 @@ if(LIBOMP_ARCH STREQUAL "aarch64")
8789
endif()
8890
endif()
8991

90-
libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 aarch64_a64fx mic mips mips64 riscv64 loongarch64 ve s390x)
92+
libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 aarch64_a64fx mic mips mips64 riscv64 loongarch64 ve s390x wasm32)
9193

9294
set(LIBOMP_LIB_TYPE normal CACHE STRING
9395
"Performance,Profiling,Stubs library (normal/profile/stubs)")
@@ -168,6 +170,7 @@ set(RISCV64 FALSE)
168170
set(LOONGARCH64 FALSE)
169171
set(VE FALSE)
170172
set(S390X FALSE)
173+
set(WASM FALSE)
171174
if("${LIBOMP_ARCH}" STREQUAL "i386" OR "${LIBOMP_ARCH}" STREQUAL "32") # IA-32 architecture
172175
set(IA32 TRUE)
173176
elseif("${LIBOMP_ARCH}" STREQUAL "x86_64" OR "${LIBOMP_ARCH}" STREQUAL "32e") # Intel(R) 64 architecture
@@ -198,6 +201,8 @@ elseif("${LIBOMP_ARCH}" STREQUAL "ve") # VE architecture
198201
set(VE TRUE)
199202
elseif("${LIBOMP_ARCH}" STREQUAL "s390x") # S390x (Z) architecture
200203
set(S390X TRUE)
204+
elseif("${LIBOMP_ARCH}" STREQUAL "wasm32") # WebAssembly architecture
205+
set(WASM TRUE)
201206
endif()
202207

203208
# Set some flags based on build_type
@@ -306,6 +311,11 @@ endif()
306311
set(LIBOMP_ENABLE_SHARED TRUE CACHE BOOL
307312
"Shared library instead of static library?")
308313

314+
if(WASM)
315+
libomp_warning_say("The WebAssembly build currently only supports static libraries; forcing LIBOMP_ENABLE_SHARED to false")
316+
set(LIBOMP_ENABLE_SHARED FALSE)
317+
endif()
318+
309319
if(WIN32 AND NOT LIBOMP_ENABLE_SHARED)
310320
libomp_error_say("Static libraries requested but not available on Windows")
311321
endif()

openmp/runtime/cmake/LibompGetArchitecture.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ function(libomp_get_architecture return_arch)
5353
#error ARCHITECTURE=ve
5454
#elif defined(__s390x__)
5555
#error ARCHITECTURE=s390x
56+
#elif defined(__wasm32__)
57+
#error ARCHITECTURE=wasm32
5658
#else
5759
#error ARCHITECTURE=UnknownArchitecture
5860
#endif

openmp/runtime/cmake/config-ix.cmake

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,20 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Intel" OR CMAKE_C_COMPILER_ID STREQUAL "IntelLL
150150
check_library_exists(irc_pic _intel_fast_memcpy "" LIBOMP_HAVE_IRC_PIC_LIBRARY)
151151
endif()
152152

153-
# Checking Threading requirements
154-
find_package(Threads REQUIRED)
155-
if(WIN32)
156-
if(NOT CMAKE_USE_WIN32_THREADS_INIT)
157-
libomp_error_say("Need Win32 thread interface on Windows.")
158-
endif()
159-
else()
160-
if(NOT CMAKE_USE_PTHREADS_INIT)
161-
libomp_error_say("Need pthread interface on Unix-like systems.")
153+
# Checking threading requirements. Note that compiling to WebAssembly threads
154+
# with either the Emscripten or wasi-threads flavor ends up using the pthreads
155+
# interface in a WebAssembly-compiled libc; CMake does not yet know how to
156+
# detect this.
157+
if (NOT WASM)
158+
find_package(Threads REQUIRED)
159+
if(WIN32)
160+
if(NOT CMAKE_USE_WIN32_THREADS_INIT)
161+
libomp_error_say("Need Win32 thread interface on Windows.")
162+
endif()
163+
else()
164+
if(NOT CMAKE_USE_PTHREADS_INIT)
165+
libomp_error_say("Need pthread interface on Unix-like systems.")
166+
endif()
162167
endif()
163168
endif()
164169

0 commit comments

Comments
 (0)