CMake从源代码中找到protobuf

时间:2018-05-08 17:28:42

标签: cmake protocol-buffers

我正在尝试构建一个依赖于源代码编译的Google Protocol Buffers的项目。我的项目应该是平台独立的,也应该支持交叉编译,这就是我更喜欢使用本地构建的protobuf的原因。但是我不希望将整个库作为子项目包含在内,因为构建它需要花费太多。

我简化的CMakeLists.txt是:

cmake_minimum_required(VERSION 3.5)
project(sample-protobuf)

# find a boost install with the libraries filesystem and system
find_package(Protobuf REQUIRED)

set(SOURCES
    main.cpp
)

add_executable(sample
    ${SOURCES}
)
target_link_libraries(sample
    PRIVATE
        protobuf::libprotobuf
)

我在Linux上调用CMake:

cmake -DCMAKE_PREFIX_PATH=/path/to/built/protobuf/ ..

但它找不到库,我收到以下消息:

  Could not find a package configuration file provided by "Protobuf" with any
  of the following names:

    ProtobufConfig.cmake
    protobuf-config.cmake

  Add the installation prefix of "Protobuf" to CMAKE_PREFIX_PATH or set
  "Protobuf_DIR" to a directory containing one of the above files.  If
  "Protobuf" provides a separate development package or SDK, be sure it has
  been installed.

在Windows上,此过程有效。 我使用建议的方法在Linux上构建了库,这不是使用CMake而是使用autotools。

我应该采取哪些不同的方式?

1 个答案:

答案 0 :(得分:0)

cd protobuf/cmake
mkdir build
cd build
cmake....
make...
sudo make install
相关问题