【发布时间】:2020-01-13 17:31:41
【问题描述】:
我在我的项目中导入 glfw 作为子模块,遵循here 描述的模式
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
## Check for GLFW
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/glfw/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
else()
add_subdirectory(glfw EXCLUDE_FROM_ALL)
endif()
如您所见,我将项目包含在add_subdirectory() 中。这有效地添加了 glfw 目标,我可以将它与我的链接,但它还包括所有 glfw 目标(文档、示例......)。
当然,我不知道我以错误的方式包含项目。
有没有办法从子模块中包含并排除其他目标?
显然EXCLUDE_FROM_ALL 不起作用。
【问题讨论】: