2
0
mirror of https://github.com/boostorg/url.git synced 2026-01-19 04:42:15 +00:00

build: tests rely on BUILD_TESTING

When URL was configured with cmake `-D BUILD_TESTING=ON` and then reconfigured with cmake `-D BUILD_TESTING=OFF`, tests would remain enabled. That's because `BUILD_TESTING` was only used once as the default value of `BOOST_URL_BUILD_TESTS` being cached. That's not how all other Boost libraries work.

This commit makes tests rely on `BUILD_TESTING` and, for backwards compatibility, `BOOST_URL_BUILD_TESTS` is only available as an extra option to enable Boost.URL tests even if `BUILD_TESTING` is `OFF`.

fix #805
This commit is contained in:
alandefreitas
2023-12-21 19:21:51 -03:00
committed by Alan de Freitas
parent 45670fc997
commit e35ae73ba5
2 changed files with 9 additions and 3 deletions

View File

@@ -31,7 +31,7 @@ set(__ignore__ ${CMAKE_C_COMPILER})
# Options
#
#-------------------------------------------------
option(BOOST_URL_BUILD_TESTS "Build boost::url tests" ${BUILD_TESTING})
option(BOOST_URL_BUILD_TESTS "Build boost::url tests even if BUILD_TESTING is OFF" OFF)
option(BOOST_URL_BUILD_FUZZERS "Build boost::url fuzzers" OFF)
option(BOOST_URL_BUILD_EXAMPLES "Build boost::url examples" ${BOOST_URL_IS_ROOT})
option(BOOST_URL_DISABLE_THREADS "Disable threads" OFF)
@@ -62,7 +62,7 @@ foreach (BOOST_URL_DEPENDENCY ${BOOST_URL_DEPENDENCIES})
endif ()
endforeach ()
# Conditional dependencies
if (BOOST_URL_BUILD_TESTS)
if (BUILD_TESTING OR BOOST_URL_BUILD_TESTS)
set(BOOST_URL_UNIT_TEST_LIBRARIES container filesystem unordered)
endif()
if (BOOST_URL_BUILD_EXAMPLES)
@@ -148,7 +148,7 @@ boost_url_setup_properties(boost_url)
# Tests
#
#-------------------------------------------------
if (BOOST_URL_BUILD_TESTS)
if (BUILD_TESTING OR BOOST_URL_BUILD_TESTS)
if (BOOST_URL_IS_ROOT)
include(CTest)
endif ()

View File

@@ -23,14 +23,19 @@ elseif(BOOST_CI_BOOST_SUBDIR_TEST)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
set(BOOST_URL_BUILD_TESTS OFF CACHE BOOL "Build the tests." FORCE)
set(PREV_BUILD_TESTING ${BUILD_TESTING} OFF CACHE BOOL "Build the tests." FORCE)
set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE)
set(BOOST_INCLUDE_LIBRARIES url)
add_subdirectory(../../../.. boost)
set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE)
elseif(BOOST_CI_URL_SUBDIR_TEST)
# Boost.URL 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_URL_BUILD_TESTS OFF CACHE BOOL "Build the tests." FORCE)
set(PREV_BUILD_TESTING ${BUILD_TESTING} OFF CACHE BOOL "Build the tests." FORCE)
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
@@ -63,6 +68,7 @@ elseif(BOOST_CI_URL_SUBDIR_TEST)
endif()
endforeach()
endif()
set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE)
endif()
add_executable(main main.cpp)