Skip to content

Commit 7daa320

Browse files
authored
Merge pull request #3878 from Yangqing/master
Allow one to omit building libprotoc and protoc binaries
2 parents cf68531 + cba18ef commit 7daa320

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

cmake/CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ project(protobuf C CXX)
1414
# Options
1515
option(protobuf_BUILD_TESTS "Build tests" ON)
1616
option(protobuf_BUILD_EXAMPLES "Build examples" OFF)
17+
option(protobuf_BUILD_PROTOC_BINARIES "Build libprotoc and protoc compiler" ON)
1718
if (BUILD_SHARED_LIBS)
1819
set(protobuf_BUILD_SHARED_LIBS_DEFAULT ON)
1920
else (BUILD_SHARED_LIBS)
@@ -184,8 +185,10 @@ endif (protobuf_UNICODE)
184185

185186
include(libprotobuf-lite.cmake)
186187
include(libprotobuf.cmake)
187-
include(libprotoc.cmake)
188-
include(protoc.cmake)
188+
if (protobuf_BUILD_PROTOC_BINARIES)
189+
include(libprotoc.cmake)
190+
include(protoc.cmake)
191+
endif (protobuf_BUILD_PROTOC_BINARIES)
189192

190193
if (protobuf_BUILD_TESTS)
191194
include(tests.cmake)

cmake/install.cmake

+22-10
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protobuf.pc.cmake
55
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protobuf-lite.pc.cmake
66
${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc @ONLY)
77

8-
foreach(_library
9-
libprotobuf-lite
10-
libprotobuf
11-
libprotoc)
8+
set(_protobuf_libraries libprotobuf-lite libprotobuf)
9+
if (protobuf_BUILD_PROTOC_BINARIES)
10+
list(APPEND _protobuf_libraries libprotoc)
11+
endif (protobuf_BUILD_PROTOC_BINARIES)
12+
13+
foreach(_library ${_protobuf_libraries})
1214
set_property(TARGET ${_library}
1315
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
1416
$<BUILD_INTERFACE:${protobuf_source_dir}/src>
@@ -19,8 +21,10 @@ foreach(_library
1921
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
2022
endforeach()
2123

22-
install(TARGETS protoc EXPORT protobuf-targets
23-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
24+
if (protobuf_BUILD_PROTOC_BINARIES)
25+
install(TARGETS protoc EXPORT protobuf-targets
26+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
27+
endif (protobuf_BUILD_PROTOC_BINARIES)
2428

2529
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
2630

@@ -101,10 +105,18 @@ configure_file(protobuf-options.cmake
101105
${CMAKE_INSTALL_CMAKEDIR}/protobuf-options.cmake @ONLY)
102106

103107
# Allows the build directory to be used as a find directory.
104-
export(TARGETS libprotobuf-lite libprotobuf libprotoc protoc
105-
NAMESPACE protobuf::
106-
FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
107-
)
108+
109+
if (protobuf_BUILD_PROTOC_BINARIES)
110+
export(TARGETS libprotobuf-lite libprotobuf libprotoc protoc
111+
NAMESPACE protobuf::
112+
FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
113+
)
114+
else (protobuf_BUILD_PROTOC_BINARIES)
115+
export(TARGETS libprotobuf-lite libprotobuf
116+
NAMESPACE protobuf::
117+
FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
118+
)
119+
endif (protobuf_BUILD_PROTOC_BINARIES)
108120

109121
install(EXPORT protobuf-targets
110122
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"

0 commit comments

Comments
 (0)