如何在 Windows 上使用 cmake 构建 google protobuf 环境? [英] How to build google protobuf environment with cmake on windows?

查看:159
本文介绍了如何在 Windows 上使用 cmake 构建 google protobuf 环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循以下说明:

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 中,我使用:

In my program's CMakeLists.txt i use:

find_package(Protobuf REQUIRED)

但它告诉我:

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

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

I think I should set set the environment variable.

有没有有效的方法来做到这一点?

Is there a effective way to do this?

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)

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

Can these files set the environment variable? And how can I use them?

推荐答案

我更喜欢在我的项目的构建树中构建 3rd 方库作为静态库.

I prefer to build 3rd party libraries as static libs in the build tree of my project.

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

I have created a cmake library to help with this. protobuf is one of the first libraries I have supported. The documentation is sparse so either feel free to ask questions or just learn from the code in the file cmake/require_protobuf.cmake

库在这里:https://github.com/madmongo1/sanity

如果您愿意做出贡献,我将不胜感激.

If you feel like contributing, I'd be grateful.

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

You will see that the script performs 2 builds. One to build protoc on the build machine, the next to build the protobuf libraries for the target machine.

这篇关于如何在 Windows 上使用 cmake 构建 google protobuf 环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆