]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: disable deprecated warning when building googletest 62622/head
authorKefu Chai <tchaikov@gmail.com>
Wed, 2 Apr 2025 03:24:40 +0000 (11:24 +0800)
committerKefu Chai <tchaikov@gmail.com>
Wed, 2 Apr 2025 03:35:45 +0000 (11:35 +0800)
In commit 986f6918, we updated the googletest submodule to silence a
CMake warning. However, this change broke the build due to a Clang issue
where it warns about deprecated declarations even from system headers
(see https://github.com/llvm/llvm-project/issues/76515). Since we use
`-Werror` in our compile options, these warnings become errors and fail
the build.

This change detects if we're affected by the specific combination of
compiler, standard library, and compile options that triggers this
issue. It then conditionally disables the `-Wdeprecated-declarations`
warning when building googletest to resolve build failures caused by
deprecated functions like `get_temporary_buffer<>` in the standard
library.

The build failure looks like:
```
FAILED: src/googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
...
In file included from /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest-all.cc:38:
In file included from /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/include/gtest/gtest.h:55:
In file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/memory:66:
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_tempbuf.h:263:8: error: 'get_temporary_buffer<testing::TestInfo *>' is deprecated [-Werror,-Wdeprecated-declarations]
  263 |                 std::get_temporary_buffer<value_type>(_M_original_len));
      |                      ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:4996:15: note: in instantiation of member function 'std::_Temporary_buffer<__gnu_cxx::__normal_iterator<testing::TestInfo **, std::vector<testing::TestInfo *>>, testing::TestInfo *>::_Temporary_buffer' requested here
 4996 |       _TmpBuf __buf(__first, (__last - __first + 1) / 2);
      |               ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:5070:23: note: in instantiation of function template specialization 'std::__stable_sort<__gnu_cxx::__normal_iterator<testing::TestInfo **, std::vector<testing::TestInfo *>>, __gnu_cxx::__ops::_Iter_comp_iter<(lambda at /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:3024:20)>>' requested here
 5070 |       _GLIBCXX_STD_A::__stable_sort(__first, __last,
      |                       ^
/home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:3023:8: note: in instantiation of function template specializatio
```

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
cmake/modules/CephChecks.cmake
src/CMakeLists.txt

index da69b24105077a33206766b96685ed64814c9391..4da4dfad5bf3d225cc4fc66df1ea29416236edc5 100644 (file)
@@ -150,6 +150,20 @@ else(NOT CMAKE_CROSSCOMPILING)
   message(STATUS "Assuming unaligned access is supported")
 endif(NOT CMAKE_CROSSCOMPILING)
 
+# Clang warns on deprecated specialization used in system
+# headers. but libstdc++-12 uses deprecated get_temporary_buffer<>
+# to implement templated stable_sort(), which is turn used by
+# googletest. see https://github.com/llvm/llvm-project/issues/76515
+# Let's detect it, so we can disable -Wdeprecated-declarations when
+# building googletest.
+cmake_push_check_state(RESET)
+set(CMAKE_REQUIRED_FLAGS "-Werror=deprecated-declarations")
+check_cxx_source_compiles("
+#include <algorithm>
+int main() { std::stable_sort((int *)0, (int*)0); }
+" COMPILER_IGNORES_DEPRECATED_DECL_IN_SYSTEM_HEADERS)
+cmake_pop_check_state()
+
 set(version_script_source "v1 { }; v2 { } v1;")
 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/version_script.txt "${version_script_source}")
 cmake_push_check_state(RESET)
index 6857e413e1ea3fe383a3fcd2eb567dce456a05ea..6f1f1d38c05f233a96c666d078b64228d37a0d83 100644 (file)
@@ -767,6 +767,12 @@ if(WITH_TESTS)
     find_package(GTest 1.13.0 REQUIRED)
     find_package(GMock REQUIRED)
   else()
+    if(NOT COMPILER_IGNORES_DEPRECATED_DECL_IN_SYSTEM_HEADERS)
+      # See https://github.com/llvm/llvm-project/issues/76515
+      set_property(DIRECTORY googletest
+        APPEND "-Wno-deprecated-declarations"
+        PROPERTY COMPILE_OPTIONS)
+    endif()
     set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
     add_subdirectory(googletest)
     add_library(GMock::GMock ALIAS gmock)