Skip to content

Commit d467e57

Browse files
ffacscursoragent
andcommitted
[C++] Fix vendored Protobuf target conflicts for version >= 3.21
Guard alias creation for protobuf::libprotobuf and protobuf::protoc to avoid duplicate target errors when Protobuf >= 3.21 already exports them. Also mark protobuf headers as SYSTEM to suppress compiler warnings from protobuf code. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 5d1421d commit d467e57

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

cmake_modules/ThirdpartyToolchain.cmake

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,24 @@ else ()
219219
if(protobuf_SOURCE_DIR)
220220
message(STATUS "Using vendored Protobuf")
221221

222-
add_library(protobuf::libprotobuf ALIAS libprotobuf)
223-
add_executable(protobuf::protoc ALIAS protoc)
222+
# Protobuf >= 3.21 exports protobuf::libprotobuf/protobuf::protoc itself.
223+
# Guard alias creation to avoid duplicate target errors.
224+
if(TARGET libprotobuf AND NOT TARGET protobuf::libprotobuf)
225+
add_library(protobuf::libprotobuf ALIAS libprotobuf)
226+
endif()
227+
if(TARGET protoc AND NOT TARGET protobuf::protoc)
228+
add_executable(protobuf::protoc ALIAS protoc)
229+
endif()
230+
231+
# Avoid exporting build/source paths in install interface.
232+
# Mark as SYSTEM so compiler suppresses warnings from protobuf headers
233+
# (e.g. -Wunused-parameter) without affecting ORC's own code.
234+
if(TARGET libprotobuf)
235+
set_property(TARGET libprotobuf PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
236+
target_include_directories(libprotobuf SYSTEM INTERFACE
237+
"$<BUILD_INTERFACE:${protobuf_SOURCE_DIR}/src>"
238+
"$<BUILD_INTERFACE:${protobuf_BINARY_DIR}>")
239+
endif()
224240

225241
if(BUILD_POSITION_INDEPENDENT_LIB)
226242
set_target_properties(libprotobuf PROPERTIES POSITION_INDEPENDENT_CODE ON)

0 commit comments

Comments
 (0)