From c27d7d7596e32a59b78f077608321c05b49f0b82 Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Sun, 21 Jun 2026 08:26:35 +1000 Subject: [PATCH] cmake: Also build the test programs in BUILD_TESTING=Y mode --- CMakeLists.txt | 13 ++++++++++++- test/CMakeLists.txt | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 270b1d3a..7f221e0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,17 @@ target_compile_features(boost_format INTERFACE cxx_std_11) if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") - add_subdirectory(test) + if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + + message(STATUS "Using CMake version ${CMAKE_VERSION}") + + set(Boost_DEBUG ON) + find_package(Boost 1.85 CONFIG REQUIRED COMPONENTS assert config core optional smart_ptr throw_exception utility) + + endif() + + # Follow the Boost convention: don't build test targets by default, + # and only when explicitly requested by building target tests + add_subdirectory(test EXCLUDE_FROM_ALL) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..469a311c --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.8...3.20) + +add_executable(format_test1 format_test1.cpp) +target_link_libraries(format_test1 Boost::format) + +add_executable(format_test2 format_test2.cpp) +target_link_libraries(format_test2 Boost::format) + +add_executable(format_test3 format_test3.cpp) +target_link_libraries(format_test3 Boost::format) + +add_executable(format_test_enum format_test_enum.cpp) +target_link_libraries(format_test_enum Boost::format) + +add_executable(format_test_exceptions format_test_exceptions.cpp) +target_link_libraries(format_test_exceptions Boost::format) + +add_executable(format_test_wstring format_test_wstring.cpp) +target_link_libraries(format_test_wstring Boost::format)