编译CMake 3.10.2源码时因缺失gl/gl.h配置失败,如何取消依赖?
gl/gl.h Hey there, let's work through this issue with compiling CMake 3.10.2. The gl/gl.h error pops up because CMake tries to build its Qt-based GUI tools (like cmake-gui) which require OpenGL dependencies. Since you don't have a GL environment set up and likely just need the core command-line CMake functionality, you can disable these GUI components entirely to skip the GL dependency.
Here's how to do it step by step:
Prepare your build directory (always a good practice to keep your source tree clean):
mkdir build && cd buildRun CMake configuration with GUI-disabling flags
Use your existing older CMake version to configure the build, adding these critical flags to cut out GL-dependent components:cmake ../path/to/cmake-3.10.2-source \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_QtDialog=OFF \ -DCMAKE_DISABLE_FIND_PACKAGE_OpenGL=ON \ -DBUILD_CursesDialog=OFF
Let's break down what each flag does:
-DBUILD_QtDialog=OFF: This directly disables the Qt-basedcmake-guitool, which is the main source of the OpenGL dependency.-DCMAKE_DISABLE_FIND_PACKAGE_OpenGL=ON: Forces CMake to skip all attempts to locate OpenGL headers or libraries, eliminating any related checks entirely.-DBUILD_CursesDialog=OFF: Optional, but disables the ncurses-based terminal GUI if you don't need it (this doesn't rely on GL, but removing it keeps the build focused on core command-line tools).-DCMAKE_BUILD_TYPE=Release: Compiles optimized, release-ready binaries instead of debug builds to save resources.
- Compile and install
Once the configuration completes without errors, proceed to compile and install the new CMake version:make -j$(nproc) sudo make install
This setup will only build the core command-line tools (cmake, ctest, cpack) and skip all GUI components that require OpenGL. Since you're using your existing CMake to bootstrap the new version, you don't have to worry about missing additional build tools beyond what you already have.
内容的提问来源于stack exchange,提问作者KillerSnail

