From 0886655247f3d9a0b9ad76a652684fd1aff4ff00 Mon Sep 17 00:00:00 2001 From: Steve Gerbino Date: Thu, 26 Feb 2026 11:42:55 +0100 Subject: [PATCH] Export and install test_suite for downstream use Make boost_capy_test_suite and boost_capy_test_suite_main available to downstream consumers via find_package(boost_capy). Add generator expressions for include dirs, EXPORT_NAME properties, Boost:: aliases, and install rules for targets, headers, and CMake modules. --- CMakeLists.txt | 13 +++++++++++-- cmake/boost_capy-config.cmake.in | 1 + extra/test_suite/CMakeLists.txt | 16 ++++++++++++++-- test/unit/CMakeLists.txt | 6 +----- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1cf7b2d..5a2058d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,13 +78,16 @@ set_target_properties(boost_capy PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO OFF INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL OFF) +include(GNUInstallDirs) + +add_subdirectory(extra/test_suite) + if(BOOST_SUPERPROJECT_VERSION AND NOT CMAKE_VERSION VERSION_LESS 3.13) boost_install( TARGETS boost_capy VERSION ${BOOST_SUPERPROJECT_VERSION} HEADER_DIRECTORY include) else() - include(GNUInstallDirs) include(CMakePackageConfigHelpers) # Set INSTALL_INTERFACE for standalone installs (boost_install handles @@ -95,13 +98,19 @@ else() set(BOOST_CAPY_INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/boost_capy) - install(TARGETS boost_capy + install(TARGETS boost_capy boost_capy_test_suite boost_capy_test_suite_main EXPORT boost_capy-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + install(FILES extra/test_suite/test_suite.hpp + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/boost/capy/extra/test_suite) + install(FILES + extra/test_suite/DiscoverTests.cmake + extra/test_suite/DiscoverAndWriteTestsScripts.cmake + DESTINATION ${BOOST_CAPY_INSTALL_CMAKEDIR}) install(EXPORT boost_capy-targets NAMESPACE Boost:: DESTINATION ${BOOST_CAPY_INSTALL_CMAKEDIR}) diff --git a/cmake/boost_capy-config.cmake.in b/cmake/boost_capy-config.cmake.in index 4d76299a..e095a4df 100644 --- a/cmake/boost_capy-config.cmake.in +++ b/cmake/boost_capy-config.cmake.in @@ -1,3 +1,4 @@ @PACKAGE_INIT@ include("${CMAKE_CURRENT_LIST_DIR}/boost_capy-targets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/DiscoverTests.cmake") check_required_components(boost_capy) diff --git a/extra/test_suite/CMakeLists.txt b/extra/test_suite/CMakeLists.txt index 0f3e25b5..748290f6 100644 --- a/extra/test_suite/CMakeLists.txt +++ b/extra/test_suite/CMakeLists.txt @@ -15,13 +15,25 @@ cmake_minimum_required(VERSION 3.8...3.20) # Library target with test_suite.cpp and test_suite.hpp add_library(boost_capy_test_suite STATIC test_suite.cpp test_suite.hpp) -target_include_directories(boost_capy_test_suite PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(boost_capy_test_suite PUBLIC + $ + $) target_compile_features(boost_capy_test_suite PUBLIC cxx_std_17) # Library target that links the previous and adds test_main.cpp add_library(boost_capy_test_suite_main STATIC test_main.cpp) target_link_libraries(boost_capy_test_suite_main PUBLIC boost_capy_test_suite) -target_include_directories(boost_capy_test_suite_main PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(boost_capy_test_suite_main PUBLIC + $ + $) target_compile_features(boost_capy_test_suite_main PUBLIC cxx_std_17) +set_target_properties(boost_capy_test_suite PROPERTIES + EXPORT_NAME capy_test_suite) +set_target_properties(boost_capy_test_suite_main PROPERTIES + EXPORT_NAME capy_test_suite_main) + +add_library(Boost::capy_test_suite ALIAS boost_capy_test_suite) +add_library(Boost::capy_test_suite_main ALIAS boost_capy_test_suite_main) + include(DiscoverTests.cmake) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 0d744adf..14774345 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -7,10 +7,6 @@ # Official repository: https://github.com/cppalliance/capy # -if(NOT TARGET boost_capy_test_suite) - add_subdirectory(../../extra/test_suite test_suite) -endif() - file(GLOB_RECURSE PFILES CONFIGURE_DEPENDS *.cpp *.hpp) list(APPEND PFILES CMakeLists.txt @@ -21,7 +17,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${PFILES}) add_executable(boost_capy_tests ${PFILES}) target_link_libraries( boost_capy_tests PRIVATE - boost_capy_test_suite_main + Boost::capy_test_suite_main Boost::capy) target_include_directories(boost_capy_tests PRIVATE . ../../)