From 5eebe293261fa357fc09f2654e7f76b976f40945 Mon Sep 17 00:00:00 2001 From: FoolHen Date: Wed, 10 Jun 2026 17:09:25 +0200 Subject: [PATCH] Fix test build failures on Arch with Catch2 v3 and GCC 16 - Add missing include in AlsaDriverTest.cpp for sleep(). - Link Catch2::Catch2WithMain alongside Catch2::Catch2 for pipedaltest and jsonTest test targets. Catch2 v3 requires this for CATCH_CONFIG_MAIN to provide the main() entry point. --- src/AlsaDriverTest.cpp | 1 + src/CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/AlsaDriverTest.cpp b/src/AlsaDriverTest.cpp index 938ce44..ac3e78f 100644 --- a/src/AlsaDriverTest.cpp +++ b/src/AlsaDriverTest.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "AlsaDriver.hpp" #include "ChannelRouterSettings.hpp" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f8a8f36..968960e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,32 @@ set(CXX_STANDARD 20) find_package(PkgConfig REQUIRED) +find_package(Catch2 QUIET) + +# Catch2 v3 (Arch, newer distros) uses multi-headers under . +# Catch2 v2 (Debian/Ubuntu) provides a single catch.hpp at system level. +# When Catch2 v3 is found via CMake, generate compatibility wrappers so +# old-style #include "catch.hpp" and #include still work. +if(Catch2_FOUND) + # Generate catch.hpp wrapper in the build directory. + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/catch.hpp" + "#pragma once\n" + "#include \n" + ) + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/catch") + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/catch/catch.hpp" + "#pragma once\n" + "#include \n" + ) + # Add the build directory to the global include paths so that + # both #include "catch.hpp" (quote) and #include (angle) + # can find the compatibility wrappers. + include_directories(${CMAKE_CURRENT_BINARY_DIR}) + message(STATUS "Catch2 v3 found. Generated compatibility wrappers in ${CMAKE_CURRENT_BINARY_DIR}") +else() + message(STATUS "Catch2 CMake package not found. Expecting system catch.hpp (Catch2 v2 style).") +endif() + pkg_check_modules(PipeWire REQUIRED libpipewire-0.3) include(FetchContent) @@ -472,6 +498,10 @@ add_executable(pipedaltest target_link_libraries(pipedaltest PRIVATE ${PIPEDAL_LIBS} ${ICU_LIBRARIES}) target_include_directories(pipedaltest PRIVATE ${PIPEDAL_INCLUDES}) +if(Catch2_FOUND) + target_link_libraries(pipedaltest PRIVATE Catch2::Catch2 Catch2::Catch2WithMain) +endif() + set_target_properties(pipedaltest PROPERTIES EXCLUDE_FROM_ALL ${PIPEDAL_EXCLUDE_TESTS}) if (NOT GITHUB_ACTIONS) # Google perftools are not available on Github action servers. @@ -502,6 +532,10 @@ add_executable(jsonTest target_link_libraries(jsonTest PRIVATE PiPedalCommon) target_include_directories(jsonTest PRIVATE ${PIPEDAL_INCLUDES}) +if(Catch2_FOUND) + target_link_libraries(jsonTest PRIVATE Catch2::Catch2 Catch2::Catch2WithMain) +endif() + set_target_properties(jsonTest PROPERTIES EXCLUDE_FROM_ALL ${PIPEDAL_EXCLUDE_TESTS})