@@ -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+
171232enable_testing ()
172233macro (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})
179240endmacro (maketest )
180241macro (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})
185246endmacro (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 )
271332endif ()
272333
273334# Documentation
0 commit comments