我通过其他cmakelists.txt从github获取了Catch库,该库包含在主要库中:

cmake_minimum_required(VERSION 3.2)
project(MyProject)

add_subdirectory(ext/catch)
include_directories(${CATCH_INCLUDE_DIR} ${CXXOPTS_INCLUDE_DIR} src)
...

其中用于Catch的CmakeLists.txt是:
cmake_minimum_required(VERSION 2.8.8)
project(catch_builder CXX)
include(ExternalProject)
find_package(Git REQUIRED)

ExternalProject_Add(
    catch
    PREFIX ${CMAKE_CURRENT_SOURCE_DIR}
    GIT_REPOSITORY https://github.com/philsquared/Catch.git
    TIMEOUT 10
    UPDATE_COMMAND ${GIT_EXECUTABLE} pull
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
    LOG_DOWNLOAD ON
)

# Expose required variable (CATCH_INCLUDE_DIR) to parent scope
ExternalProject_Get_Property(catch source_dir)
set(CATCH_INCLUDE_DIR ${source_dir}/include CACHE INTERNAL "Path to include folder for Catch")
message(${CATCH_INCLUDE_DIR})

但是,主项目的构建要比从Git检索Catch早开始。
如何解决这个问题?我的cmake脚本出了什么问题?

最佳答案

我认为我有同样的问题,我所做的是:

  • 将AddCatch.cmake(捕获的cmakelist)放入CMAKE_MODULE_PATHe.g.: set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
  • 删除以下行:project(catch_builder CXX)
  • add_subdirectory(ext/catch)替换include(AddCatch)

  • 它应该工作得很好;)

    09-13 00:27