From: Kefu Chai Date: Thu, 3 Apr 2025 02:03:08 +0000 (+0800) Subject: cmake: Fix warning suppression for googletest build X-Git-Tag: v20.3.0~180^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=08ce6dc51b1d9956b3e63b43da315fa4567fc80f;p=ceph.git cmake: Fix warning suppression for googletest build In commit 27e9d563, we attempted to disable deprecated warnings when building googletest, but the implementation contained two errors: 1. The `set_property()` call occurred before adding the target directory, making it impossible to set properties on non-existent objects. 2. The `-Wno-deprecated-declarations` flag was incorrectly passed as an `APPEND` argument instead of a `PROPERTY` argument. This caused build failures with libstdc++-12 and newer Clang versions: ``` CMake Error at src/CMakeLists.txt:772 (set_property): set_property given invalid argument "-Wno-deprecated-declarations". ``` This commit fixes both issues by: - Moving the `set_property()` call after `add_subdirectory()` - Correctly passing the warning flag as a `PROPERTY` argument Signed-off-by: Kefu Chai --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6f1f1d38c05f2..1114bd254acce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -767,12 +767,6 @@ 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) @@ -781,6 +775,12 @@ if(WITH_TESTS) $) target_include_directories(gmock_main INTERFACE $) + if(NOT COMPILER_IGNORES_DEPRECATED_DECL_IN_SYSTEM_HEADERS) + # See https://github.com/llvm/llvm-project/issues/76515 + set_property(DIRECTORY googletest + APPEND + PROPERTY COMPILE_OPTIONS "-Wno-deprecated-declarations") + endif() add_library(GTest::GTest ALIAS gtest) add_library(GTest::Main ALIAS gtest_main) endif()