|
| 1 | +cmake: Add `BOOST_TEST_HEADERS_ONLY` configuration variable |
| 2 | + |
| 3 | +This change allows the build to be configured to install only the |
| 4 | +Boost.Test headers required for using the headers-only variant of the |
| 5 | +Unit Test Framework. |
| 6 | + |
| 7 | +Upstream commit: 097e97820e654ead9c477b47443a545cef5d3b12 |
| 8 | + |
| 9 | + |
| 10 | +--- a/libs/test/CMakeLists.txt |
| 11 | ++++ b/libs/test/CMakeLists.txt |
| 12 | +@@ -30,60 +30,70 @@ set(_boost_test_dependencies |
| 13 | + Boost::utility |
| 14 | + ) |
| 15 | + |
| 16 | +-# Compiled targets |
| 17 | ++option(BOOST_TEST_HEADERS_ONLY "Boost.Test: Only install headers" OFF) |
| 18 | + |
| 19 | +-function(boost_test_add_library name) |
| 20 | ++set(_boost_test_libraries "") |
| 21 | + |
| 22 | +- add_library(boost_${name} ${ARGN}) |
| 23 | +- add_library(Boost::${name} ALIAS boost_${name}) |
| 24 | ++if (NOT BOOST_TEST_HEADERS_ONLY) |
| 25 | + |
| 26 | +- target_include_directories(boost_${name} PUBLIC include) |
| 27 | +- target_link_libraries(boost_${name} PUBLIC ${_boost_test_dependencies}) |
| 28 | ++ # Compiled targets |
| 29 | + |
| 30 | +- target_compile_definitions(boost_${name} |
| 31 | +- PUBLIC BOOST_TEST_NO_LIB |
| 32 | +- # Source files already define BOOST_TEST_SOURCE |
| 33 | +- # PRIVATE BOOST_TEST_SOURCE |
| 34 | +- ) |
| 35 | ++ function(boost_test_add_library name) |
| 36 | + |
| 37 | +- if(BUILD_SHARED_LIBS) |
| 38 | +- target_compile_definitions(boost_${name} PUBLIC BOOST_TEST_DYN_LINK) |
| 39 | +- else() |
| 40 | +- target_compile_definitions(boost_${name} PUBLIC BOOST_TEST_STATIC_LINK) |
| 41 | +- endif() |
| 42 | ++ add_library(boost_${name} ${ARGN}) |
| 43 | ++ add_library(Boost::${name} ALIAS boost_${name}) |
| 44 | + |
| 45 | +-endfunction() |
| 46 | ++ target_include_directories(boost_${name} PUBLIC include) |
| 47 | ++ target_link_libraries(boost_${name} PUBLIC ${_boost_test_dependencies}) |
| 48 | + |
| 49 | +-boost_test_add_library(prg_exec_monitor |
| 50 | +- src/cpp_main.cpp |
| 51 | +- src/debug.cpp |
| 52 | +- src/execution_monitor.cpp |
| 53 | +-) |
| 54 | ++ target_compile_definitions(boost_${name} |
| 55 | ++ PUBLIC BOOST_TEST_NO_LIB |
| 56 | ++ # Source files already define BOOST_TEST_SOURCE |
| 57 | ++ # PRIVATE BOOST_TEST_SOURCE |
| 58 | ++ ) |
| 59 | + |
| 60 | +-set(SOURCES |
| 61 | +- src/compiler_log_formatter.cpp |
| 62 | +- src/debug.cpp |
| 63 | +- src/decorator.cpp |
| 64 | +- src/execution_monitor.cpp |
| 65 | +- src/framework.cpp |
| 66 | +- src/junit_log_formatter.cpp |
| 67 | +- src/plain_report_formatter.cpp |
| 68 | +- src/progress_monitor.cpp |
| 69 | +- src/results_collector.cpp |
| 70 | +- src/results_reporter.cpp |
| 71 | +- src/test_framework_init_observer.cpp |
| 72 | +- src/test_tools.cpp |
| 73 | +- src/test_tree.cpp |
| 74 | +- src/unit_test_log.cpp |
| 75 | +- src/unit_test_main.cpp |
| 76 | +- src/unit_test_monitor.cpp |
| 77 | +- src/unit_test_parameters.cpp |
| 78 | +- src/xml_log_formatter.cpp |
| 79 | +- src/xml_report_formatter.cpp |
| 80 | +-) |
| 81 | ++ if(BUILD_SHARED_LIBS) |
| 82 | ++ target_compile_definitions(boost_${name} PUBLIC BOOST_TEST_DYN_LINK) |
| 83 | ++ else() |
| 84 | ++ target_compile_definitions(boost_${name} PUBLIC BOOST_TEST_STATIC_LINK) |
| 85 | ++ endif() |
| 86 | ++ |
| 87 | ++ endfunction() |
| 88 | + |
| 89 | +-boost_test_add_library(test_exec_monitor STATIC ${SOURCES} src/test_main.cpp) |
| 90 | +-boost_test_add_library(unit_test_framework ${SOURCES}) |
| 91 | ++ boost_test_add_library(prg_exec_monitor |
| 92 | ++ src/cpp_main.cpp |
| 93 | ++ src/debug.cpp |
| 94 | ++ src/execution_monitor.cpp |
| 95 | ++ ) |
| 96 | ++ |
| 97 | ++ set(SOURCES |
| 98 | ++ src/compiler_log_formatter.cpp |
| 99 | ++ src/debug.cpp |
| 100 | ++ src/decorator.cpp |
| 101 | ++ src/execution_monitor.cpp |
| 102 | ++ src/framework.cpp |
| 103 | ++ src/junit_log_formatter.cpp |
| 104 | ++ src/plain_report_formatter.cpp |
| 105 | ++ src/progress_monitor.cpp |
| 106 | ++ src/results_collector.cpp |
| 107 | ++ src/results_reporter.cpp |
| 108 | ++ src/test_framework_init_observer.cpp |
| 109 | ++ src/test_tools.cpp |
| 110 | ++ src/test_tree.cpp |
| 111 | ++ src/unit_test_log.cpp |
| 112 | ++ src/unit_test_main.cpp |
| 113 | ++ src/unit_test_monitor.cpp |
| 114 | ++ src/unit_test_parameters.cpp |
| 115 | ++ src/xml_log_formatter.cpp |
| 116 | ++ src/xml_report_formatter.cpp |
| 117 | ++ ) |
| 118 | ++ |
| 119 | ++ boost_test_add_library(test_exec_monitor STATIC ${SOURCES} src/test_main.cpp) |
| 120 | ++ boost_test_add_library(unit_test_framework ${SOURCES}) |
| 121 | ++ |
| 122 | ++ set(_boost_test_libraries boost_prg_exec_monitor boost_test_exec_monitor boost_unit_test_framework) |
| 123 | ++ |
| 124 | ++endif() |
| 125 | + |
| 126 | + # Header-only targets |
| 127 | + |
| 128 | +@@ -107,7 +117,7 @@ if(BOOST_SUPERPROJECT_VERSION AND NOT CMAKE_VERSION VERSION_LESS 3.13) |
| 129 | + |
| 130 | + boost_install( |
| 131 | + TARGETS |
| 132 | +- boost_prg_exec_monitor boost_test_exec_monitor boost_unit_test_framework |
| 133 | ++ ${_boost_test_libraries} |
| 134 | + boost_included_prg_exec_monitor boost_included_test_exec_monitor boost_included_unit_test_framework |
| 135 | + VERSION ${BOOST_SUPERPROJECT_VERSION} |
| 136 | + HEADER_DIRECTORY include |
0 commit comments