Carlo Wood
Carlo Wood

Reputation: 6801

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

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)?

Upvotes: 7

Views: 8337

Answers (2)

gnikit
gnikit

Reputation: 1291

You can use the options DOWNLOAD_DIR, SOURCE_DIR, TMP_DIR, etc. as you would with ExternalProject_Add()

Cmake FetchContent_Declare Documentation:

The <contentOptions> can be any of the download, update or patch options that the ExternalProject_Add() command understands. The configure, build, install and test steps are explicitly disabled and therefore options related to them will be ignored. The SOURCE_SUBDIR option is an exception, see FetchContent_MakeAvailable() for details on how that affects behavior.

Upvotes: 5

Carlo Wood
Carlo Wood

Reputation: 6801

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.

Upvotes: 6

Related Questions