问题
I am following the instructions from:
https://github.com/google/protobuf/tree/master/cmake
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=../../../../install/protobuf ../..
nmake install
In my program's CMakeLists.txt i use:
find_package(Protobuf REQUIRED)
But it tells me:
-- 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?
in protobuf-master/cmake/install.cmake
i can see this:
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?
回答1:
I prefer to build 3rd party libraries as static libs in the build tree of my project.
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
library is here: https://github.com/madmongo1/sanity
If you feel like contributing, I'd be grateful.
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.
来源:https://stackoverflow.com/questions/38408486/how-to-build-google-protobuf-environment-with-cmake-on-windows