From 125f80ec730a3913d64a704b63ed980f5c8117f0 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Fri, 9 Feb 2024 10:00:50 +0100 Subject: [PATCH] Add support for compilation and test on Windows Tested on Visual Studio 2022 --- CMakeLists.txt | 18 ++++++++++++++++++ tests/CMakeLists.txt | 6 ++++-- tests/static_string.cpp | 5 +++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d47b08..ae7a808 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,13 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") add_compile_options(-Werror -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wsign-conversion -Wold-style-cast) endif() +if(MSVC) + # On Windows, also ensure that all .dll libraries are placed in the + # same build directory so they can be found by the loader (there is + # no rpath on Windows) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") +endif() + option(BUILD_SHARED_LIBS "Build shared libraries" ON) add_library(rsl @@ -30,6 +37,17 @@ target_link_libraries(rsl PUBLIC tl_expected::tl_expected ) +# There is no explicit export of symbols in the library either via +# hand-written ***_export.h headers or generate_export_header CMake macro, +# as the header-only functions in this library are quite limited in number, +# it is perfectly ok to export all of them (as done in *nix) with the +# WINDOWS_EXPORT_ALL_SYMBOLS property +if(MSVC) + set_target_properties(rsl PROPERTIES + WINDOWS_EXPORT_ALL_SYMBOLS TRUE + ) +endif() + add_subdirectory(docs) option(RSL_BUILD_TESTING "Build tests" OFF) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index db03179..adb037b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,8 +14,10 @@ add_executable(test-rsl random.cpp static_string.cpp static_vector.cpp - strong_type.cpp - try.cpp) + strong_type.cpp) +if(NOT MSVC) + target_sources(test-rsl PRIVATE try.cpp) +endif() target_link_libraries(test-rsl PRIVATE rsl::rsl Catch2::Catch2WithMain diff --git a/tests/static_string.cpp b/tests/static_string.cpp index 9b570ca..613b7df 100644 --- a/tests/static_string.cpp +++ b/tests/static_string.cpp @@ -20,9 +20,10 @@ TEST_CASE("rsl::StaticString") { SECTION("Collection constructor") { auto const string = "Hello, world!"s; - auto const static_string = rsl::StaticString<14>(string); + constexpr int string_capacity = 14; + auto const static_string = rsl::StaticString(string); CHECK(static_string.begin() != static_string.end()); - auto const* begin = static_string.begin(); + std::array::const_iterator begin = static_string.begin(); CHECK(*begin++ == 'H'); CHECK(*begin++ == 'e'); CHECK(*begin++ == 'l');