Skip to content

Commit b399348

Browse files
committed
fix: use custom protoc command for cross-platform compatibility
- Replace protobuf_generate with custom add_custom_command - Use --proto_path to ensure correct symbol naming - Linux/macOS use system protobuf (apt/brew) - Windows uses vcpkg - Update documentation for platform-specific dependencies
1 parent a6ee159 commit b399348

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

CMakeLists.txt

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ set(FFI_PROTO_FILES
7676
set(PROTO_BINARY_DIR ${LIVEKIT_BINARY_DIR}/generated)
7777
file(MAKE_DIRECTORY ${PROTO_BINARY_DIR})
7878

79-
find_package(Protobuf CONFIG REQUIRED)
79+
# Try to find Protobuf via CONFIG mode first (vcpkg), then fall back to MODULE mode (apt/brew)
80+
find_package(Protobuf CONFIG QUIET)
81+
if(NOT Protobuf_FOUND)
82+
find_package(Protobuf REQUIRED)
83+
endif()
8084

8185
add_library(livekit_proto OBJECT ${FFI_PROTO_FILES})
8286
target_include_directories(livekit_proto PRIVATE
@@ -85,13 +89,28 @@ target_include_directories(livekit_proto PRIVATE
8589
)
8690
target_link_libraries(livekit_proto PRIVATE protobuf::libprotobuf)
8791

88-
protobuf_generate(
89-
LANGUAGE cpp
90-
TARGET livekit_proto
91-
PROTOC_OUT_DIR ${PROTO_BINARY_DIR}
92-
IMPORT_DIRS ${FFI_PROTO_DIR}
92+
# Manually generate protobuf files to avoid path prefix issues
93+
set(PROTO_SRCS)
94+
set(PROTO_HDRS)
95+
foreach(PROTO_FILE ${FFI_PROTO_FILES})
96+
get_filename_component(PROTO_NAME ${PROTO_FILE} NAME_WE)
97+
list(APPEND PROTO_SRCS "${PROTO_BINARY_DIR}/${PROTO_NAME}.pb.cc")
98+
list(APPEND PROTO_HDRS "${PROTO_BINARY_DIR}/${PROTO_NAME}.pb.h")
99+
endforeach()
100+
101+
add_custom_command(
102+
OUTPUT ${PROTO_SRCS} ${PROTO_HDRS}
103+
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
104+
--proto_path=${FFI_PROTO_DIR}
105+
--cpp_out=${PROTO_BINARY_DIR}
106+
${FFI_PROTO_FILES}
107+
DEPENDS ${FFI_PROTO_FILES}
108+
COMMENT "Generating C++ protobuf files"
109+
VERBATIM
93110
)
94111

112+
target_sources(livekit_proto PRIVATE ${PROTO_SRCS} ${PROTO_HDRS})
113+
95114
set(GENERATED_INCLUDE_DIR "${LIVEKIT_BINARY_DIR}/generated")
96115
file(MAKE_DIRECTORY "${GENERATED_INCLUDE_DIR}")
97116

DEPENDENCIES.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,27 +140,26 @@ sudo dnf install protobuf-devel abseil-cpp-devel openssl-devel
140140

141141
```cmake
142142
find_package(Protobuf REQUIRED)
143-
find_package(absl REQUIRED)
144143
find_package(OpenSSL REQUIRED)
145144
146145
target_link_libraries(your_app PRIVATE
147146
# LiveKit static libraries
148147
livekit
149148
livekit_ffi
150149
151-
# Protobuf and Abseil (REQUIRED)
150+
# Protobuf (REQUIRED)
152151
protobuf::libprotobuf
153-
absl::log
154-
absl::check
155-
absl::strings
156-
absl::base
157152
158153
# Linux system libraries (REQUIRED)
159154
OpenSSL::SSL
160155
OpenSSL::Crypto
161156
pthread
162157
dl
163158
)
159+
160+
# NOTE: If using Protobuf 6.0+, you also need to link Abseil:
161+
# find_package(absl REQUIRED)
162+
# target_link_libraries(your_app PRIVATE absl::log absl::strings absl::base)
164163
```
165164

166165
### Manual Linking (Makefile/gcc)
@@ -169,8 +168,7 @@ g++ your_app.cpp \
169168
-I/path/to/livekit/include \
170169
-L/path/to/livekit/lib \
171170
-llivekit -llivekit_ffi \
172-
-lprotobuf -labsl_log -labsl_strings -labsl_base \
173-
-lssl -lcrypto -lpthread -ldl
171+
-lprotobuf -lssl -lcrypto -lpthread -ldl
174172
```
175173

176174
---

0 commit comments

Comments
 (0)