From: Kefu Chai Date: Wed, 2 Apr 2025 03:24:40 +0000 (+0800) Subject: cmake: disable deprecated warning when building googletest X-Git-Tag: testing/wip-vshankar-testing-20250407.170244-debug~41^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=27e9d56304f3b8e8ee69fac24fa5a38336d2089b;p=ceph-ci.git cmake: disable deprecated warning when building googletest 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' is deprecated [-Werror,-Wdeprecated-declarations] 263 | std::get_temporary_buffer(_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 *>::_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>, __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 --- diff --git a/cmake/modules/CephChecks.cmake b/cmake/modules/CephChecks.cmake index da69b241050..4da4dfad5bf 100644 --- a/cmake/modules/CephChecks.cmake +++ b/cmake/modules/CephChecks.cmake @@ -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 +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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6857e413e1e..6f1f1d38c05 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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)