Skip to content

Conversation

ZhongRuoyu
Copy link
Contributor

Replace deprecated protobuf_generate_cpp with protobuf_generate, which is available in CMake since version 3.13 1. This CMake version is already higher than the minimum required version (3.20), so no backward compatibility needs to be considered.

Although protobuf_generate does not separate the generated .cc and .h files into different variables, we don't need to worry about that because they are always used together anyway.

Also, remove the generated protobuf sources from LLVM_OPTIONAL_SOURCES; they are not in the source tree so it's unnecessary to list them there.

Fixes #160677.

Footnotes

  1. https://cmake.org/cmake/help/latest/module/FindProtobuf.html#command:protobuf_generate

Replace deprecated protobuf_generate_cpp with protobuf_generate, which
is available in CMake since version 3.13 [1]. This CMake version is
already higher than the minimum required version (3.20), so no backward
compatibility needs to be considered.

Although protobuf_generate does not separate the generated .cc and .h
files into different variables, we don't need to worry about that
because they are always used together anyway.

Also, remove the generated protobuf sources from LLVM_OPTIONAL_SOURCES;
they are not in the source tree so it's unnecessary to list them there.

Fixes llvm#160677.

[1]: https://cmake.org/cmake/help/latest/module/FindProtobuf.html#command:protobuf_generate

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Sep 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 29, 2025

@llvm/pr-subscribers-clang

Author: Ruoyu Zhong (ZhongRuoyu)

Changes

Replace deprecated protobuf_generate_cpp with protobuf_generate, which is available in CMake since version 3.13 1. This CMake version is already higher than the minimum required version (3.20), so no backward compatibility needs to be considered.

Although protobuf_generate does not separate the generated .cc and .h files into different variables, we don't need to worry about that because they are always used together anyway.

Also, remove the generated protobuf sources from LLVM_OPTIONAL_SOURCES; they are not in the source tree so it's unnecessary to list them there.

Fixes #160677.


Full diff: https://github.com/llvm/llvm-project/pull/161239.diff

1 Files Affected:

  • (modified) clang/tools/clang-fuzzer/CMakeLists.txt (+11-6)
diff --git a/clang/tools/clang-fuzzer/CMakeLists.txt b/clang/tools/clang-fuzzer/CMakeLists.txt
index 2b9720ee627cb..d6fcf9283969c 100644
--- a/clang/tools/clang-fuzzer/CMakeLists.txt
+++ b/clang/tools/clang-fuzzer/CMakeLists.txt
@@ -26,12 +26,18 @@ if(CLANG_ENABLE_PROTO_FUZZER)
   add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI)
   include_directories(${PROTOBUF_INCLUDE_DIRS})
   include_directories(${CMAKE_CURRENT_BINARY_DIR})
-  protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS cxx_proto.proto)
-  protobuf_generate_cpp(LOOP_PROTO_SRCS LOOP_PROTO_HDRS cxx_loop_proto.proto)
-  set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES} ${PROTO_SRCS})
+  protobuf_generate(
+    LANGUAGE cpp
+    OUT_VAR PROTO_SRCS
+    PROTOS cxx_proto.proto
+  )
+  protobuf_generate(
+    LANGUAGE cpp
+    OUT_VAR LOOP_PROTO_SRCS
+    PROTOS cxx_loop_proto.proto
+  )
   add_clang_library(clangCXXProto
     ${PROTO_SRCS}
-    ${PROTO_HDRS}
 
     LINK_LIBS
     ${PROTOBUF_LIBRARIES}
@@ -39,7 +45,6 @@ if(CLANG_ENABLE_PROTO_FUZZER)
 
   add_clang_library(clangCXXLoopProto
     ${LOOP_PROTO_SRCS}
-    ${LOOP_PROTO_HDRS}
 
     LINK_LIBS
     ${PROTOBUF_LIBRARIES}
@@ -54,7 +59,7 @@ if(CLANG_ENABLE_PROTO_FUZZER)
 
   # Build the protobuf->LLVM IR translation library and driver.
   add_clang_subdirectory(proto-to-llvm)
-  
+
   # Build the fuzzer initialization library.
   add_clang_subdirectory(fuzzer-initialize)
 

Footnotes

  1. https://cmake.org/cmake/help/latest/module/FindProtobuf.html#command:protobuf_generate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

protobuf_generate_cpp is deprecated

2 participants