Search code examples
c++cmakevisual-studio-2019glew

Compile GLEW with CMake and Visual Studio 2019?


I tried to compile (build) GLEW source code with CMake and Visual Studio 2019 for get binaries. In directory (disk) C:\ I created folder GL and inside it, placed unzipped glew-2.1.0. In C:\GL\, I created the folder build. Because I found the file "CMakeLists.txt" in 3 folders,

  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

I tested all 3 paths in "Browse Source..." text box in CMake. In "Browse Build..." text box I pasted C:/GL/build. In all 3 tests CMake responded:

"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."

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


Solution

  • If you change the top-level source directory on which CMake runs, you should first delete your CMake cache (File > Delete Cache in CMake GUI), and run CMake from scratch to avoid these errors.

    Have you tried the CMake instructions on the GLEW Github here? Try running these commands from the command line:

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

    Though this deviates from the typical out-of-source build CMake idiom, this is how GLEW intends the build system be created. So on your system:

    • Source directory: C:/GL/glew-2.1.0/build/cmake
    • Build directory: C:/GL/glew-2.1.0/build

    Note, the GLEW build instructions warn about the use of CMake for building this repo:

    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.

    Thus, you may have better luck following the typical Windows build approaches recommended here.