From b018ce4f7e3052be0ba55a95bf27d048ebf3650b Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 12 Feb 2026 14:10:42 +0100 Subject: [PATCH 1/4] Make import std; usable Add FILE_SET HEADERS too support generic installation --- .gitignore | 3 + CMakeLists.txt | 125 ++++++++++++++++++++++---- modules/boost_type_index.cppm | 14 ++- test/cmake_subdir_test/CMakeLists.txt | 28 +++--- 4 files changed, 129 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index e051528..217f5bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ doc/autodoc.xml doc/html +build +compile_commands.json +GNUmakefile diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ec3256..17a8d97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,42 +1,129 @@ -# Generated by `boostdep --cmake type_index` +# ----------------------------------------------------------------------------- +# Boost.type_index CMake +# Handles: no modules, modules, modules + import std; +# ----------------------------------------------------------------------------- # Copyright 2020, 2021 Peter Dimov # Distributed under the Boost Software License, Version 1.0. # https://www.boost.org/LICENSE_1_0.txt -cmake_minimum_required(VERSION 3.5...3.31) +cmake_minimum_required(VERSION 3.21...4.2) project(boost_type_index VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) -if (BOOST_USE_MODULES) +if(PROJECT_IS_TOP_LEVEL) + find_package(Boost 1.90.0 CONFIG) +endif() + +# ----------------------------------------------------------------------------- +# User option: enable C++ modules +# ----------------------------------------------------------------------------- +option(BOOST_USE_MODULES "Build Boost using C++ modules" OFF) + +# ----------------------------------------------------------------------------- +# Determine target type and sources +# ----------------------------------------------------------------------------- +if(BOOST_USE_MODULES) + + # Ensure CMAKE_CXX_STANDARD is set for module detection + if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 20) + endif() + add_library(boost_type_index) - target_sources(boost_type_index PUBLIC - FILE_SET modules_public TYPE CXX_MODULES FILES modules/boost_type_index.cppm + + target_sources(boost_type_index + PUBLIC + FILE_SET modules_public + TYPE CXX_MODULES + FILES modules/boost_type_index.cppm ) - target_compile_features(boost_type_index PUBLIC cxx_std_20) + # Require C++20 for modules + target_compile_features(boost_type_index PUBLIC cxx_std_${CMAKE_CXX_STANDARD}) + # Define macro indicating modules usage target_compile_definitions(boost_type_index PUBLIC BOOST_USE_MODULES) - if (CMAKE_CXX_COMPILER_IMPORT_STD) - target_compile_definitions(boost_type_index PRIVATE BOOST_TYPE_INDEX_USE_STD_MODULE) - message(STATUS "Using `import std;`") + + # Check if import std; is available for the current standard + if(${CMAKE_CXX_STANDARD} IN_LIST CMAKE_CXX_COMPILER_IMPORT_STD) + target_compile_definitions(boost_type_index PUBLIC BOOST_TYPE_INDEX_USE_STD_MODULE) + set_propery(TARGET boost_type_index CXX_MODULE_STD ON) + message(STATUS "Boost.type_index: Using `import std;`") else() - message(STATUS "`import std;` is not awailable") + message(WARNING "Boost.type_index: `import std;` is not available for C++${CMAKE_CXX_STANDARD}") endif() + set(__scope PUBLIC) + else() + + # Modules disabled -> INTERFACE library add_library(boost_type_index INTERFACE) + + # Verify interface headers only at top level + if(PROJECT_IS_TOP_LEVEL) + set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ON) + endif() + set(__scope INTERFACE) + endif() -target_include_directories(boost_type_index ${__scope} include) -add_library(Boost::type_index ALIAS boost_type_index) +# ----------------------------------------------------------------------------- +# Include headers +# ----------------------------------------------------------------------------- +if(CMAKE_VERSION VERSION_LESS 3.23) + target_include_directories(boost_type_index ${__scope} include) +else() + target_sources( + boost_type_index + ${__scope} + FILE_SET headers_public + TYPE HEADERS + BASE_DIRS include + FILES + include/boost/type_index.hpp + include/boost/type_index/runtime_cast.hpp + include/boost/type_index/stl_type_index.hpp + include/boost/type_index/detail/compile_time_type_info.hpp + include/boost/type_index/detail/stl_register_class.hpp + include/boost/type_index/detail/config.hpp + include/boost/type_index/detail/ctti_register_class.hpp + include/boost/type_index/ctti_type_index.hpp + include/boost/type_index/runtime_cast/std_shared_ptr_cast.hpp + include/boost/type_index/runtime_cast/detail/runtime_cast_impl.hpp + include/boost/type_index/runtime_cast/register_runtime_class.hpp + include/boost/type_index/runtime_cast/pointer_cast.hpp + include/boost/type_index/runtime_cast/reference_cast.hpp + include/boost/type_index/runtime_cast/boost_shared_ptr_cast.hpp + include/boost/type_index/type_index_facade.hpp + ) -target_link_libraries(boost_type_index - ${__scope} - Boost::config - Boost::container_hash - Boost::throw_exception -) + # If modules are disabled, require C++17 for headers + if(NOT BOOST_USE_MODULES) + target_compile_features(boost_type_index ${__scope} cxx_std_17) + endif() +endif() + +# ----------------------------------------------------------------------------- +# Link dependencies +# ----------------------------------------------------------------------------- +if(PROJECT_IS_TOP_LEVEL) + target_link_libraries(boost_any ${__scope} Boost::headers) +else() + target_link_libraries(boost_type_index + ${__scope} + Boost::config + Boost::container_hash + Boost::throw_exception + ) +endif() + +# Alias for convenient import +add_library(Boost::type_index ALIAS boost_type_index) +# ----------------------------------------------------------------------------- +# Testing +# ----------------------------------------------------------------------------- if(BUILD_TESTING) - add_subdirectory(test) + add_subdirectory(test) endif() diff --git a/modules/boost_type_index.cppm b/modules/boost_type_index.cppm index 6f53dda..7023476 100644 --- a/modules/boost_type_index.cppm +++ b/modules/boost_type_index.cppm @@ -9,8 +9,6 @@ module; #include -#include -#include #if __has_include() # include @@ -21,7 +19,11 @@ module; #include #include -#ifndef BOOST_TYPE_INDEX_USE_STD_MODULE +#ifdef BOOST_TYPE_INDEX_USE_STD_MODULE +import std; +#else +#include +#include #include #include #include @@ -36,12 +38,6 @@ module; export module boost.type_index; -#ifdef BOOST_TYPE_INDEX_USE_STD_MODULE -// Should not be in the global module fragment -// https://eel.is/c++draft/module#global.frag-1 -import std; -#endif - #ifdef __clang__ # pragma clang diagnostic ignored "-Winclude-angled-in-module-purview" #endif diff --git a/test/cmake_subdir_test/CMakeLists.txt b/test/cmake_subdir_test/CMakeLists.txt index 698e472..4bae3c2 100644 --- a/test/cmake_subdir_test/CMakeLists.txt +++ b/test/cmake_subdir_test/CMakeLists.txt @@ -2,7 +2,7 @@ # 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 -cmake_minimum_required(VERSION 3.5...4.0) +cmake_minimum_required(VERSION 3.21...4.2) project(type_index_subdir_test LANGUAGES CXX) @@ -16,14 +16,16 @@ foreach(dep IN ITEMS smart_ptr throw_exception unordered - predef) + predef +) add_subdirectory(../../../${dep} boostorg/${dep}) endforeach() + add_subdirectory(../../ boostorg/type_index) enable_testing() -if (BOOST_USE_MODULES) +if(BOOST_USE_MODULES) add_executable(boost_type_index_module_usage ../../modules/usage_sample.cpp) target_link_libraries(boost_type_index_module_usage PRIVATE Boost::type_index) add_test(NAME boost_type_index_module_usage COMMAND boost_type_index_module_usage) @@ -32,18 +34,18 @@ if (BOOST_USE_MODULES) add_executable(boost_type_index_module_usage_mu ../../modules/usage_test_mu1.cpp ../../modules/usage_test_mu2.cpp) target_link_libraries(boost_type_index_module_usage_mu PRIVATE Boost::type_index) add_test(NAME boost_type_index_module_usage_mu COMMAND boost_type_index_module_usage_mu) +else() + list(APPEND RUN_TESTS_SOURCES + compare_ctti_stl.cpp + ctti_print_name.cpp + track_13621.cpp + type_index_runtime_cast_test.cpp + type_index_test.cpp + ) endif() -list(APPEND RUN_TESTS_SOURCES - compare_ctti_stl.cpp - ctti_print_name.cpp - track_13621.cpp - type_index_runtime_cast_test.cpp - type_index_test.cpp -) - -foreach (testsourcefile ${RUN_TESTS_SOURCES}) - get_filename_component(testname ${testsourcefile} NAME_WLE) +foreach(testsourcefile ${RUN_TESTS_SOURCES}) + get_filename_component(testname ../${testsourcefile} NAME_WLE) add_executable(${PROJECT_NAME}_${testname} ../${testsourcefile}) target_link_libraries(${PROJECT_NAME}_${testname} Boost::type_index Boost::smart_ptr) add_test(NAME ${PROJECT_NAME}_${testname} COMMAND ${PROJECT_NAME}_${testname}) From dd6bf2f1521a7d6e14339d8991e354885a96b6b2 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 12 Feb 2026 18:02:39 +0100 Subject: [PATCH 2/4] Prevent use of FILE_SET w/o modules --- CMakeLists.txt | 61 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 17a8d97..e9b901d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,11 +31,12 @@ if(BOOST_USE_MODULES) add_library(boost_type_index) - target_sources(boost_type_index + target_sources( + boost_type_index PUBLIC FILE_SET modules_public - TYPE CXX_MODULES - FILES modules/boost_type_index.cppm + TYPE CXX_MODULES + FILES modules/boost_type_index.cppm ) # Require C++20 for modules @@ -59,6 +60,9 @@ else() # Modules disabled -> INTERFACE library add_library(boost_type_index INTERFACE) + # If modules are disabled, require C++17 for headers + target_compile_features(boost_type_index INTERFACE cxx_std_17) + # Verify interface headers only at top level if(PROJECT_IS_TOP_LEVEL) set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ON) @@ -71,37 +75,32 @@ endif() # ----------------------------------------------------------------------------- # Include headers # ----------------------------------------------------------------------------- -if(CMAKE_VERSION VERSION_LESS 3.23) - target_include_directories(boost_type_index ${__scope} include) -else() +if(BOOST_USE_MODULES) target_sources( boost_type_index - ${__scope} - FILE_SET headers_public - TYPE HEADERS - BASE_DIRS include - FILES - include/boost/type_index.hpp - include/boost/type_index/runtime_cast.hpp - include/boost/type_index/stl_type_index.hpp - include/boost/type_index/detail/compile_time_type_info.hpp - include/boost/type_index/detail/stl_register_class.hpp - include/boost/type_index/detail/config.hpp - include/boost/type_index/detail/ctti_register_class.hpp - include/boost/type_index/ctti_type_index.hpp - include/boost/type_index/runtime_cast/std_shared_ptr_cast.hpp - include/boost/type_index/runtime_cast/detail/runtime_cast_impl.hpp - include/boost/type_index/runtime_cast/register_runtime_class.hpp - include/boost/type_index/runtime_cast/pointer_cast.hpp - include/boost/type_index/runtime_cast/reference_cast.hpp - include/boost/type_index/runtime_cast/boost_shared_ptr_cast.hpp - include/boost/type_index/type_index_facade.hpp + PUBLIC + FILE_SET headers_public + TYPE HEADERS + BASE_DIRS include + FILES + include/boost/type_index.hpp + include/boost/type_index/runtime_cast.hpp + include/boost/type_index/stl_type_index.hpp + include/boost/type_index/detail/compile_time_type_info.hpp + include/boost/type_index/detail/stl_register_class.hpp + include/boost/type_index/detail/config.hpp + include/boost/type_index/detail/ctti_register_class.hpp + include/boost/type_index/ctti_type_index.hpp + include/boost/type_index/runtime_cast/std_shared_ptr_cast.hpp + include/boost/type_index/runtime_cast/detail/runtime_cast_impl.hpp + include/boost/type_index/runtime_cast/register_runtime_class.hpp + include/boost/type_index/runtime_cast/pointer_cast.hpp + include/boost/type_index/runtime_cast/reference_cast.hpp + include/boost/type_index/runtime_cast/boost_shared_ptr_cast.hpp + include/boost/type_index/type_index_facade.hpp ) - - # If modules are disabled, require C++17 for headers - if(NOT BOOST_USE_MODULES) - target_compile_features(boost_type_index ${__scope} cxx_std_17) - endif() +else() + target_include_directories(boost_type_index ${__scope} include) endif() # ----------------------------------------------------------------------------- From 448096821d6d9b8206a110911f759128558cc51b Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 12 Feb 2026 22:06:22 +0100 Subject: [PATCH 3/4] Fix yamllint issue --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f228ef2..c6bbdb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -248,8 +248,8 @@ jobs: needs: posix runs-on: ubuntu-latest steps: - - name: Coveralls Finished - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.github_token }} - parallel-finished: true + - name: Coveralls Finished + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + parallel-finished: true From 1568a4bc5bfb39e68b70f4a0055d8151776ade00 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 15 Feb 2026 20:58:50 +0100 Subject: [PATCH 4/4] Fix typo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e9b901d..22e9831 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ if(BOOST_USE_MODULES) # Check if import std; is available for the current standard if(${CMAKE_CXX_STANDARD} IN_LIST CMAKE_CXX_COMPILER_IMPORT_STD) target_compile_definitions(boost_type_index PUBLIC BOOST_TYPE_INDEX_USE_STD_MODULE) - set_propery(TARGET boost_type_index CXX_MODULE_STD ON) + set_property(TARGET boost_type_index CXX_MODULE_STD ON) message(STATUS "Boost.type_index: Using `import std;`") else() message(WARNING "Boost.type_index: `import std;` is not available for C++${CMAKE_CXX_STANDARD}")