如何在 windows 上使用 cmake 构建 google protobuf 环境?

How to build google protobuf environment with cmake on windows?

我正在按照以下说明进行操作:

https://github.com/google/protobuf/tree/master/cmake

cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=../../../../install/protobuf ../..

nmake install

在我的程序 CMakeLists.txt 中,我使用:

find_package(Protobuf REQUIRED)

但它告诉我:

-- Could NOT find Protobuf (missing:  Protobuf_LIBRARIES Protobuf_INCLUDE_DIR)

我想我应该设置环境变量。

有什么有效的方法吗?

protobuf-master/cmake/install.cmake 我可以看到这个:

configure_file(protobuf-config.cmake.in
  ${CMAKE_INSTALL_CMAKEDIR}/protobuf-config.cmake @ONLY)
configure_file(protobuf-config-version.cmake.in
  ${CMAKE_INSTALL_CMAKEDIR}/protobuf-config-version.cmake @ONLY)
configure_file(protobuf-module.cmake.in
  ${CMAKE_INSTALL_CMAKEDIR}/protobuf-module.cmake @ONLY)
configure_file(protobuf-options.cmake
  ${CMAKE_INSTALL_CMAKEDIR}/protobuf-options.cmake @ONLY)

这些文件可以设置环境变量吗?我该如何使用它们?

我更喜欢在项目的构建树中将第 3 方库构建为静态库。

我创建了一个 cmake 库来帮助解决这个问题。 protobuf 是我支持的首批库之一。文档很少,所以请随意提问或从文件中的代码学习 cmake/require_protobuf.cmake

图书馆在这里:https://github.com/madmongo1/sanity

如果你愿意贡献,我将不胜感激。

您将看到该脚本执行了 2 次构建。一个用于在构建机器上构建 protoc,下一个用于为目标机器构建 protobuf 库。