Skip to content

Commit a50ae36

Browse files
Abseil Teamvslashg
authored andcommitted
Export of internal Abseil changes
-- 4ceae78ecef025a331985958bba12ce12d4d0a68 by Derek Mauro <[email protected]>: Internal change PiperOrigin-RevId: 358888936 -- 48f69b0b46e2041bb321e8af7374d7e0b45efc25 by Derek Mauro <[email protected]>: Use the standard CTest mechanism BUILD_TESTING for enabling/disabling tests in CMake Fixes #901 PiperOrigin-RevId: 358822190 GitOrigin-RevId: 4ceae78ecef025a331985958bba12ce12d4d0a68 Change-Id: Ib1ca69a42355f2a4cd4c7f5a47184c4fd8441f35
1 parent a2d7f45 commit a50ae36

File tree

6 files changed

+15
-16
lines changed

6 files changed

+15
-16
lines changed

CMake/AbseilHelpers.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ endif()
4141
# LINKOPTS: List of link options
4242
# PUBLIC: Add this so that this library will be exported under absl::
4343
# Also in IDE, target will appear in Abseil folder while non PUBLIC will be in Abseil/internal.
44-
# TESTONLY: When added, this target will only be built if user passes -DABSL_RUN_TESTS=ON to CMake.
44+
# TESTONLY: When added, this target will only be built if BUILD_TESTING=ON.
4545
#
4646
# Note:
4747
# By default, absl_cc_library will always create a library named absl_${NAME},
@@ -83,7 +83,7 @@ function(absl_cc_library)
8383
${ARGN}
8484
)
8585

86-
if(ABSL_CC_LIB_TESTONLY AND NOT ABSL_RUN_TESTS)
86+
if(ABSL_CC_LIB_TESTONLY AND NOT BUILD_TESTING)
8787
return()
8888
endif()
8989

@@ -337,7 +337,7 @@ endfunction()
337337
# gtest_main
338338
# )
339339
function(absl_cc_test)
340-
if(NOT ABSL_RUN_TESTS)
340+
if(NOT BUILD_TESTING)
341341
return()
342342
endif()
343343

CMake/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ target_link_libraries(my_exe absl::base absl::synchronization absl::strings)
5252

5353
### Running Abseil Tests with CMake
5454

55-
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.
55+
Use the `-DBUILD_TESTING=ON` flag to run Abseil tests.
5656

5757
You will need to provide Abseil with a Googletest dependency. There are two
5858
options for how to do this:
@@ -70,7 +70,7 @@ For example, to run just the Abseil tests, you could use this script:
7070
cd path/to/abseil-cpp
7171
mkdir build
7272
cd build
73-
cmake -DABSL_USE_GOOGLETEST_HEAD=ON -DABSL_RUN_TESTS=ON ..
73+
cmake -DBUILD_TESTING=ON -DABSL_USE_GOOGLETEST_HEAD=ON ..
7474
make -j
7575
ctest
7676
```

CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ if (POLICY CMP0077)
4141
cmake_policy(SET CMP0077 NEW)
4242
endif (POLICY CMP0077)
4343

44+
# Set BUILD_TESTING to OFF by default.
45+
# This must come before the project() and include(CTest) lines.
46+
OPTION(BUILD_TESTING "Build tests" OFF)
47+
4448
project(absl CXX)
49+
include(CTest)
4550

4651
# Output directory is correct by default for most build setups. However, when
4752
# 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
104109
"If ABSL_USE_GOOGLETEST_HEAD is OFF and ABSL_GOOGLETEST_URL is not set, specifies the directory of a local GoogleTest checkout."
105110
)
106111

107-
option(ABSL_RUN_TESTS "If ON, Abseil tests will be run." OFF)
108-
109-
if(${ABSL_RUN_TESTS})
110-
# enable CTest. This will set BUILD_TESTING to ON unless otherwise specified
111-
# on the command line
112-
include(CTest)
113-
112+
if(BUILD_TESTING)
114113
## check targets
115114
if (NOT ABSL_USE_EXTERNAL_GOOGLETEST)
116115
set(absl_gtest_build_dir ${CMAKE_BINARY_DIR}/googletest-build)

ci/linux_gcc-latest_libstdcxx_cmake.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ for std in ${ABSL_CMAKE_CXX_STANDARDS}; do
5353
/bin/bash -c "
5454
cmake /abseil-cpp \
5555
-DABSL_GOOGLETEST_DOWNLOAD_URL=${ABSL_GOOGLETEST_DOWNLOAD_URL} \
56-
-DABSL_RUN_TESTS=ON \
5756
-DBUILD_SHARED_LIBS=${build_shared} \
57+
-DBUILD_TESTING=ON \
5858
-DCMAKE_BUILD_TYPE=${compilation_mode} \
5959
-DCMAKE_CXX_STANDARD=${std} \
6060
-DCMAKE_MODULE_LINKER_FLAGS=\"-Wl,--no-undefined\" && \

ci/linux_gcc_alpine_cmake.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ for std in ${ABSL_CMAKE_CXX_STANDARDS}; do
5353
/bin/sh -c "
5454
cmake /abseil-cpp \
5555
-DABSL_GOOGLETEST_DOWNLOAD_URL=${ABSL_GOOGLETEST_DOWNLOAD_URL} \
56-
-DABSL_RUN_TESTS=ON \
56+
-DBUILD_TESTING=ON \
5757
-DCMAKE_BUILD_TYPE=${compilation_mode} \
5858
-DCMAKE_CXX_STANDARD=${std} \
5959
-DCMAKE_MODULE_LINKER_FLAGS=\"-Wl,--no-undefined\" && \

ci/macos_xcode_cmake.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ for compilation_mode in ${ABSL_CMAKE_BUILD_TYPES}; do
4545
time cmake ${ABSEIL_ROOT} \
4646
-GXcode \
4747
-DBUILD_SHARED_LIBS=${build_shared} \
48+
-DBUILD_TESTING=ON \
4849
-DCMAKE_BUILD_TYPE=${compilation_mode} \
4950
-DCMAKE_CXX_STANDARD=11 \
5051
-DCMAKE_MODULE_LINKER_FLAGS="-Wl,--no-undefined" \
51-
-DABSL_GOOGLETEST_DOWNLOAD_URL="${ABSL_GOOGLETEST_DOWNLOAD_URL}" \
52-
-DABSL_RUN_TESTS=ON
52+
-DABSL_GOOGLETEST_DOWNLOAD_URL="${ABSL_GOOGLETEST_DOWNLOAD_URL}"
5353
time cmake --build .
5454
time ctest -C ${compilation_mode} --output-on-failure
5555
done

0 commit comments

Comments
 (0)