【发布时间】:2018-08-26 20:56:03
【问题描述】:
我正在编写我的项目的 CMakeLists.txt 文件。我的项目依赖于外部依赖,GLFW,幸运的是 GLFW 也使用 CMake 构建系统。我正在使用 find_package() 和 git 子模块来处理依赖项管理,目前这就是我的 CMakeLists.txt 文件的样子:
# CMake version
cmake_minimum_required(VERSION 3.0)
# project name
project(CHIP-8)
# dependency management
find_package(OpenGL REQUIRED)
find_package(glfw)
if(NOT glfw)
message("Unable to locate glfw.")
message("Cloning the repository.")
execute_process(
COMMAND
git submodule update --init -- libs
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
)
message("Building glfw.")
add_subdirectory(libs/glfw)
endif()
根据我对 CMake 的有限理解,命令 add_subdirectory(libs/glfw) 在最近克隆的 glfw 子模块上运行 CMake。问题是许多不必要的功能是 GLFW 的默认构建的一部分,例如示例、单元测试和文档。
documentation for compiling GLFW 列出了用于禁用这些功能 GLFW_BUILD_EXAMPLES、GLFW_BUILD_TESTS 和 GLFW_BUILD_DOCS 的 CMake 选项。
我有两个问题,第一个是如何指定这些选项,第二个是我为 find_package 准确传递的参数(我确实在我的系统上安装了 GLFW,但每次构建它时仍然尝试克隆和构建存储库)。
【问题讨论】: