Skip to content

Commit 669304f

Browse files
authored
protobuf (#12935)
1 parent 5df6581 commit 669304f

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

cmake/external/protobuf.cmake

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414

1515
INCLUDE(ExternalProject)
1616
# Always invoke `FIND_PACKAGE(Protobuf)` for importing function protobuf_generate_cpp
17+
IF(NOT WIN32)
1718
FIND_PACKAGE(Protobuf QUIET)
19+
ENDIF(NOT WIN32)
1820
macro(UNSET_VAR VAR_NAME)
1921
UNSET(${VAR_NAME} CACHE)
2022
UNSET(${VAR_NAME})
2123
endmacro()
24+
2225
UNSET_VAR(PROTOBUF_INCLUDE_DIR)
2326
UNSET_VAR(PROTOBUF_FOUND)
2427
UNSET_VAR(PROTOBUF_PROTOC_EXECUTABLE)
@@ -94,12 +97,14 @@ macro(PROMPT_PROTOBUF_LIB)
9497
SET(protobuf_DEPS ${ARGN})
9598

9699
MESSAGE(STATUS "Protobuf protoc executable: ${PROTOBUF_PROTOC_EXECUTABLE}")
100+
MESSAGE(STATUS "Protobuf-lite library: ${PROTOBUF_LITE_LIBRARY}")
97101
MESSAGE(STATUS "Protobuf library: ${PROTOBUF_LIBRARY}")
102+
MESSAGE(STATUS "Protoc library: ${PROTOBUF_PROTOC_LIBRARY}")
98103
MESSAGE(STATUS "Protobuf version: ${PROTOBUF_VERSION}")
99104
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
100105

101106
# Assuming that all the protobuf libraries are of the same type.
102-
IF(${PROTOBUF_LIBRARY} MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$")
107+
IF(${PROTOBUF_LIBRARY} MATCHES ${CMAKE_STATIC_LIBRARY_SUFFIX})
103108
SET(protobuf_LIBTYPE STATIC)
104109
ELSEIF(${PROTOBUF_LIBRARY} MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$")
105110
SET(protobuf_LIBTYPE SHARED)
@@ -137,18 +142,25 @@ macro(SET_PROTOBUF_VERSION)
137142
endmacro()
138143

139144
set(PROTOBUF_ROOT "" CACHE PATH "Folder contains protobuf")
145+
IF (WIN32)
146+
SET(PROTOBUF_ROOT ${THIRD_PARTY_PATH}/install/protobuf)
147+
MESSAGE(WARNING, "In windows, protobuf only support msvc build, please build it manually and put it at " ${PROTOBUF_ROOT})
148+
ENDIF(WIN32)
149+
140150
if (NOT "${PROTOBUF_ROOT}" STREQUAL "")
151+
141152
find_path(PROTOBUF_INCLUDE_DIR google/protobuf/message.h PATHS ${PROTOBUF_ROOT}/include NO_DEFAULT_PATH)
142-
find_library(PROTOBUF_LIBRARY protobuf PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
143-
find_library(PROTOBUF_LITE_LIBRARY protobuf-lite PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
144-
find_library(PROTOBUF_PROTOC_LIBRARY protoc PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
153+
find_library(PROTOBUF_LIBRARY protobuf libprotobuf.lib PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
154+
find_library(PROTOBUF_LITE_LIBRARY protobuf-lite libprotobuf-lite.lib PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
155+
find_library(PROTOBUF_PROTOC_LIBRARY protoc libprotoc.lib PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
145156
find_program(PROTOBUF_PROTOC_EXECUTABLE protoc PATHS ${PROTOBUF_ROOT}/bin NO_DEFAULT_PATH)
146157
if (PROTOBUF_INCLUDE_DIR AND PROTOBUF_LIBRARY AND PROTOBUF_LITE_LIBRARY AND PROTOBUF_PROTOC_LIBRARY AND PROTOBUF_PROTOC_EXECUTABLE)
147158
message(STATUS "Using custom protobuf library in ${PROTOBUF_ROOT}.")
159+
SET(PROTOBUF_FOUND true)
148160
SET_PROTOBUF_VERSION()
149161
PROMPT_PROTOBUF_LIB()
150162
else()
151-
message(WARNING "Cannot find protobuf library in ${PROTOBUF_ROOT}.")
163+
message(WARNING "Cannot find protobuf library in ${PROTOBUF_ROOT}")
152164
endif()
153165
endif()
154166

@@ -239,6 +251,7 @@ IF(CMAKE_CROSSCOMPILING)
239251
CACHE FILEPATH "protobuf executable." FORCE)
240252
ENDIF()
241253

254+
242255
IF(NOT PROTOBUF_FOUND)
243256
build_protobuf(extern_protobuf FALSE)
244257

0 commit comments

Comments
 (0)