【问题标题】:How can I get FetchContent to download to a specific location?如何让 FetchContent 下载到特定位置?
【发布时间】:2020-04-02 19:52:06
【问题描述】:

遵循FetchContent 文档,例如使用类似的东西

FetchContent_Declare(
    gitache_package_libcwd_r
    GIT_REPOSITORY "https://github.com/CarloWood/libcwd.git"
    GIT_TAG "master"
)
FetchContent_MakeAvailable(
    gitache_package_libcwd_r
)

源代码克隆到${CMAKE_BINARY_DIR}/_deps/gitache_package_libcwd_r-src/

我怎样才能让它把源代码放在别处,比如/opt/gitache/libcwd_r/src/gitache_package_libcwd_r(就像我使用ExternalProjectPREFIX/opt/gitache/libcwd_r一样)?

【问题讨论】:

  • 您可以尝试为FetchContent_Declare设置SOURCE_DIR参数。此参数适用于ExternalProject_Add,因此它可能适用于FetchContent_Declare,这是它的包装器。

标签: cmake


【解决方案1】:

如果有人偶然发现这个问题寻找答案,我发现至少可以通过在调用FetchContent_Declare 之前设置FETCHCONTENT_BASE_DIR 来替换"${CMAKE_BINARY_DIR}/_deps" 部分。我不确定是否可以进行更精细的操作。如果您使用 FetchContent_Populate 的扩展版本,这似乎是可能的,但恕我直言,使用它有几个缺点。

例如

set(FETCHCONTENT_BASE_DIR "/opt/gitache/libcwd_r")
FetchContent_Declare(... etc (see question)

将克隆到/opt/gitache/libcwd_r/gitache_package_libcwd_r-src/ 并使用 /opt/gitache/libcwd_r/gitache_package_libcwd_r-build 作为构建目录。

【讨论】:

    猜你喜欢
    • 2022-10-19
    • 2018-02-16
    • 2020-01-20
    • 2019-06-25
    • 1970-01-01
    • 2011-09-27
    • 2010-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多