使用 CMake 和 Visual Studio 2019 编译 GLEW?

Compile GLEW with CMake and Visual Studio 2019?

我尝试使用 CMake 和 Visual Studio 2019 编译(构建)GLEW 源代码以获取二进制文件。在目录(磁盘)C:\ 中,我创建了文件夹 GL 并在其中解压缩 glew-2.1.0。在 C:\GL\ 中,我创建了文件夹 build。因为我在3个文件夹中找到了文件"CMakeLists.txt",

  1. C:\GL\glew-2.1.0\build\conan\test_package
  2. C:\GL\glew-2.1.0\build\cmake
  3. C:\GL\glew-2.1.0\build\cmake\testbuild

我在 CMake 的 "Browse Source..." 文本框中测试了所有 3 个路径。在 "Browse Build..." 文本框中我粘贴了 C:/GL/build。 在所有 3 个测试中,CMake 都响应:

"CMake Error: The source 
"C:/GL/glew-2.1.0/build/cmake/CMakeLists.txt" 
does not match the source
"C:/GL/glew-2.1.0/build/cmake/testbuild/CMakeLists.txt"
used to generate cache.  Re-run cmake with a different source directory."

即"file CMakeLists.txt in 2nd path does not match file of same name in 3rd path".

如果您更改 CMake 运行 所在的顶级源目录,您应该首先 删除 您的 CMake 缓存(文件 > 在 CMake GUI 中删除缓存),并从头开始 运行 CMake 以避免这些错误。

您是否在 GLEW Github here 上尝试过 CMake 指令?尝试 运行 从命令行执行这些命令:

> cd C:/GL/glew-2.1.0/build
> cmake ./cmake

尽管这偏离了典型的源外构建 CMake 习惯用法,但这正是 GLEW 打算创建构建系统的方式。所以在你的系统上:

  • 源码目录:C:/GL/glew-2.1.0/build/cmake
  • 构建目录:C:/GL/glew-2.1.0/build

请注意,GLEW 构建说明警告使用 CMake 构建此存储库:

The cmake build is mostly contributer maintained. Due to the multitude of use cases this is maintained on a best effort basis. Pull requests are welcome.

因此,按照推荐的 here.

典型 Windows 构建方法,您可能会有更好的运气

根据squareskittles先生的回答-评论我对他的回答的评论,我已经测试成功,正确的答案是存放二进制文件的文件夹应该是C:/GL/glew-2.1.0/build或任何您在 glew-2.1.0 中创建的文件夹。虽然这是 glew 的特殊性。使用 GLFW,您可以在其外部创建可容纳的二进制文件文件夹。然而,根据 Mr.squareskittles 在他的答案中的编辑,我已经测试成功,如果你删除 Cashe(在 CMake GUI 中,单击文件 > 删除 Cashe)你可以在 glew-2.1.0 之外创建容纳二进制文件文件夹。问候。