How can I get FetchContent to download to a specific location?

妖精的绣舞 提交于 2021-01-29 14:42:55

问题


Following the FetchContent documentation, e.g. using something like

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

The source code is cloned into ${CMAKE_BINARY_DIR}/_deps/gitache_package_libcwd_r-src/.

How can I make it put the source code elsewhere, like /opt/gitache/libcwd_r/src/gitache_package_libcwd_r (as it would be when I'd be using ExternalProject with a PREFIX of /opt/gitache/libcwd_r)?


回答1:


In case anyone stumbles on this question looking for an answer, I found that at least it is possible to replace the "${CMAKE_BINARY_DIR}/_deps" part by setting FETCHCONTENT_BASE_DIR before the call to FetchContent_Declare. I'm not sure if more fine tuned manipulation is possible or not. It seems possible, if you use the extended version of FetchContent_Populate, but using that has several drawbacks imho.

For example

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

will clone into /opt/gitache/libcwd_r/gitache_package_libcwd_r-src/ and use /opt/gitache/libcwd_r/gitache_package_libcwd_r-build as build directory.



来源:https://stackoverflow.com/questions/60981812/how-can-i-get-fetchcontent-to-download-to-a-specific-location

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!