diff --git a/.gitignore b/.gitignore index eaaa5026..cd1a1ce0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ build* /.vs /checks.json /.vscode -install_dir/ +install*/ cmake_build*/ compile_commands.json .cache/ diff --git a/CMakeLists.txt b/CMakeLists.txt index f5fceb91..05bdf5b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,9 @@ option(BOOST_UT_DISABLE_MODULE "Disable ut module" ON) if(NOT BOOST_UT_DISABLE_MODULE) -cmake_minimum_required(VERSION 4.0.0) + cmake_minimum_required(VERSION 4.0.0) else() -cmake_minimum_required(VERSION 3.21...3.25) + cmake_minimum_required(VERSION 3.21...3.25) endif() project( ut @@ -33,16 +33,9 @@ option(BOOST_UT_BUILD_BENCHMARKS "Build the benchmarks" OFF) 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_ENABLE_INSTALL "Enable install targets" ${PROJECT_IS_TOP_LEVEL}) -option(BOOST_UT_USE_WARNINGS_AS_ERORS "Build the tests" ${PROJECT_IS_TOP_LEVEL}) +option(BOOST_UT_USE_WARNINGS_AS_ERRORS "Treat compile warnings as errors" ${PROJECT_IS_TOP_LEVEL}) -add_library(ut INTERFACE) -if(NOT BOOST_UT_DISABLE_MODULE) -add_library(ut_module) -endif() -target_include_directories(ut INTERFACE $) -target_compile_features(ut INTERFACE cxx_std_20) - -if(BOOST_UT_USE_WARNINGS_AS_ERORS) +if(BOOST_UT_USE_WARNINGS_AS_ERRORS) include(cmake/WarningsAsErrors.cmake) endif() @@ -66,52 +59,52 @@ if(BOOST_UT_ENABLE_SANITIZERS) ) endif() -if(BOOST_UT_DISABLE_MODULE) - target_compile_definitions(ut INTERFACE BOOST_UT_DISABLE_MODULE) -endif() - -if(NOT BOOST_UT_DISABLE_MODULE) -target_sources(ut_module PUBLIC FILE_SET CXX_MODULES FILES include/boost/ut.cppm) -endif() - +add_library(ut INTERFACE) if(NOT TARGET Boost::ut) add_library(Boost::ut ALIAS ut) endif() - -if(NOT BOOST_UT_DISABLE_MODULE) -add_library(Boost::ut_module ALIAS ut_module) -endif() - -include(GNUInstallDirs) -include(CMakePackageConfigHelpers) - -install( - FILES include/boost/ut.hpp include/boost/ut.cppm - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/boost -) - +target_compile_features(ut INTERFACE cxx_std_20) +target_sources(ut INTERFACE FILE_SET HEADERS BASE_DIRS include FILES include/boost/ut.hpp) install( TARGETS ut EXPORT ut_Targets - INCLUDES DESTINATION include + FILE_SET HEADERS ) + +if(BOOST_UT_DISABLE_MODULE) + target_compile_definitions(ut INTERFACE BOOST_UT_DISABLE_MODULE) +else() + include(GNUInstallDirs) + + add_library(ut_module) + add_library(Boost::ut_module ALIAS ut_module) + target_compile_features(ut_module PUBLIC cxx_std_23) + set_target_properties(ut_module PROPERTIES CXX_MODULE_STD ON) + target_sources(ut_module PUBLIC FILE_SET CXX_MODULES BASE_DIRS include FILES include/boost/ut.cppm) + target_link_libraries(ut_module PUBLIC Boost::ut) + install( + TARGETS ut_module + EXPORT ut_Targets + FILE_SET CXX_MODULES + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + ) +endif() + install( EXPORT ut_Targets FILE utConfig.cmake NAMESPACE Boost:: DESTINATION lib/cmake/ut + CXX_MODULES_DIRECTORY "." ) +include(CMakePackageConfigHelpers) write_basic_package_version_file( "utConfigVersion.cmake" VERSION ${PROJECT_VERSION} - COMPATIBILITY SameMajorVersion - ARCH_INDEPENDENT -) -install( - FILES "${PROJECT_BINARY_DIR}/utConfigVersion.cmake" - DESTINATION lib/cmake/ut + COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT ) +install(FILES "${PROJECT_BINARY_DIR}/utConfigVersion.cmake" DESTINATION lib/cmake/ut) if(EMSCRIPTEN) set(CMAKE_EXECUTABLE_SUFFIX ".js") diff --git a/include/boost/ut.cppm b/include/boost/ut.cppm index 100ac890..0625db1d 100644 --- a/include/boost/ut.cppm +++ b/include/boost/ut.cppm @@ -6,10 +6,10 @@ module; #endif export module boost.ut; -export import std; +import std; #define BOOST_UT_CXX_MODULES 1 -#include "ut.hpp" +#include template class boost::ut::reporter_junit; template void boost::ut::reporter_junit::on(boost::ut::events::log); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 223784d1..7a318055 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,3 +28,6 @@ endif() add_subdirectory(ut) add_subdirectory(ft) +if(TARGET Boost::ut_module) + add_subdirectory(ut-module) +endif() diff --git a/test/ut-module/CMakeLists.txt b/test/ut-module/CMakeLists.txt new file mode 100644 index 00000000..0a36018f --- /dev/null +++ b/test/ut-module/CMakeLists.txt @@ -0,0 +1,16 @@ +# not using ut_add_custom_command_or_test() to explicitly link against Boost:ut_module +add_executable(from-ut-module main.cpp) +target_compile_features(from-ut-module PRIVATE cxx_std_20) +target_link_libraries(from-ut-module PRIVATE Boost::ut_module) +set_target_properties(from-ut-module PROPERTIES CXX_SCAN_FOR_MODULES ON) + +if(BOOST_UT_ENABLE_RUN_AFTER_BUILD) + add_custom_command( + TARGET from-ut-module + POST_BUILD + COMMAND from-ut-module + COMMENT "Running from-ut-module" + ) +else() + add_test(NAME from-ut-module COMMAND from-ut-module) +endif() \ No newline at end of file diff --git a/test/ut-module/main.cpp b/test/ut-module/main.cpp new file mode 100644 index 00000000..68870602 --- /dev/null +++ b/test/ut-module/main.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2019-2020 Kris Jusiak (kris at jusiak dot net) +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +import boost.ut; + +int main() { + using namespace boost::ut; + + "module"_test = [] { + // clang-format off + expect(42_i == 42 and constant<3 == 3_i>); + // clang-format on + }; +}