cmake FetchContent 未在 docker 中使用 DOWNLOAD_NO_EXTRACT 下载
cmake FetchContent not downloading with DOWNLOAD_NO_EXTRACT in docker
我的 CMakeLists.txt
使用 FetchContent
下载 JAR 文件,它在 Ubuntu 18.04 WSL 中按预期工作。 运行 docker 中的 cmake,但是不下载文件。
我指定 DOWNLOAD_NO_EXTRACT TRUE
,因为它以其他方式提取 JAR 文件。没有它,它会提取 docker.
中的 JAR 内容
这是一个最小的复制。
CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 3.7 FATAL_ERROR)
include (FetchContent)
FetchContent_Declare(
AntlrJar
URL https://www.antlr.org/download/antlr-4.10.1-complete.jar
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/dependencies
DOWNLOAD_NO_EXTRACT TRUE
)
FetchContent_GetProperties(AntlrJar)
FetchContent_Populate(AntlrJar)
Dockerfile:
FROM ubuntu:20.04
WORKDIR /src
RUN apt update
RUN apt install -y cmake g++
COPY CMakeLists.txt /src
然后我在 /src
中执行 cmake .
并注意到“依赖项”为空。
FetchContent_Declare
(和 ExternalProject_Add
)的参数 SOURCE_DIR
影响下载文件的解压:
SOURCE_DIR <dir>
Source directory into which downloaded contents will be unpacked, or for non-URL download methods, the directory in which the repository should be checked out, cloned, etc.
(引用自 documentation)。
要指定下载文件的目录存储,请使用DOWNLOAD_DIR
参数:
DOWNLOAD_DIR <dir>
Directory in which to store downloaded files before unpacking them. This directory is only used by the URL download method, all other download methods use SOURCE_DIR directly instead.
FetchContent_Declare(
AntlrJar
URL https://www.antlr.org/download/antlr-4.10.1-complete.jar
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/dependencies
DOWNLOAD_NO_EXTRACT TRUE
)
我的 CMakeLists.txt
使用 FetchContent
下载 JAR 文件,它在 Ubuntu 18.04 WSL 中按预期工作。 运行 docker 中的 cmake,但是不下载文件。
我指定 DOWNLOAD_NO_EXTRACT TRUE
,因为它以其他方式提取 JAR 文件。没有它,它会提取 docker.
这是一个最小的复制。
CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 3.7 FATAL_ERROR)
include (FetchContent)
FetchContent_Declare(
AntlrJar
URL https://www.antlr.org/download/antlr-4.10.1-complete.jar
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/dependencies
DOWNLOAD_NO_EXTRACT TRUE
)
FetchContent_GetProperties(AntlrJar)
FetchContent_Populate(AntlrJar)
Dockerfile:
FROM ubuntu:20.04
WORKDIR /src
RUN apt update
RUN apt install -y cmake g++
COPY CMakeLists.txt /src
然后我在 /src
中执行 cmake .
并注意到“依赖项”为空。
FetchContent_Declare
(和 ExternalProject_Add
)的参数 SOURCE_DIR
影响下载文件的解压:
SOURCE_DIR <dir>
Source directory into which downloaded contents will be unpacked, or for non-URL download methods, the directory in which the repository should be checked out, cloned, etc.
(引用自 documentation)。
要指定下载文件的目录存储,请使用DOWNLOAD_DIR
参数:
DOWNLOAD_DIR <dir>
Directory in which to store downloaded files before unpacking them. This directory is only used by the URL download method, all other download methods use SOURCE_DIR directly instead.
FetchContent_Declare(
AntlrJar
URL https://www.antlr.org/download/antlr-4.10.1-complete.jar
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/dependencies
DOWNLOAD_NO_EXTRACT TRUE
)