feat: allow configuring GSL library use

Resolves #576
This commit is contained in:
Mateusz Pusz
2024-05-30 12:23:14 +02:00
parent 3a792b4057
commit a6562acde5
20 changed files with 199 additions and 94 deletions
+22 -6
View File
@@ -23,21 +23,37 @@
cmake_minimum_required(VERSION 3.5)
# find dependencies
if(NOT TARGET gsl::gsl-lite)
find_package(gsl-lite REQUIRED)
endif()
if(${projectPrefix}BUILD_CXX_MODULES)
add_library(example_utils INTERFACE)
target_compile_features(example_utils INTERFACE cxx_std_20)
target_compile_definitions(example_utils INTERFACE ${projectPrefix}MODULES)
target_include_directories(example_utils INTERFACE include)
target_link_libraries(example_utils INTERFACE gsl::gsl-lite)
endif()
add_library(example_utils-headers INTERFACE)
target_include_directories(example_utils-headers INTERFACE include)
target_link_libraries(example_utils-headers INTERFACE gsl::gsl-lite)
if(${projectPrefix}API_CONTRACTS STREQUAL "NONE")
target_compile_definitions(mp-units-core INTERFACE ${projectPrefix}API_CONTRACTS=0)
elseif(${projectPrefix}API_CONTRACTS STREQUAL "GSL-LITE")
if(NOT TARGET gsl::gsl-lite)
find_package(gsl-lite REQUIRED)
endif()
if(${projectPrefix}BUILD_CXX_MODULES)
target_link_libraries(example_utils INTERFACE gsl::gsl-lite)
endif()
target_link_libraries(example_utils-headers INTERFACE gsl::gsl-lite)
target_compile_definitions(mp-units-core INTERFACE ${projectPrefix}API_CONTRACTS=2)
elseif(${projectPrefix}API_CONTRACTS STREQUAL "MS-GSL")
if(NOT TARGET Microsoft.GSL::GSL)
find_package(Microsoft.GSL REQUIRED)
endif()
if(${projectPrefix}BUILD_CXX_MODULES)
target_link_libraries(example_utils INTERFACE Microsoft.GSL::GSL)
endif()
target_link_libraries(example_utils-headers INTERFACE Microsoft.GSL::GSL)
target_compile_definitions(mp-units-core INTERFACE ${projectPrefix}API_CONTRACTS=3)
endif()
#
# add_example(target <depependencies>...)
+2 -3
View File
@@ -22,7 +22,6 @@
#pragma once
#include <gsl/gsl-lite.hpp>
#include <mp-units/bits/hacks.h>
#include <mp-units/compat_macros.h>
#include <compare> // IWYU pragma: export
@@ -50,13 +49,13 @@ public:
requires std::copyable<T>
: value_(value)
{
gsl_Expects(validate(value_));
MP_UNITS_EXPECTS(validate(value_));
}
constexpr explicit validated_type(T&& value) noexcept(std::is_nothrow_move_constructible_v<T>) :
value_(std::move(value))
{
gsl_Expects(validate(value_));
MP_UNITS_EXPECTS(validate(value_));
}
constexpr validated_type(const T& value, validated_tag) noexcept(std::is_nothrow_copy_constructible_v<T>)