问题
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