Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for compilation and test on Windows #116

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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