Skip to content

Commit

Permalink
Add support for compilation and test on Windows
Browse files Browse the repository at this point in the history
Tested on Visual Studio 2022
  • Loading branch information
traversaro committed Feb 10, 2024
1 parent cebc67c commit 125f80e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/static_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_capacity>(string);
CHECK(static_string.begin() != static_string.end());
auto const* begin = static_string.begin();
std::array<std::string::value_type, string_capacity>::const_iterator begin = static_string.begin();
CHECK(*begin++ == 'H');
CHECK(*begin++ == 'e');
CHECK(*begin++ == 'l');
Expand Down

0 comments on commit 125f80e

Please sign in to comment.