Skip to content

Commit 81c85f5

Browse files
committed
cmake: Support for building on Windows
1 parent 1e7ec70 commit 81c85f5

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
- macos-15
3232
- macos-14
3333
- macos-13
34+
- windows-2022
35+
- windows-2019
3436
steps:
3537
- uses: actions/checkout@v4
3638
- run: bash -x build-cmake.sh

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ option(BUILD_SHARED_LIBS "Build libraries as SHARED" TRUE)
55

66
add_library(mpi_abi mpistubs.c)
77
set_target_properties(mpi_abi PROPERTIES VERSION 0)
8+
set_target_properties(mpi_abi PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1)
89

910
include(GNUInstallDirs)
1011
install(FILES mpi.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

build-cmake.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
set -eu
33
cmake -B build -DCMAKE_INSTALL_PREFIX="${PREFIX:-$PWD}"
4-
cmake --build build
5-
cmake --install build
4+
cmake --build build --config Release
5+
cmake --install build --config Release
66
(test -d lib64 && ln -f -s lib64 lib) || true

check.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ export PATH=${prefix}/bin:$PATH
66

77
case "$(uname)" in
88
Linux)
9+
lib="lib"
910
so=".so"
1011
;;
1112
Darwin)
1213
ldd () { otool -L "$1"; }
14+
lib="lib"
1315
so=".dylib"
1416
;;
17+
*_NT-*)
18+
lib=""
19+
so=".dll"
20+
;;
1521
esac
1622

1723
tempdir="$(mktemp -d)"
@@ -41,13 +47,11 @@ command -v mpicc
4147
command -v mpicxx
4248
echo "$(mpicc -show-incdir)/mpi.h":
4349
grep -E 'MPI_(SUB)?VERSION' "$(mpicc -show-incdir)/mpi.h"
44-
echo "$(mpicc -show-libdir)/lib$(mpicc -show-libs)$so":
45-
ldd "$(mpicc -show-libdir)/lib$(mpicc -show-libs)$so"
50+
echo "$(mpicc -show-libdir)/$lib$(mpicc -show-libs)$so":
51+
ldd "$(mpicc -show-libdir)/$lib$(mpicc -show-libs)$so"
4652

4753
set -x
4854

49-
RPATH=-Wl,-rpath,$(mpicc -show-libdir)
50-
5155
mpicc -show
5256
mpicc -show-incdir
5357
mpicc -show-libdir
@@ -58,8 +62,8 @@ for cc in gcc clang; do
5862
diff cc.log mpicc.log
5963
mpicc -cc="$cc" ./helloworld.c -c
6064
test -f helloworld.o && rm helloworld.o
61-
mpicc -cc="$cc" ./helloworld.c "$RPATH"
62-
ldd a.out && rm a.out
65+
mpicc -cc="$cc" ./helloworld.c -o hw.exe
66+
ldd hw.exe && rm hw.exe
6367
done
6468

6569
mpicxx -show
@@ -72,6 +76,6 @@ for cxx in g++ clang++; do
7276
diff cxx.log mpicxx.log
7377
mpicxx -cxx="$cxx" ./helloworld.cxx -c
7478
test -f helloworld.o && rm helloworld.o
75-
mpicxx -cxx="$cxx" ./helloworld.cxx "$RPATH"
76-
ldd a.out && rm a.out
79+
mpicxx -cxx="$cxx" ./helloworld.cxx -o hw.exe
80+
ldd hw.exe && rm hw.exe
7781
done

0 commit comments

Comments
 (0)