Skip to content

Commit c0df923

Browse files
Weiming Zhaoweimingzha0
Weiming Zhao
authored andcommitted
[libhalo] Allow link with static protobuf library
This can avoid the dependency on a specific version of protobuf
1 parent d9163e3 commit c0df923

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cmake/modules/protobuf.cmake

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@
1616

1717
# Build protobuf.
1818

19+
option(HALO_USE_STATIC_PROTOBUF "Link against static protobuf library" OFF)
20+
21+
if (HALO_USE_STATIC_PROTOBUF)
22+
set(Protobuf_USE_STATIC_LIBS ON)
23+
endif()
24+
1925
find_package(Protobuf REQUIRED 3.9.1)
2026

2127
if (Protobuf_FOUND)
2228
message(STATUS "Found Protobuf ${Protobuf_VERSION}: ${Protobuf_LIBRARY}")
2329
else()
24-
message(FATAL_ERROR "Protobuf lib not found")
30+
message(FATAL_ERROR "Protobuf lib not found")
2531
endif(Protobuf_FOUND)
2632

2733
macro(gen_protobuf_files)
@@ -42,11 +48,11 @@ macro(gen_protobuf_files)
4248

4349
# Add link library and include pathes for generated files.
4450
set(GEN_TARGET ${_TARGET_NAME}_GEN)
45-
add_library(${GEN_TARGET} OBJECT "")
51+
add_library(${GEN_TARGET} OBJECT "")
4652
target_sources(${GEN_TARGET} PUBLIC ${ALL_GEN_SRCS})
4753
if (HALO_NO_RTTI)
4854
target_compile_definitions(${GEN_TARGET} PUBLIC -DGOOGLE_PROTOBUF_NO_RTTI=1)
49-
endif()
55+
endif()
5056
target_link_libraries(${GEN_TARGET} PUBLIC ${Protobuf_LIBRARIES})
5157
target_include_directories(${GEN_TARGET} PUBLIC ${Protobuf_INCLUDE_DIRS} ${GEN_DIR})
5258

0 commit comments

Comments
 (0)