From 92e0480d9d209ddf2f5f416ac0a267e47e621162 Mon Sep 17 00:00:00 2001 From: Thomas Debrunner Date: Tue, 2 Apr 2024 15:06:54 +0200 Subject: [PATCH] make tests build under mingw --- cmake/toolchain-mingw64.cmake | 17 +++++++++++++++++ tests/CMakeLists.txt | 6 ++++++ tests/MessageSet.cpp | 16 ++++++++++++++++ tests/test_main.cpp | 1 + 4 files changed, 40 insertions(+) create mode 100644 cmake/toolchain-mingw64.cmake diff --git a/cmake/toolchain-mingw64.cmake b/cmake/toolchain-mingw64.cmake new file mode 100644 index 0000000..cb3e5fa --- /dev/null +++ b/cmake/toolchain-mingw64.cmake @@ -0,0 +1,17 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Windows) + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc-posix) +set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++-posix) + +# here we specify the root directory of the target environment +set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32) + +# adjust the default behaviour of the FIND_ commands: +# search programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +# for libraries and headers in the target environment +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a46f263..9f97c3e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,3 +14,9 @@ target_compile_options(tests PRIVATE -O0 -g --coverage -Wall -Wextra -pedantic) target_link_options(tests PRIVATE --coverage) target_include_directories(tests PRIVATE ../include) target_link_libraries(tests PRIVATE Threads::Threads) + +if(WIN32) + message(STATUS "Building for Windows") + add_compile_definitions(WINVER=0x0601 _WIN32_WINNT=0x0601) # require at least Windows 7 + target_link_libraries(tests PRIVATE wsock32 ws2_32) +endif() diff --git a/tests/MessageSet.cpp b/tests/MessageSet.cpp index 46093ed..e37de35 100644 --- a/tests/MessageSet.cpp +++ b/tests/MessageSet.cpp @@ -9,6 +9,7 @@ using namespace mav; +#ifndef _NO_STD_FILESYSTEM std::string dump_minimal_xml() { // write temporary file auto temp_path = std::filesystem::temp_directory_path(); @@ -18,12 +19,20 @@ std::string dump_minimal_xml() { out.close(); return xml_file.u8string(); } +#endif TEST_CASE("Message set creation") { +#ifndef _NO_STD_FILESYSTEM + // test loading from file for systems with std::filesystem auto file_name = dump_minimal_xml(); MessageSet message_set{file_name}; std::remove(file_name.c_str()); +#else + // just load from the string for systems without filesystem + MessageSet message_set; + message_set.addFromXMLString(minimal_xml); +#endif CHECK_EQ(message_set.size(), 2); @@ -65,9 +74,16 @@ TEST_CASE("Message set creation") { } TEST_CASE("Create messages from set") { +#ifndef _NO_STD_FILESYSTEM + // test loading from file for systems with std::filesystem auto file_name = dump_minimal_xml(); MessageSet message_set{file_name}; std::remove(file_name.c_str()); +#else + // just load from the string for systems without filesystem + MessageSet message_set; + message_set.addFromXMLString(minimal_xml); +#endif REQUIRE(message_set.contains("HEARTBEAT")); SUBCASE("Can create message from name") { diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 1058417..db6d3a8 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -2,4 +2,5 @@ // Created by thomas on 01.02.23. // #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include #include "doctest.h"