]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cmake: Fix googletest deprecated warnings by using target_compile_options()
authorKefu Chai <tchaikov@gmail.com>
Fri, 4 Apr 2025 07:37:20 +0000 (15:37 +0800)
committerKefu Chai <tchaikov@gmail.com>
Fri, 4 Apr 2025 07:44:16 +0000 (15:44 +0800)
Previously, we attempted to disable deprecated declarations warnings when
building gtest by adding `-Wno-deprecated-declarations` to the COMPILE_OPTIONS
property of the googletest directory. However, this approach failed to apply
the option when actually building gtest.

This change applies the compile option directly to the `gtest` target using
target_compile_options() instead. Verified by forcing the condition to TRUE
and confirming the option is included when building `gtest-all.cc` through
`cmake --build ~/dev/ceph/build --target gtest --verbose`.

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

index 23b9442bd28af36692a16ca108e93d9759155ba6..801086e1268a121af683c32f043dd2ec4c92dd6d 100644 (file)
@@ -777,9 +777,8 @@ if(WITH_TESTS)
       $<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")
+      target_compile_options(gtest
+        PRIVATE "-Wno-deprecated-declarations")
     endif()
     add_library(GTest::GTest ALIAS gtest)
     add_library(GTest::Main ALIAS gtest_main)