diff options
author | Derek Mauro <dmauro@google.com> | 2022-08-29 16:52:14 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-08-29 16:52:55 -0700 |
commit | 277ce1ddc2e6d8d3687f3f5e3c95ef1db04c787a (patch) | |
tree | e44f719dca278ecda4d4052aa2075cc6e4dd0199 | |
parent | d9382f72901dd2bd40d38834eb591cea784e90e5 (diff) |
CMake: Add an option to build the libraries that are used for writing
tests without requiring Abseil's tests be built (default=OFF)
This disables building libraries that are only used for writing tests
by default.
The logging library releases some libraries used for writing tests
that themselves depend on GoogleTest. This allows Abseil to build by
default without requiring GoogleTest.
Fixes #1262
PiperOrigin-RevId: 470847215
Change-Id: I296f41aa06d6f302853af3f32e1f762649504afc
-rw-r--r-- | CMake/AbseilHelpers.cmake | 5 | ||||
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rwxr-xr-x | ci/cmake_install_test.sh | 12 |
3 files changed, 20 insertions, 3 deletions
diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake index 3fb86375..e3194bcf 100644 --- a/CMake/AbseilHelpers.cmake +++ b/CMake/AbseilHelpers.cmake @@ -97,8 +97,9 @@ function(absl_cc_library) ${ARGN} ) - if(NOT ABSL_CC_LIB_PUBLIC AND ABSL_CC_LIB_TESTONLY AND - NOT (BUILD_TESTING AND ABSL_BUILD_TESTING)) + if(ABSL_CC_LIB_TESTONLY AND + NOT ((BUILD_TESTING AND ABSL_BUILD_TESTING) OR + (ABSL_BUILD_TEST_HELPERS AND ABSL_CC_LIB_PUBLIC))) return() endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 995d90e5..706af68a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,6 +114,10 @@ include(CMakeDependentOption) option(ABSL_BUILD_TESTING "If ON, Abseil will build all of Abseil's own tests." OFF) +option(ABSL_BUILD_TEST_HELPERS + "If ON, Abseil will build libraries that you can use to write tests against Abseil code. This option requires that Abseil is configured to use GoogleTest." + OFF) + option(ABSL_USE_EXTERNAL_GOOGLETEST "If ON, Abseil will assume that the targets for GoogleTest are already provided by the including project. This makes sense when Abseil is used with add_subdirectory." OFF) @@ -133,7 +137,7 @@ set(ABSL_LOCAL_GOOGLETEST_DIR "/usr/src/googletest" CACHE PATH "If ABSL_USE_GOOGLETEST_HEAD is OFF and ABSL_GOOGLETEST_URL is not set, specifies the directory of a local GoogleTest checkout." ) -if(BUILD_TESTING AND ABSL_BUILD_TESTING) +if((BUILD_TESTING AND ABSL_BUILD_TESTING) OR ABSL_BUILD_TEST_HELPERS) ## check targets if (ABSL_USE_EXTERNAL_GOOGLETEST) if (ABSL_FIND_GOOGLETEST) diff --git a/ci/cmake_install_test.sh b/ci/cmake_install_test.sh index 97ed8478..ab3b86f0 100755 --- a/ci/cmake_install_test.sh +++ b/ci/cmake_install_test.sh @@ -29,6 +29,18 @@ source "${ABSEIL_ROOT}/ci/cmake_common.sh" source "${ABSEIL_ROOT}/ci/linux_docker_containers.sh" readonly DOCKER_CONTAINER=${LINUX_GCC_LATEST_CONTAINER} +# Verify that everything works with the standard "cmake && make && make install" +# without building tests or requiring GoogleTest. +time docker run \ + --mount type=bind,source="${ABSEIL_ROOT}",target=/abseil-cpp-ro,readonly \ + --tmpfs=/buildfs:exec \ + --workdir=/buildfs \ + --rm \ + ${DOCKER_EXTRA_ARGS:-} \ + ${DOCKER_CONTAINER} \ + /bin/bash -c "cmake /abseil-cpp-ro && make -j$(nproc) && make install" + +# Verify that a more complicated project works. for link_type in ${LINK_TYPE}; do time docker run \ --mount type=bind,source="${ABSEIL_ROOT}",target=/abseil-cpp-ro,readonly \ |