diff --git a/CMakeLists.txt b/CMakeLists.txt index d6bb450e..1ca4c4f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,8 @@ option(BOOST_UT_BUILD_EXAMPLES "Build the examples" ${PROJECT_IS_TOP_LEVEL}) option(BOOST_UT_BUILD_TESTS "Build the tests" ${PROJECT_IS_TOP_LEVEL}) option(BOOST_UT_USE_WARNINGS_AS_ERORS "Build the tests" ${PROJECT_IS_TOP_LEVEL}) option(BOOST_UT_DISABLE_MODULE "Disable ut module" OFF) +option(BOOST_UT_ENBLE_MODULE "Enable ut module" OFF) +option(BOOST_UT_DISABLE_STD_INCLUDES "Disble including Standar headers" OFF) option(BOOST_UT_ALLOW_CPM_USE "Do not reach out across network for CPM" ON) if(NOT CMAKE_SKIP_INSTALL_RULES) @@ -80,9 +82,20 @@ if(BOOST_UT_ENABLE_SANITIZERS) endif() if(BOOST_UT_DISABLE_MODULE) + if(BOOST_UT_ENBLE_MODULE) + MESSAGE(FATAL_ERROR "Modules both enabled and disabled") + endif() target_compile_definitions(ut INTERFACE BOOST_UT_DISABLE_MODULE) endif() +if(BOOST_UT_ENBLE_MODULE) + target_compile_definitions(ut INTERFACE BOOST_UT_USE_MODULE) +endif() + +if(BOOST_UT_DISABLE_STD_INCLUDES) + target_compile_definitions(ut INTERFACE BOOST_UT_DISABLE_STD_INCLUDES) +endif() + if(NOT CMAKE_SKIP_INSTALL_RULES) # Create target Boost::ut and install target packageProject( diff --git a/include/boost/ut.hpp b/include/boost/ut.hpp index 531a7411..cc70eebc 100644 --- a/include/boost/ut.hpp +++ b/include/boost/ut.hpp @@ -5,9 +5,15 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // + +#if not defined(BOOST_UT_USE_MODULE) #if defined(__cpp_modules) && !defined(BOOST_UT_DISABLE_MODULE) -export module boost.ut; -export import std; +#define BOOST_UT_USE_MODULE +#endif +#endif + +#if defined(BOOST_UT_USE_MODULE) +module; #define BOOST_UT_EXPORT export #else #pragma once @@ -53,6 +59,7 @@ export import std; #else #define BOOST_UT_VERSION 1'1'9 +#if not defined(BOOST_UT_DISABLE_STD_INCLUDES) #if defined(__has_builtin) and defined(__GNUC__) and (__GNUC__ < 10) and \ not defined(__clang__) #undef __has_builtin @@ -83,10 +90,6 @@ export import std; #include #include #include -#if __has_include() and __has_include() -#include -#include -#endif #if defined(__cpp_exceptions) #include #endif @@ -97,6 +100,17 @@ export import std; #if __has_include() #include #endif +#endif // BOOST_UT_DISABLE_STD_INCLUDES + +#if __has_include() and __has_include() +#include +#include +#endif + +#if defined(BOOST_UT_USE_MODULE) +export module boost.ut; +import std; +#endif struct _unique_name_for_auto_detect_prefix_and_suffix_lenght_0123456789_struct { }; @@ -302,17 +316,23 @@ inline constexpr const std::string_view need_name = "_unique_name_for_auto_detect_prefix_and_suffix_lenght_0123456789_struct"; #endif inline constexpr const std::size_t need_length = need_name.length(); +#if not defined(BOOST_UT_USE_MODULE) static_assert(need_length <= raw_length, "Auto find prefix and suffix lenght broken error 1"); +#endif inline constexpr const std::size_t prefix_length = raw_type_name.find(need_name); +#if not defined(BOOST_UT_USE_MODULE) static_assert(prefix_length != std::string_view::npos, "Auto find prefix and suffix lenght broken error 2"); static_assert(prefix_length <= raw_length, "Auto find prefix and suffix lenght broken error 3"); +#endif inline constexpr const std::size_t tail_lenght = raw_length - prefix_length; +#if not defined(BOOST_UT_USE_MODULE) static_assert(need_length <= tail_lenght, "Auto find prefix and suffix lenght broken error 4"); +#endif inline constexpr const std::size_t suffix_length = tail_lenght - need_length; } // namespace detail