]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: Fix warning suppression for googletest build 62641/head
authorKefu Chai <tchaikov@gmail.com>
Thu, 3 Apr 2025 02:03:08 +0000 (10:03 +0800)
committerKefu Chai <tchaikov@gmail.com>
Thu, 3 Apr 2025 02:14:08 +0000 (10:14 +0800)
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 <tchaikov@gmail.com>
src/CMakeLists.txt

index 6f1f1d38c05f233a96c666d078b64228d37a0d83..1114bd254acceab2417e3cf143ee3c96819727b8 100644 (file)
@@ -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_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES>)
     target_include_directories(gmock_main INTERFACE
       $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES>)
+    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()