From 1d62158cf9e75d4211ea1441f9af397f2f089c4e Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 24 Jun 2026 12:31:33 +0200 Subject: [PATCH 1/5] Make import std; usable Add FILE_SET HEADERS too support generic installation Prevent use of FILE_SET w/o modules Fix yamllint issues Fix typos Always use FILE_SET HEADERS if possible --- .github/workflows/ci.yml | 10 +- .gitignore | 2 + CMakeLists.txt | 128 +++++++++++++++++++++----- modules/boost_type_index.cppm | 14 +-- test/cmake_subdir_test/CMakeLists.txt | 42 ++++++--- 5 files changed, 147 insertions(+), 49 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4baac31..efc7f6f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -259,8 +259,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 diff --git a/.gitignore b/.gitignore index dbcd323..2a06130 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ doc/html build* .cache .vscode +compile_commands.json +GNUmakefile diff --git a/CMakeLists.txt b/CMakeLists.txt index 2275d3b..0d6c154 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,47 +1,129 @@ -# Generated by `boostdep --cmake type_index` +# ----------------------------------------------------------------------------- +# Boost.type_index CMake +# Handles: no modules, modules, modules + import std; +# ----------------------------------------------------------------------------- # Copyright 2020, 2021 Peter Dimov # Copyright 2026 Fedor Osetrov # Distributed under the Boost Software License, Version 1.0. # https://www.boost.org/LICENSE_1_0.txt -cmake_minimum_required(VERSION 3.5...4.20) +cmake_minimum_required(VERSION 3.28...4.4) project(boost_type_index VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) -if (BOOST_USE_MODULES) +if(PROJECT_IS_TOP_LEVEL) + find_package(Boost 1.91.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 CXX_MODULES - BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" - FILES "${CMAKE_CURRENT_SOURCE_DIR}/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_STANDARD IN_LIST CMAKE_CXX_COMPILER_IMPORT_STD) AND CMAKE_CXX_MODULE_STD) - target_compile_features(boost_type_index PRIVATE cxx_std_23) - 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_property(TARGET boost_type_index PROPERTY CXX_MODULE_STD ON) + message(STATUS "Boost.type_index: Using `import std;`") else() - message(STATUS "`import std;` is not available") + 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) + + # 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) + endif() + set(__scope INTERFACE) + endif() -target_include_directories(boost_type_index ${__scope} include) -add_library(Boost::type_index ALIAS boost_type_index) +# ----------------------------------------------------------------------------- +# Include headers +# ----------------------------------------------------------------------------- +# Note: usable starting with cmake v3.23 +if(NOT CMAKE_VERSION VERSION_LESS 3.23) + target_sources( + boost_type_index + 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 + ) +else() + target_include_directories(boost_type_index ${__scope} include) +endif() + +# ----------------------------------------------------------------------------- +# Link dependencies +# ----------------------------------------------------------------------------- +if(PROJECT_IS_TOP_LEVEL) + target_link_libraries(boost_type_index ${__scope} Boost::headers) +else() + target_link_libraries(boost_type_index + ${__scope} + Boost::config + Boost::container_hash + Boost::throw_exception + ) +endif() -target_link_libraries(boost_type_index - ${__scope} - Boost::config - Boost::container_hash - Boost::throw_exception -) +# 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 c40a43a..dab6693 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 @@ -40,12 +42,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 e10cdb4..c3e841c 100644 --- a/test/cmake_subdir_test/CMakeLists.txt +++ b/test/cmake_subdir_test/CMakeLists.txt @@ -2,28 +2,31 @@ # 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.28...4.4) + +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "451f2fe2-a8a2-47c3-bc32-94786d8fc91b") project(type_index_subdir_test LANGUAGES CXX) foreach(dep IN ITEMS - assert - config - core - container_hash - describe - mp11 - smart_ptr - throw_exception - unordered - predef) + assert + config + core + container_hash + describe + mp11 + smart_ptr + throw_exception + unordered + predef +) add_subdirectory(../../../${dep} boostorg/${dep}) endforeach() enable_testing() add_subdirectory(../../ boostorg/type_index) -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,4 +35,19 @@ 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() + +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}) +endforeach() From 32553f5e7641af9baca12e0048483e2c8be953ec Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 24 Jun 2026 13:27:49 +0200 Subject: [PATCH 2/5] import std; Should not be in the global module fragment --- modules/boost_type_index.cppm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/boost_type_index.cppm b/modules/boost_type_index.cppm index dab6693..e16f081 100644 --- a/modules/boost_type_index.cppm +++ b/modules/boost_type_index.cppm @@ -19,9 +19,7 @@ module; #include #include -#ifdef BOOST_TYPE_INDEX_USE_STD_MODULE -import std; -#else +#ifndef BOOST_TYPE_INDEX_USE_STD_MODULE #include #include #include @@ -42,6 +40,12 @@ import std; 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 From d89eeb8d3635b51bf7451c61dcb77edd0ff59890 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 24 Jun 2026 14:29:32 +0200 Subject: [PATCH 3/5] Fix standalone build and tests --- CMakeLists.txt | 18 ++++++++++++------ test/CMakeLists.txt | 11 ++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d6c154..6bdabf0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,10 @@ cmake_minimum_required(VERSION 3.28...4.4) project(boost_type_index VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) if(PROJECT_IS_TOP_LEVEL) - find_package(Boost 1.91.0 CONFIG) + set(BUILD_TESTING ON) + enable_testing() + find_package(Threads) + find_package(Boost 1.91.0 CONFIG REQUIRED) endif() # ----------------------------------------------------------------------------- @@ -57,17 +60,17 @@ if(BOOST_USE_MODULES) else() + # Verify interface headers only at top level + if(PROJECT_IS_TOP_LEVEL) + set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ON) + endif() + # 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) - endif() - set(__scope INTERFACE) endif() @@ -114,7 +117,10 @@ else() ${__scope} Boost::config Boost::container_hash + Boost::core + Boost::smart_ptr Boost::throw_exception + Boost::unordered ) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 29cde66..eeea37c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -25,7 +25,7 @@ target_link_libraries(boost_type_index_test_lib_anonymous_rtti PRIVATE Boost::ty function(boost_type_index_test name sources) add_executable(${name} "${sources}") - target_link_libraries(${name} PRIVATE Boost::core ${ARGN}) + target_link_libraries(${name} PRIVATE Boost::type_index ${ARGN}) add_test(NAME ${name} COMMAND ${name}) add_dependencies(tests ${name}) endfunction() @@ -49,16 +49,13 @@ function(boost_type_index_add_target target) target_include_directories(${target} ${__scope} ../include) target_link_libraries(${target} ${__scope} - Boost::config - Boost::container_hash - Boost::throw_exception ) endfunction() boost_type_index_test(type_index_test type_index_test.cpp Boost::type_index) boost_type_index_test(type_index_constexpr_test type_index_constexpr_test.cpp Boost::type_index) boost_type_index_test(type_index_ctti_print_name_test ctti_print_name.cpp Boost::type_index) -boost_type_index_test(type_index_runtime_cast_test type_index_runtime_cast_test.cpp Boost::type_index Boost::smart_ptr) +boost_type_index_test(type_index_runtime_cast_test type_index_runtime_cast_test.cpp Boost::type_index) boost_type_index_test(type_index_crossmodule_test testing_crossmodule.cpp Boost::type_index boost_type_index_test_lib_rtti) boost_type_index_test(type_index_crossmodule_anonymous_test testing_crossmodule_anonymous.cpp Boost::type_index boost_type_index_test_lib_anonymous_rtti) @@ -78,7 +75,7 @@ foreach (testsourcefile ${EXAMPLE_FILES}) continue() endif() - boost_type_index_test(type_index_${testname}_example ${testsourcefile} Boost::type_index Boost::unordered) + boost_type_index_test(type_index_${testname}_example ${testsourcefile} Boost::type_index) target_include_directories(type_index_${testname}_example PRIVATE ../examples) if (_use_import_std) @@ -89,7 +86,7 @@ foreach (testsourcefile ${EXAMPLE_FILES}) continue() endif() - boost_type_index_test(type_index_${testname}_no_rtti_example ${testsourcefile} Boost::type_index_no_rtti Boost::unordered) + boost_type_index_test(type_index_${testname}_no_rtti_example ${testsourcefile} Boost::type_index_no_rtti) target_include_directories(type_index_${testname}_no_rtti_example PRIVATE ../examples) endforeach() From 9209d16be96e4ffd9095671bc47093195bd72b84 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 24 Jun 2026 15:19:29 +0200 Subject: [PATCH 4/5] Fix link problems of cmake_subdir_test --- test/cmake_subdir_test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cmake_subdir_test/CMakeLists.txt b/test/cmake_subdir_test/CMakeLists.txt index c3e841c..363347e 100644 --- a/test/cmake_subdir_test/CMakeLists.txt +++ b/test/cmake_subdir_test/CMakeLists.txt @@ -48,6 +48,6 @@ endif() 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) + target_link_libraries(${PROJECT_NAME}_${testname} Boost::type_index) add_test(NAME ${PROJECT_NAME}_${testname} COMMAND ${PROJECT_NAME}_${testname}) endforeach() From 7257548f905902541a861717659d00f8c7d75138 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Mon, 6 Jul 2026 15:12:50 +0200 Subject: [PATCH 5/5] Quickfix for CI tests Use FILE_SET HEADERS only if BOOST_USE_MODULES is set --- CMakeLists.txt | 15 +-- test/CMakeLists.txt | 174 ++++++++++++++------------ test/cmake_subdir_test/CMakeLists.txt | 24 ++-- 3 files changed, 110 insertions(+), 103 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bdabf0..d94e700 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,20 +27,13 @@ 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) # Require C++20 for modules target_compile_features(boost_type_index PUBLIC cxx_std_${CMAKE_CXX_STANDARD}) @@ -72,14 +65,13 @@ else() target_compile_features(boost_type_index INTERFACE cxx_std_17) set(__scope INTERFACE) - endif() # ----------------------------------------------------------------------------- # Include headers # ----------------------------------------------------------------------------- # Note: usable starting with cmake v3.23 -if(NOT CMAKE_VERSION VERSION_LESS 3.23) +if(NOT CMAKE_VERSION VERSION_LESS 3.23 AND BOOST_USE_MODULES) target_sources( boost_type_index PUBLIC @@ -113,7 +105,8 @@ endif() if(PROJECT_IS_TOP_LEVEL) target_link_libraries(boost_type_index ${__scope} Boost::headers) else() - target_link_libraries(boost_type_index + target_link_libraries( + boost_type_index ${__scope} Boost::config Boost::container_hash diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eeea37c..0d8e0b4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,7 +4,7 @@ # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt if(NOT TARGET tests) - add_custom_target(tests) + add_custom_target(tests) endif() if(MSVC) @@ -31,25 +31,28 @@ function(boost_type_index_test name sources) endfunction() function(boost_type_index_add_target target) - if(BOOST_USE_MODULES) - # C++ modules with different compile flags and definitions must be built separately - add_library(${target}) - target_sources(${target} - PUBLIC - FILE_SET CXX_MODULES - BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../" - FILES "${CMAKE_CURRENT_SOURCE_DIR}/../modules/boost_type_index.cppm" - ) - target_compile_features(${target} PUBLIC cxx_std_20) - else() - add_library(${target} INTERFACE) - target_link_libraries(${target} INTERFACE Boost::type_index) - endif() - - target_include_directories(${target} ${__scope} ../include) - target_link_libraries(${target} - ${__scope} - ) + if(BOOST_USE_MODULES) + # C++ modules with different compile flags and definitions must be built separately + add_library(${target}) + target_sources( + ${target} + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../" + FILES "${CMAKE_CURRENT_SOURCE_DIR}/../modules/boost_type_index.cppm" + ) + target_compile_features(${target} PUBLIC cxx_std_20) + else() + add_library(${target} INTERFACE) + target_link_libraries(${target} INTERFACE Boost::type_index) + endif() + + target_include_directories(${target} ${__scope} ../include) + if(PROJECT_IS_TOP_LEVEL AND TARGET Boost::headers) + target_link_libraries(${target} ${__scope} Boost::headers) + else() + target_link_libraries(${target} ${__scope} Boost::config Boost::container_hash Boost::throw_exception) + endif() endfunction() boost_type_index_test(type_index_test type_index_test.cpp Boost::type_index) @@ -67,23 +70,29 @@ boost_type_index_test(type_index_ctti_alignment_test type_index_test_ctti_alignm get_target_property(_use_import_std boost_type_index CXX_MODULE_STD) +######################################### +if(PROJECT_IS_TOP_LEVEL AND TARGET Boost::headers) + return() +endif() +######################################### + file(GLOB EXAMPLE_FILES "../examples/*.cpp") -foreach (testsourcefile ${EXAMPLE_FILES}) +foreach(testsourcefile ${EXAMPLE_FILES}) get_filename_component(testname ${testsourcefile} NAME_WE) if(testname STREQUAL "user_defined_typeinfo") - continue() + continue() endif() boost_type_index_test(type_index_${testname}_example ${testsourcefile} Boost::type_index) target_include_directories(type_index_${testname}_example PRIVATE ../examples) - if (_use_import_std) - continue() + if(_use_import_std) + continue() endif() if(testname STREQUAL "table_of_names") - continue() + continue() endif() boost_type_index_test(type_index_${testname}_no_rtti_example ${testsourcefile} Boost::type_index_no_rtti) @@ -92,69 +101,76 @@ endforeach() boost_type_index_add_target(boost_type_index_user_defined_typeinfo) if(BOOST_USE_MODULES) - target_compile_definitions(boost_type_index_user_defined_typeinfo PRIVATE "BOOST_TYPE_INDEX_USER_TYPEINDEX=<../examples/user_defined_typeinfo.hpp>") + target_compile_definitions( + boost_type_index_user_defined_typeinfo + PRIVATE "BOOST_TYPE_INDEX_USER_TYPEINDEX=<../examples/user_defined_typeinfo.hpp>" + ) endif() boost_type_index_test(type_index_user_defined_typeinfo_example ../examples/user_defined_typeinfo.cpp boost_type_index_user_defined_typeinfo) target_include_directories(type_index_user_defined_typeinfo_example PRIVATE ../examples) # CMake currently does not support standard stl module with different compile flags -if (NOT _use_import_std) - -boost_type_index_add_target(boost_type_index_user_defined_typeinfo_no_rtti) -if(BOOST_USE_MODULES) - target_compile_definitions(boost_type_index_user_defined_typeinfo_no_rtti PRIVATE "BOOST_TYPE_INDEX_USER_TYPEINDEX=<../examples/user_defined_typeinfo.hpp>") -endif() -target_compile_options(boost_type_index_user_defined_typeinfo_no_rtti ${__scope} ${BOOST_TYPEINDEX_DETAIL_NO_RTTI}) - -boost_type_index_test(type_index_user_defined_typeinfo_no_rtti_example ../examples/user_defined_typeinfo.cpp boost_type_index_user_defined_typeinfo_no_rtti) -target_include_directories(type_index_user_defined_typeinfo_no_rtti_example PRIVATE ../examples) - -foreach(target IN ITEMS - boost_type_index_no_rtti - boost_type_index_rtti_no_compat - boost_type_index_no_rtti_no_compat -) - boost_type_index_add_target(${target}) -endforeach() - -target_compile_options(boost_type_index_no_rtti ${__scope} ${BOOST_TYPEINDEX_DETAIL_NO_RTTI}) -target_compile_options(boost_type_index_no_rtti_no_compat ${__scope} ${BOOST_TYPEINDEX_DETAIL_NO_RTTI}) -target_compile_definitions(boost_type_index_rtti_no_compat ${__scope} BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY=1) -target_compile_definitions(boost_type_index_no_rtti_no_compat ${__scope} BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY=1) - -add_library(Boost::type_index_no_rtti ALIAS boost_type_index_no_rtti) -add_library(Boost::type_index_rtti_no_compat ALIAS boost_type_index_rtti_no_compat) -add_library(Boost::type_index_no_rtti_no_compat ALIAS boost_type_index_no_rtti_no_compat) - -# Making libraries that CANNOT work between rtti-on/rtti-off modules -add_library(boost_type_index_test_lib_nortti SHARED test_lib.cpp) -target_compile_options(boost_type_index_test_lib_nortti PRIVATE ${BOOST_TYPEINDEX_DETAIL_NO_RTTI}) -target_link_libraries(boost_type_index_test_lib_nortti PRIVATE Boost::type_index_no_rtti) - -add_library(boost_type_index_test_lib_anonymous_nortti SHARED test_lib_anonymous.cpp) -target_compile_options(boost_type_index_test_lib_anonymous_nortti PRIVATE ${BOOST_TYPEINDEX_DETAIL_NO_RTTI}) -target_link_libraries(boost_type_index_test_lib_anonymous_nortti PRIVATE Boost::type_index_no_rtti) - -# Making libraries that can work between rtti-on/rtti-off modules -add_library(boost_type_index_test_lib_nortti_compat SHARED test_lib.cpp) -target_compile_options(boost_type_index_test_lib_nortti_compat PRIVATE ${BOOST_TYPEINDEX_DETAIL_NO_RTTI}) -target_compile_definitions(boost_type_index_test_lib_nortti_compat PUBLIC BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY=1) -target_link_libraries(boost_type_index_test_lib_nortti_compat PUBLIC Boost::type_index_no_rtti_no_compat) +if(NOT _use_import_std) + boost_type_index_add_target(boost_type_index_user_defined_typeinfo_no_rtti) + if(BOOST_USE_MODULES) + target_compile_definitions( + boost_type_index_user_defined_typeinfo_no_rtti + PRIVATE "BOOST_TYPE_INDEX_USER_TYPEINDEX=<../examples/user_defined_typeinfo.hpp>" + ) + endif() + target_compile_options(boost_type_index_user_defined_typeinfo_no_rtti ${__scope} ${BOOST_TYPEINDEX_DETAIL_NO_RTTI}) + + boost_type_index_test(type_index_user_defined_typeinfo_no_rtti_example ../examples/user_defined_typeinfo.cpp boost_type_index_user_defined_typeinfo_no_rtti) + target_include_directories(type_index_user_defined_typeinfo_no_rtti_example PRIVATE ../examples) + + foreach(target IN ITEMS boost_type_index_no_rtti boost_type_index_rtti_no_compat boost_type_index_no_rtti_no_compat) + boost_type_index_add_target(${target}) + endforeach() + + target_compile_options(boost_type_index_no_rtti ${__scope} ${BOOST_TYPEINDEX_DETAIL_NO_RTTI}) + target_compile_options(boost_type_index_no_rtti_no_compat ${__scope} ${BOOST_TYPEINDEX_DETAIL_NO_RTTI}) + target_compile_definitions(boost_type_index_rtti_no_compat ${__scope} BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY=1) + target_compile_definitions( + boost_type_index_no_rtti_no_compat + ${__scope} + BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY=1 + ) -add_library(boost_type_index_test_lib_rtti_compat SHARED test_lib.cpp) -target_compile_options(boost_type_index_test_lib_rtti_compat PRIVATE ${BOOST_TYPEINDEX_DETAIL_RTTI}) -target_compile_definitions(boost_type_index_test_lib_rtti_compat PUBLIC BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY=1) -target_link_libraries(boost_type_index_test_lib_rtti_compat PUBLIC Boost::type_index_rtti_no_compat) + add_library(Boost::type_index_no_rtti ALIAS boost_type_index_no_rtti) + add_library(Boost::type_index_rtti_no_compat ALIAS boost_type_index_rtti_no_compat) + add_library(Boost::type_index_no_rtti_no_compat ALIAS boost_type_index_no_rtti_no_compat) + + # Making libraries that CANNOT work between rtti-on/rtti-off modules + add_library(boost_type_index_test_lib_nortti SHARED test_lib.cpp) + target_compile_options(boost_type_index_test_lib_nortti PRIVATE ${BOOST_TYPEINDEX_DETAIL_NO_RTTI}) + target_link_libraries(boost_type_index_test_lib_nortti PRIVATE Boost::type_index_no_rtti) + + add_library(boost_type_index_test_lib_anonymous_nortti SHARED test_lib_anonymous.cpp) + target_compile_options(boost_type_index_test_lib_anonymous_nortti PRIVATE ${BOOST_TYPEINDEX_DETAIL_NO_RTTI}) + target_link_libraries(boost_type_index_test_lib_anonymous_nortti PRIVATE Boost::type_index_no_rtti) + + # Making libraries that can work between rtti-on/rtti-off modules + add_library(boost_type_index_test_lib_nortti_compat SHARED test_lib.cpp) + target_compile_options(boost_type_index_test_lib_nortti_compat PRIVATE ${BOOST_TYPEINDEX_DETAIL_NO_RTTI}) + target_compile_definitions( + boost_type_index_test_lib_nortti_compat + PUBLIC BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY=1 + ) + target_link_libraries(boost_type_index_test_lib_nortti_compat PUBLIC Boost::type_index_no_rtti_no_compat) -boost_type_index_test(type_index_test_no_rtti type_index_test.cpp Boost::type_index_no_rtti) + add_library(boost_type_index_test_lib_rtti_compat SHARED test_lib.cpp) + target_compile_options(boost_type_index_test_lib_rtti_compat PRIVATE ${BOOST_TYPEINDEX_DETAIL_RTTI}) + target_compile_definitions(boost_type_index_test_lib_rtti_compat PUBLIC BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY=1) + target_link_libraries(boost_type_index_test_lib_rtti_compat PUBLIC Boost::type_index_rtti_no_compat) -boost_type_index_test(type_index_crossmodule_no_rtti_test testing_crossmodule.cpp Boost::type_index_no_rtti boost_type_index_test_lib_nortti) + boost_type_index_test(type_index_test_no_rtti type_index_test.cpp Boost::type_index_no_rtti) -# # Mixing RTTI on and off -if(NOT MSVC) # MSVC sometimes overrides the /GR- and the tests link - boost_type_index_test(type_index_crossmodule_no_rtti_rtti_compat_test testing_crossmodule.cpp boost_type_index_test_lib_rtti_compat) - boost_type_index_test(type_index_crossmodule_rtti_nortti_compat_test testing_crossmodule.cpp boost_type_index_test_lib_nortti_compat) -endif() + boost_type_index_test(type_index_crossmodule_no_rtti_test testing_crossmodule.cpp Boost::type_index_no_rtti boost_type_index_test_lib_nortti) + # Mixing RTTI on and off + if(NOT MSVC) # MSVC sometimes overrides the /GR- and the tests link + boost_type_index_test(type_index_crossmodule_no_rtti_rtti_compat_test testing_crossmodule.cpp boost_type_index_test_lib_rtti_compat) + boost_type_index_test(type_index_crossmodule_rtti_nortti_compat_test testing_crossmodule.cpp boost_type_index_test_lib_nortti_compat) + endif() endif() diff --git a/test/cmake_subdir_test/CMakeLists.txt b/test/cmake_subdir_test/CMakeLists.txt index 363347e..363a172 100644 --- a/test/cmake_subdir_test/CMakeLists.txt +++ b/test/cmake_subdir_test/CMakeLists.txt @@ -4,21 +4,18 @@ cmake_minimum_required(VERSION 3.28...4.4) -set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "451f2fe2-a8a2-47c3-bc32-94786d8fc91b") +if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.4.0") + set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "f35a9ac6-8463-4d38-8eec-5d6008153e7d") +else() + set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "451f2fe2-a8a2-47c3-bc32-94786d8fc91b") +endif() project(type_index_subdir_test LANGUAGES CXX) -foreach(dep IN ITEMS - assert - config - core - container_hash - describe - mp11 - smart_ptr - throw_exception - unordered - predef +foreach( + dep + IN + ITEMS assert config core container_hash describe mp11 smart_ptr throw_exception unordered predef ) add_subdirectory(../../../${dep} boostorg/${dep}) endforeach() @@ -36,7 +33,8 @@ if(BOOST_USE_MODULES) 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 + list( + APPEND RUN_TESTS_SOURCES compare_ctti_stl.cpp ctti_print_name.cpp track_13621.cpp