Skip to content

Commit ea78184

Browse files
MinGW
1 parent 4030350 commit ea78184

4 files changed

Lines changed: 177 additions & 8 deletions

File tree

.github/workflows/ccpp.yml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: "Windows MSVC",
1414
enabled: 1,
1515
os: windows-latest,
16-
deps: "",
16+
deps1: "",
1717
config: "cmake
1818
-B build
1919
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
@@ -23,11 +23,31 @@ jobs:
2323
build: "cmake --build build --config Release",
2424
test: "ctest --output-on-failure --test-dir build"
2525
}
26+
- {
27+
name: "MinGW",
28+
enabled: 1,
29+
os: ubuntu-latest,
30+
update: "sudo apt-get update",
31+
deps1: "sudo apt-get install -y mingw-w64 cmake ninja-build wine64",
32+
deps2: "./build-mingw-deps $RUNNER_TEMP",
33+
config: "PKG_CONFIG_PATH=$RUNNER_TEMP/prefix/lib/pkgconfig
34+
cmake
35+
-S .
36+
-B build
37+
-G Ninja
38+
-DRTOSC_WERROR=ON
39+
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/mingw64.cmake
40+
-DMINGW_PREFIX=$RUNNER_TEMP/prefix
41+
-DCMAKE_BUILD_TYPE=Debug
42+
",
43+
build: "cmake --build build --config Debug",
44+
test: "ctest --output-on-failure --test-dir build"
45+
}
2646
- {
2747
name: "Ubuntu gcc",
2848
enabled: 1,
2949
os: ubuntu-latest,
30-
deps: "sudo apt-get install liblo-dev",
50+
deps1: "sudo apt-get install liblo-dev",
3151
config: "cd build && cmake -DRTOSC_WERROR=1 ..",
3252
build: "cd build && make",
3353
test: "cd build && ctest --output-on-failure"
@@ -36,7 +56,7 @@ jobs:
3656
name: "Ubuntu clang+lld",
3757
enabled: 1,
3858
os: ubuntu-latest,
39-
deps: "sudo apt-get install liblo-dev",
59+
deps1: "sudo apt-get install liblo-dev",
4060
config: "cd build &&
4161
cmake
4262
-DRTOSC_WERROR=1
@@ -62,9 +82,15 @@ jobs:
6282
uses: actions/checkout@v4
6383
with:
6484
fetch-depth: 0
65-
- name: install deps
85+
- name: update system
86+
if: ${{ matrix.config.enabled == 1 }}
87+
run: ${{ matrix.config.update }}
88+
- name: install deps (1)
89+
if: ${{ matrix.config.enabled == 1 }}
90+
run: ${{ matrix.config.deps1 }}
91+
- name: install deps (2)
6692
if: ${{ matrix.config.enabled == 1 }}
67-
run: ${{ matrix.config.deps }}
93+
run: ${{ matrix.config.deps2 }}
6894
- name: create build directory
6995
if: ${{ matrix.config.enabled == 1 }}
7096
run: mkdir build

CMakeLists.txt

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,79 @@ endif(BUILD_RTOSC_EXAMPLES)
168168

169169

170170
# Testing Code
171+
172+
173+
function(rtosc_add_test testname testbinary)
174+
# Remaining arguments are test args
175+
set(test_args ${ARGN})
176+
177+
# Default: native execution
178+
set(cmd ${testbinary})
179+
set(env)
180+
181+
# Condition 1: -DMINGW_PREFIX was passed
182+
# Condition 2: environment variable forces wine
183+
if(DEFINED MINGW_PREFIX OR DEFINED ENV{ZYN_USE_WINE})
184+
185+
# Allow override via environment (useful in CI)
186+
if(DEFINED ENV{RUNNER_TEMP})
187+
set(_runner_temp "$ENV{RUNNER_TEMP}")
188+
else()
189+
set(_runner_temp "")
190+
endif()
191+
192+
# Compose WINEPATH
193+
set(_winepath
194+
"/usr/x86_64-w64-mingw32/bin/;"
195+
"/usr/x86_64-w64-mingw32/lib/;"
196+
"/usr/lib/gcc/x86_64-w64-mingw32/13-win32"
197+
)
198+
199+
if(_runner_temp)
200+
list(APPEND _winepath
201+
"${_runner_temp}/prefix/lib"
202+
"${_runner_temp}/prefix/bin"
203+
)
204+
endif()
205+
206+
# Join with semicolons (WINEPATH wants ;, but ENVIRONMENT PROPERTY also wants it)
207+
list(JOIN _winepath "\\\\;" WINEPATH_VALUE)
208+
209+
# Wine command
210+
set(cmd wine ${testbinary})
211+
212+
# Environment for CTest
213+
set(env "WINEPATH=${WINEPATH_VALUE}")
214+
215+
endif()
216+
217+
# Register test
218+
add_test(
219+
NAME ${testname}
220+
COMMAND ${cmd} ${test_args}
221+
)
222+
223+
# Apply environment only if needed
224+
if(env)
225+
set_tests_properties(${testname}
226+
PROPERTIES ENVIRONMENT "${env}"
227+
)
228+
message(STATUS "${env}")
229+
endif()
230+
endfunction()
231+
171232
enable_testing()
172233
macro(maketest fname)
173234
add_executable(${fname} test/${fname}.c)
174-
add_test(${fname} ${fname})
235+
rtosc_add_test(${fname} ${fname})
175236
target_link_libraries(${fname} PRIVATE rtosc)
176237
target_compile_options(${fname} PRIVATE
177238
"$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-std=c99>")
178239
#add_test(memcheck_${fname} valgrind --leak-check=full --show-reachable=yes --error-exitcode=1 ./${fname})
179240
endmacro(maketest)
180241
macro(maketestcpp fname)
181242
add_executable(${fname} test/${fname}.cpp)
182-
add_test(${fname} ${fname})
243+
rtosc_add_test(${fname} ${fname})
183244
target_link_libraries(${fname} PRIVATE rtosc-cpp rtosc)
184245
#add_test(memcheck_${fname} valgrind --leak-check=full --show-reachable=yes --error-exitcode=1 ./${fname})
185246
endmacro(maketestcpp)
@@ -267,7 +328,7 @@ if(LIBLO_FOUND AND RUBY_FOUND)
267328
target_link_directories(port-checker-testapp PRIVATE ${LIBLO_LIBRARY_DIRS})
268329
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test/test-port-checker.rb
269330
${CMAKE_CURRENT_BINARY_DIR}/test-port-checker.rb COPYONLY)
270-
add_test(test-port-checker test-port-checker.rb)
331+
rtosc_add_test(test-port-checker test-port-checker.rb)
271332
endif()
272333

273334
# Documentation

build-mingw-deps

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
die()
4+
{
5+
echo "$@" >&2
6+
exit 1
7+
}
8+
9+
trap_func()
10+
{
11+
trap - ERR # don't run the trap again
12+
die "Error in line $1 (return code $2)"
13+
}
14+
15+
check_prerequisites()
16+
{
17+
for program in make wget tar autoconf automake x86_64-w64-mingw32-{gcc,ar}
18+
do
19+
command -v "$program" >/dev/null || die "Error: Must have \"$program\" installed"
20+
done
21+
}
22+
23+
main()
24+
{
25+
set -eE
26+
trap 'trap_func $LINENO $?' ERR
27+
28+
check_prerequisites
29+
30+
local tmp_dir
31+
if [ "$1" ]
32+
then
33+
[ -d "$1" ] || die "Error: Directory \"$1\" does not exit"
34+
tmp_dir=$1
35+
else
36+
tmp_dir=$(mktemp -d "/tmp/build-mingw-deps.XXXXXXXXXX")
37+
fi
38+
39+
local urls=(
40+
https://github.com/radarsat1/liblo/archive/refs/tags/0.34.tar.gz # GPL-2.1-only
41+
)
42+
local archives=(liblo-0.34)
43+
44+
# shellcheck disable=SC2043 # loop intended to run once (can be extended for future deps)
45+
for i in 0
46+
do
47+
local tarball=$tmp_dir/${archives[$i]}.tar.gz
48+
[ -f "$tarball" ] || wget "${urls[$i]}" -O "$tarball"
49+
tar -C "$tmp_dir/" -xf "$tarball"
50+
# rm "$tarball"
51+
done
52+
53+
[ -d "$tmp_dir/prefix" ] || mkdir "$tmp_dir/prefix"
54+
55+
(cd "$tmp_dir/liblo-0.34"
56+
./autogen.sh --host=x86_64-w64-mingw32 \
57+
--prefix="$tmp_dir/prefix" \
58+
--disable-shared \
59+
--enable-static \
60+
--disable-doc
61+
make
62+
make install)
63+
}
64+
65+
main "$@"

cmake/toolchains/mingw64.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
set(CMAKE_SYSTEM_NAME Windows)
2+
set(CMAKE_SYSTEM_PROCESSOR x86_64)
3+
4+
# MinGW-W64 compiler
5+
SET(CMAKE_AR x86_64-w64-mingw32-gcc-ar CACHE FILEPATH "Archiver")
6+
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
7+
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
8+
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
9+
SET(CMAKE_LD x86_64-w64-mingw32-gcc)
10+
11+
# Search for libraries only in MinGW root AND the prefix of compiled dependencies
12+
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32 ${MINGW_PREFIX})
13+
14+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
15+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
16+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
17+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

0 commit comments

Comments
 (0)