From 80bb20eb93176704504354168b4335889dd803cb Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Sun, 26 Apr 2026 14:03:18 -0400 Subject: [PATCH 1/2] unified cmake test --- test/cmake_install_test/CMakeLists.txt | 17 --- test/cmake_subdir_test/CMakeLists.txt | 44 ------ test/cmake_subdir_test/main.cpp | 126 ------------------ test/cmake_test/CMakeLists.txt | 83 ++++++++++++ .../main.cpp | 0 5 files changed, 83 insertions(+), 187 deletions(-) delete mode 100644 test/cmake_install_test/CMakeLists.txt delete mode 100644 test/cmake_subdir_test/CMakeLists.txt delete mode 100644 test/cmake_subdir_test/main.cpp create mode 100644 test/cmake_test/CMakeLists.txt rename test/{cmake_install_test => cmake_test}/main.cpp (100%) diff --git a/test/cmake_install_test/CMakeLists.txt b/test/cmake_install_test/CMakeLists.txt deleted file mode 100644 index eb0df159..00000000 --- a/test/cmake_install_test/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2018, 2019, 2021 Peter Dimov -# 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...3.20) - -project(cmake_install_test LANGUAGES CXX) - -find_package(boost_openmethod REQUIRED) - -add_executable(main main.cpp) -target_link_libraries(main Boost::openmethod) - -enable_testing() -add_test(main main) - -add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) diff --git a/test/cmake_subdir_test/CMakeLists.txt b/test/cmake_subdir_test/CMakeLists.txt deleted file mode 100644 index f5fb5711..00000000 --- a/test/cmake_subdir_test/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright 2018, 2019, 2021 Peter Dimov -# 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...3.20) - -project(cmake_subdir_test LANGUAGES CXX) - -add_subdirectory(../.. boostorg/openmethod) - -# boostdep --brief openmethod - -set(deps - -# Primary dependencies - -assert -config -core -dynamic_bitset -mp11 -preprocessor - -# Secondary dependencies - -static_assert -throw_exception -container_hash -describe -) - -foreach(dep IN LISTS deps) - - add_subdirectory(../../../${dep} boostorg/${dep}) - -endforeach() - -add_executable(main main.cpp) -target_link_libraries(main Boost::openmethod) - -enable_testing() -add_test(NAME main COMMAND main) - -add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) diff --git a/test/cmake_subdir_test/main.cpp b/test/cmake_subdir_test/main.cpp deleted file mode 100644 index 74894f59..00000000 --- a/test/cmake_subdir_test/main.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (c) 2018-2025 Jean-Louis Leroy -// 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) - -#include -#include -#include - -#include -#include - -using boost::openmethod::virtual_ptr; - -struct Character { - virtual ~Character() { - } -}; - -struct Warrior : Character {}; - -struct Device { - virtual ~Device() { - } -}; - -struct Hands : Device {}; -struct Axe : Device {}; -struct Banana : Device {}; - -struct Creature { - virtual ~Creature() { - } -}; - -struct Dragon : Creature {}; -struct Bear : Creature {}; - -BOOST_OPENMETHOD_CLASSES( - Character, Warrior, Device, Hands, Axe, Banana, Creature, Dragon, Bear); - -BOOST_OPENMETHOD( - fight, (virtual_ptr, virtual_ptr, virtual_ptr), - std::string); - -BOOST_OPENMETHOD_OVERRIDE( - fight, (virtual_ptr, virtual_ptr, virtual_ptr), - std::string) { - return "are you insane?"; -} - -BOOST_OPENMETHOD_OVERRIDE( - fight, (virtual_ptr, virtual_ptr, virtual_ptr), - std::string) { - return "not agile enough to wield"; -} - -BOOST_OPENMETHOD_OVERRIDE( - fight, (virtual_ptr, virtual_ptr, virtual_ptr), - std::string) { - return "and cuts it into pieces"; -} - -BOOST_OPENMETHOD_OVERRIDE( - fight, (virtual_ptr, virtual_ptr, virtual_ptr), - std::string) { - return "and dies a honorable death"; -} - -BOOST_OPENMETHOD_OVERRIDE( - fight, (virtual_ptr, virtual_ptr, virtual_ptr), - std::string) { - return "Congratulations! You have just vainquished a dragon with your bare " - "hands" - " (unbelievable, isn't it?)"; -} - -auto main() -> int { - boost::openmethod::initialize(); - - std::unique_ptr bob = std::make_unique(), - rambo = std::make_unique(); - - std::unique_ptr elliott = std::make_unique(), - paddington = std::make_unique(); - - std::unique_ptr hands = std::make_unique(), - axe = std::make_unique(), - chiquita = std::make_unique(); - - std::cout << "bob fights elliot with axe:\n" - << fight(*bob, *elliott, *axe) << "\n"; - // bob fights elliot with axe: - // not agile enough to wield - - std::cout << "rambo fights paddington with axe:\n" - << fight(*rambo, *paddington, *axe) << "\n"; - // rambo fights paddington with axe: - // and cuts it into pieces - - std::cout << "rambo fights paddington with banana:\n" - << fight(*rambo, *paddington, *chiquita) << "\n"; - // rambo fights paddington with banana: - // are you insane? - - std::cout << "rambo fights elliott with axe:\n" - << fight(*rambo, *elliott, *axe) << "\n"; - // rambo fights elliott with axe: - // and dies a honorable death - - std::cout << "bob fights elliot with hands:\n" - << fight(*bob, *elliott, *hands) << "\n"; - // bob fights elliot with hands: Congratulations! You have just vainquished - // a dragon with your bare hands (unbelievable, isn't it?) - - std::cout << "rambo fights elliot with hands:\n" - << fight(*rambo, *elliott, *hands) << "\n"; - // rambo fights elliot with hands: - // you just killed a dragon with your bare hands. Incredible isn't it? - - return 0; -} - -auto call_fight(Character& character, Creature& creature, Device& device) { - return fight(character, creature, device); -} diff --git a/test/cmake_test/CMakeLists.txt b/test/cmake_test/CMakeLists.txt new file mode 100644 index 00000000..0956492f --- /dev/null +++ b/test/cmake_test/CMakeLists.txt @@ -0,0 +1,83 @@ +# +# Copyright (c) 2022 alandefreitas (alandefreitas@gmail.com) +# +# Distributed under the Boost Software License, Version 1.0. +# https://www.boost.org/LICENSE_1_0.txt +# + +cmake_minimum_required(VERSION 3.8...3.20) + +project(cmake_test LANGUAGES CXX) +set(__ignore__ ${CMAKE_C_COMPILER}) +set(__ignore__ ${CMAKE_C_FLAGS}) + +if(BOOST_CI_INSTALL_TEST) + # Boost as a package (https://github.com/boostorg/cmake#using-boost-after-building-and-installing-it-with-cmake) + find_package(Boost CONFIG REQUIRED COMPONENTS openmethod) +elseif(BOOST_CI_INSTALL_MODULE_TEST) + # Boost.OpenMethod as a package + find_package(boost_openmethod CONFIG REQUIRED) +elseif(BOOST_CI_BOOST_SUBDIR_TEST) + # Boost as a subdirectory (https://github.com/boostorg/cmake#using-boost-after-building-and-installing-it-with-cmake) + if (BUILD_SHARED_LIBS) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) + endif() + set(BOOST_OPENMETHOD_BUILD_TESTS OFF CACHE BOOL "Build the tests." FORCE) + set(PREV_BUILD_TESTING ${BUILD_TESTING}) + set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE) + set(BOOST_INCLUDE_LIBRARIES openmethod) + add_subdirectory(../../../.. boost) + set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE) +else() + # Boost.OpenMethod as a subdirectory (https://github.com/boostorg/cmake#using-an-individual-boost-library-with-add_subdirectory) + if (BUILD_SHARED_LIBS) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) + endif() + set(BOOST_OPENMETHOD_BUILD_TESTS OFF CACHE BOOL "Build the tests." FORCE) + set(BOOST_OPENMETHOD_BUILD_FUZZERS OFF CACHE BOOL "Build the fuzzers." FORCE) + set(BOOST_OPENMETHOD_BUILD_EXAMPLES OFF CACHE BOOL "Build the examples." FORCE) + set(PREV_BUILD_TESTING ${BUILD_TESTING}) + set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE) + file(GLOB subdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_SOURCE_DIR}/../../../*) + foreach(subdir ${subdirs}) + # This is testing the case when the super-project is not available + # and users want to add libraries as subdirectories. + # According to the convention above, users should scan all dependencies + # with boostdep and include each of them with add_subdirectory. + # For developers, hard-coding all dependencies is impractical + # and error-prone because the list of transitive dependencies + # is unstable over time and across Boost versions and branches. + # For this reason, we list all directories in ../.. and add them + # as subdirectories. Only directories previously cloned + # with `depinst.py` in CI will be added. This will unfortunately + # add test dependencies we don't need. + if ( + IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../../${subdir} AND + EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../../${subdir}/CMakeLists.txt + ) + add_subdirectory(../../../${subdir} boostorg/${subdir}) + endif() + endforeach() + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../../numeric AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../../numeric) + # Iterate potential transitive dependencies in libs/numeric + file(GLOB subdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/../../../numeric ${CMAKE_CURRENT_SOURCE_DIR}/../../../numeric/*) + foreach(subdir ${subdirs}) + if ( + IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../../numeric/${subdir} AND + EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../../numeric/${subdir}/CMakeLists.txt + ) + add_subdirectory(../../../numeric/${subdir} boostorg/numeric/${subdir}) + endif() + endforeach() + endif() + set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE) +endif() + +add_executable(main main.cpp) +target_link_libraries(main Boost::openmethod) + +if (BUILD_TESTING) + enable_testing() + add_test(NAME main COMMAND main) + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) +endif() diff --git a/test/cmake_install_test/main.cpp b/test/cmake_test/main.cpp similarity index 100% rename from test/cmake_install_test/main.cpp rename to test/cmake_test/main.cpp From 99aa19463ea8d4361bd45f7e328a17985bc6e016 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leroy Date: Sun, 26 Apr 2026 18:43:53 -0400 Subject: [PATCH 2/2] Update test/cmake_test/CMakeLists.txt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- test/cmake_test/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test/cmake_test/CMakeLists.txt b/test/cmake_test/CMakeLists.txt index 0956492f..2e878c4c 100644 --- a/test/cmake_test/CMakeLists.txt +++ b/test/cmake_test/CMakeLists.txt @@ -34,7 +34,6 @@ else() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) endif() set(BOOST_OPENMETHOD_BUILD_TESTS OFF CACHE BOOL "Build the tests." FORCE) - set(BOOST_OPENMETHOD_BUILD_FUZZERS OFF CACHE BOOL "Build the fuzzers." FORCE) set(BOOST_OPENMETHOD_BUILD_EXAMPLES OFF CACHE BOOL "Build the examples." FORCE) set(PREV_BUILD_TESTING ${BUILD_TESTING}) set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE)