Skip to content

Commit

Permalink
Fix the way we find protobuf library (onnx#539)
Browse files Browse the repository at this point in the history
* Fix the way we find protobuf library

* Review comments

* Fix

* indent

* Fix build

* Reset changes on setup.py
  • Loading branch information
Yinghai Lu authored and bddppq committed Feb 21, 2018
1 parent fe54d88 commit c894dd7
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,44 @@ if (WIN32)
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /WX")
endif()
add_subdirectory(third_party/pybind11)
FIND_PACKAGE(Protobuf REQUIRED)

# Customized version of find Protobuf. We need to avoid situations mentioned
# in https://github.com/caffe2/caffe2/blob/b7d983f255ef5496474f1ea188edb5e0ac442761/cmake/ProtoBuf.cmake#L82-L92
# The following section is stolen from cmake/ProtoBuf.cmake in Caffe2
find_program(PROTOBUF_PROTOC_EXECUTABLE
NAMES protoc
DOC "The Google Protocol Buffers Compiler")

# Only if protoc was found, seed the include directories and libraries.
# We assume that protoc is installed at PREFIX/bin.
# We use get_filename_component to resolve PREFIX.
if(PROTOBUF_PROTOC_EXECUTABLE)
get_filename_component(
_PROTOBUF_INSTALL_PREFIX
${PROTOBUF_PROTOC_EXECUTABLE}
DIRECTORY)
get_filename_component(
_PROTOBUF_INSTALL_PREFIX
${_PROTOBUF_INSTALL_PREFIX}/..
REALPATH)
find_library(PROTOBUF_LIBRARY
NAMES protobuf
PATHS ${_PROTOBUF_INSTALL_PREFIX}/lib
NO_DEFAULT_PATH)
find_library(PROTOBUF_PROTOC_LIBRARY
NAMES protoc
PATHS ${_PROTOBUF_INSTALL_PREFIX}/lib
NO_DEFAULT_PATH)
find_library(PROTOBUF_LITE_LIBRARY
NAMES protobuf-lite
PATHS ${_PROTOBUF_INSTALL_PREFIX}/lib
NO_DEFAULT_PATH)
find_path(PROTOBUF_INCLUDE_DIR
google/protobuf/service.h
PATHS ${_PROTOBUF_INSTALL_PREFIX}/include
NO_DEFAULT_PATH)
find_package(Protobuf REQUIRED)
endif()

# Build the libraries with -fPIC
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand Down

0 comments on commit c894dd7

Please sign in to comment.