From e911899f7116b26bbcbd54629e899f7b9e43f692 Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Sun, 18 Jun 2023 18:55:50 +0200 Subject: [PATCH 1/2] Allows using a pure modular build. This allows the user to force modules to be used. Since the std module is enable it's not needed to include the Standard library headers. Clang 17 does not work properly in this case, so allow users to avoid these includes. Note static_asserts can't be exported so they are disabled. --- CMakeLists.txt | 13 +++++++++++++ include/boost/ut.hpp | 24 ++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) 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 b4dbef74..6c8346e4 100644 --- a/include/boost/ut.hpp +++ b/include/boost/ut.hpp @@ -5,7 +5,14 @@ // (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) +#define BOOST_UT_USE_MODULE +#endif +#endif + +#if defined(BOOST_UT_USE_MODULE) export module boost.ut; export import std; #define BOOST_UT_EXPORT export @@ -41,6 +48,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 @@ -70,10 +78,6 @@ export import std; #include #include #include -#if __has_include() and __has_include() -#include -#include -#endif #if defined(__cpp_exceptions) #include #endif @@ -81,6 +85,12 @@ export import std; #if __has_include() #include #endif +#endif // BOOST_UT_DISABLE_STD_INCLUDES + +#if __has_include() and __has_include() +#include +#include +#endif struct unique_name_for_auto_detect_prefix_and_suffix_lenght_0123456789_struct { }; @@ -274,17 +284,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 From a7d50f463c187c6bc456b280bf014ee76f7e1f33 Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Sat, 16 Dec 2023 20:10:45 +0100 Subject: [PATCH 2/2] Loads system headers in the module purview. This attaches the named declaration to the global module fragment instead of to the ut module. Also avoids exporting the std module. --- include/boost/ut.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/boost/ut.hpp b/include/boost/ut.hpp index 82ca25d5..cc70eebc 100644 --- a/include/boost/ut.hpp +++ b/include/boost/ut.hpp @@ -13,8 +13,7 @@ #endif #if defined(BOOST_UT_USE_MODULE) -export module boost.ut; -export import std; +module; #define BOOST_UT_EXPORT export #else #pragma once @@ -108,6 +107,11 @@ export import std; #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 { };