summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2021-02-22 13:18:10 -0800
committerGravatar vslashg <gfalcon@google.com>2021-02-22 16:20:19 -0500
commita50ae369a30f99f79d7559002aba3413dac1bd48 (patch)
tree89fd47210f4ec6885bcd47691533fd4ebbed3fbd
parenta2d7f453c635e90b356017dd47049b89407c2d88 (diff)
Export of internal Abseil changes
-- 4ceae78ecef025a331985958bba12ce12d4d0a68 by Derek Mauro <dmauro@google.com>: Internal change PiperOrigin-RevId: 358888936 -- 48f69b0b46e2041bb321e8af7374d7e0b45efc25 by Derek Mauro <dmauro@google.com>: Use the standard CTest mechanism BUILD_TESTING for enabling/disabling tests in CMake Fixes #901 PiperOrigin-RevId: 358822190 GitOrigin-RevId: 4ceae78ecef025a331985958bba12ce12d4d0a68 Change-Id: Ib1ca69a42355f2a4cd4c7f5a47184c4fd8441f35
-rw-r--r--CMake/AbseilHelpers.cmake6
-rw-r--r--CMake/README.md4
-rw-r--r--CMakeLists.txt13
-rwxr-xr-xci/linux_gcc-latest_libstdcxx_cmake.sh2
-rwxr-xr-xci/linux_gcc_alpine_cmake.sh2
-rwxr-xr-xci/macos_xcode_cmake.sh4
6 files changed, 15 insertions, 16 deletions
diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake
index 588d4fa2..1541435d 100644
--- a/CMake/AbseilHelpers.cmake
+++ b/CMake/AbseilHelpers.cmake
@@ -41,7 +41,7 @@ endif()
# LINKOPTS: List of link options
# PUBLIC: Add this so that this library will be exported under absl::
# Also in IDE, target will appear in Abseil folder while non PUBLIC will be in Abseil/internal.
-# TESTONLY: When added, this target will only be built if user passes -DABSL_RUN_TESTS=ON to CMake.
+# TESTONLY: When added, this target will only be built if BUILD_TESTING=ON.
#
# Note:
# By default, absl_cc_library will always create a library named absl_${NAME},
@@ -83,7 +83,7 @@ function(absl_cc_library)
${ARGN}
)
- if(ABSL_CC_LIB_TESTONLY AND NOT ABSL_RUN_TESTS)
+ if(ABSL_CC_LIB_TESTONLY AND NOT BUILD_TESTING)
return()
endif()
@@ -337,7 +337,7 @@ endfunction()
# gtest_main
# )
function(absl_cc_test)
- if(NOT ABSL_RUN_TESTS)
+ if(NOT BUILD_TESTING)
return()
endif()
diff --git a/CMake/README.md b/CMake/README.md
index 8f73475a..5eee8171 100644
--- a/CMake/README.md
+++ b/CMake/README.md
@@ -52,7 +52,7 @@ target_link_libraries(my_exe absl::base absl::synchronization absl::strings)
### Running Abseil Tests with CMake
-Use the `-DABSL_RUN_TESTS=ON` flag to run Abseil tests. Note that if the `-DBUILD_TESTING=OFF` flag is passed then Abseil tests will not be run.
+Use the `-DBUILD_TESTING=ON` flag to run Abseil tests.
You will need to provide Abseil with a Googletest dependency. There are two
options for how to do this:
@@ -70,7 +70,7 @@ For example, to run just the Abseil tests, you could use this script:
cd path/to/abseil-cpp
mkdir build
cd build
-cmake -DABSL_USE_GOOGLETEST_HEAD=ON -DABSL_RUN_TESTS=ON ..
+cmake -DBUILD_TESTING=ON -DABSL_USE_GOOGLETEST_HEAD=ON ..
make -j
ctest
```
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d8c3b580..8843ee79 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,7 +41,12 @@ if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif (POLICY CMP0077)
+# Set BUILD_TESTING to OFF by default.
+# This must come before the project() and include(CTest) lines.
+OPTION(BUILD_TESTING "Build tests" OFF)
+
project(absl CXX)
+include(CTest)
# Output directory is correct by default for most build setups. However, when
# building Abseil as a DLL, it is important to have the DLL in the same
@@ -104,13 +109,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."
)
-option(ABSL_RUN_TESTS "If ON, Abseil tests will be run." OFF)
-
-if(${ABSL_RUN_TESTS})
- # enable CTest. This will set BUILD_TESTING to ON unless otherwise specified
- # on the command line
- include(CTest)
-
+if(BUILD_TESTING)
## check targets
if (NOT ABSL_USE_EXTERNAL_GOOGLETEST)
set(absl_gtest_build_dir ${CMAKE_BINARY_DIR}/googletest-build)
diff --git a/ci/linux_gcc-latest_libstdcxx_cmake.sh b/ci/linux_gcc-latest_libstdcxx_cmake.sh
index ed9cfa38..ab06aa05 100755
--- a/ci/linux_gcc-latest_libstdcxx_cmake.sh
+++ b/ci/linux_gcc-latest_libstdcxx_cmake.sh
@@ -53,8 +53,8 @@ for std in ${ABSL_CMAKE_CXX_STANDARDS}; do
/bin/bash -c "
cmake /abseil-cpp \
-DABSL_GOOGLETEST_DOWNLOAD_URL=${ABSL_GOOGLETEST_DOWNLOAD_URL} \
- -DABSL_RUN_TESTS=ON \
-DBUILD_SHARED_LIBS=${build_shared} \
+ -DBUILD_TESTING=ON \
-DCMAKE_BUILD_TYPE=${compilation_mode} \
-DCMAKE_CXX_STANDARD=${std} \
-DCMAKE_MODULE_LINKER_FLAGS=\"-Wl,--no-undefined\" && \
diff --git a/ci/linux_gcc_alpine_cmake.sh b/ci/linux_gcc_alpine_cmake.sh
index 31310ac7..bce27d29 100755
--- a/ci/linux_gcc_alpine_cmake.sh
+++ b/ci/linux_gcc_alpine_cmake.sh
@@ -53,7 +53,7 @@ for std in ${ABSL_CMAKE_CXX_STANDARDS}; do
/bin/sh -c "
cmake /abseil-cpp \
-DABSL_GOOGLETEST_DOWNLOAD_URL=${ABSL_GOOGLETEST_DOWNLOAD_URL} \
- -DABSL_RUN_TESTS=ON \
+ -DBUILD_TESTING=ON \
-DCMAKE_BUILD_TYPE=${compilation_mode} \
-DCMAKE_CXX_STANDARD=${std} \
-DCMAKE_MODULE_LINKER_FLAGS=\"-Wl,--no-undefined\" && \
diff --git a/ci/macos_xcode_cmake.sh b/ci/macos_xcode_cmake.sh
index 0847b3ea..2a870cf4 100755
--- a/ci/macos_xcode_cmake.sh
+++ b/ci/macos_xcode_cmake.sh
@@ -45,11 +45,11 @@ for compilation_mode in ${ABSL_CMAKE_BUILD_TYPES}; do
time cmake ${ABSEIL_ROOT} \
-GXcode \
-DBUILD_SHARED_LIBS=${build_shared} \
+ -DBUILD_TESTING=ON \
-DCMAKE_BUILD_TYPE=${compilation_mode} \
-DCMAKE_CXX_STANDARD=11 \
-DCMAKE_MODULE_LINKER_FLAGS="-Wl,--no-undefined" \
- -DABSL_GOOGLETEST_DOWNLOAD_URL="${ABSL_GOOGLETEST_DOWNLOAD_URL}" \
- -DABSL_RUN_TESTS=ON
+ -DABSL_GOOGLETEST_DOWNLOAD_URL="${ABSL_GOOGLETEST_DOWNLOAD_URL}"
time cmake --build .
time ctest -C ${compilation_mode} --output-on-failure
done