如何使用 cmake 在 windows 上编译 libgit2?

How to compile libgit2 on windows using cmake?

我正在尝试编译 libgit2 并按照 https://libgit2.github.com/docs/guides/build-and-link/ 上的说明进行操作,但到目前为止锁定。

谁能告诉我该怎么做?

这是我的命令行的结果:

-- Building for: Visual Studio 12 2013
-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE)
-- Could NOT find ZLIB (missing:  ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-- zlib was not found; using bundled 3rd-party sources.
-- LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.
CMake Error at d:/cmake/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE)
Call Stack (most recent call first):
  d:/cmake/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  d:/cmake/share/cmake-3.3/Modules/FindPythonInterp.cmake:162 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:594 (FIND_PACKAGE)


-- Configuring incomplete, errors occurred!
See also "D:/temp/gitlib/libgit2-master/build/CMakeFiles/CMakeOutput.log".
See also "D:/temp/gitlib/libgit2-master/build/CMakeFiles/CMakeError.log".

谢谢,

从 Paython.org 下载 Python 并安装它(即 d:\python)。然后打开你的 VS 命令行并输入 PATH D:\Python\Python35-32;d:\cmake\bin;%PATH%

一切就绪,转到您的 build 文件夹 运行 cmake .. 然后 cmake --build .

libgit2 使用 python(适用于该语言的版本 2 和 3)来构建测试。您可以安装 python 或要求 CMake 不构建测试。

IIRC CMake 会在您路径中不一定需要的几个标准位置进行查找 python,尽管它不会造成伤害。

如果您不想构建测试,您可以通过 -DBUILD_CLAR=OFF 这样它就不会费心寻找 python.