FetchContent cannot download single files that are not archives
So when I use FetchContent to download single-header files it failed because archive_read_open_file()
doesn't recognize the archive format. Here is a MWE:
cmake_minimum_required(VERSION 3.11)
project(fetchcontent-test)
include(FetchContent)
FetchContent_Declare(
tinyobjloader
URL "https://github.com/tinyobjloader/tinyobjloader/releases/download/v1.0.6/tiny_obj_loader.h"
)
FetchContent_GetProperties(tinyobjloader)
if(tinyobjloader_POPULATED)
return()
endif()
FetchContent_Populate(tinyobjloader)
add_library(tinyobjloader INTERFACE)
target_include_directories(tinyobjloader INTERFACE ${tinyobjloader_SOURCE_DIR})
As of CMake 3.17.0 I get the following error message:
-- The C compiler identification is AppleClang 11.0.3.11030032
-- The CXX compiler identification is AppleClang 11.0.3.11030032
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Scanning dependencies of target tinyobjloader-populate
[ 11%] Creating directories for 'tinyobjloader-populate'
[ 22%] Performing download step (download, verify and extract) for 'tinyobjloader-populate'
-- Downloading...
dst='/Users/jedumas/Downloads/cmake-mve/build/_deps/tinyobjloader-subbuild/tinyobjloader-populate-prefix/src/archive.tar'
timeout='none'
-- Using src='https://github.com/tinyobjloader/tinyobjloader/releases/download/v1.0.6/tiny_obj_loader.h'
-- [download 31% complete]
-- [download 100% complete]
-- [download 0% complete]
-- [download 27% complete]
-- [download 28% complete]
-- [download 55% complete]
-- [download 56% complete]
-- [download 83% complete]
-- [download 85% complete]
-- [download 100% complete]
* Closing connection 0
* Closing connection 1
-- Downloading... done
-- extracting...
src='/Users/jedumas/Downloads/cmake-mve/build/_deps/tinyobjloader-subbuild/tinyobjloader-populate-prefix/src/archive.tar'
dst='/Users/jedumas/Downloads/cmake-mve/build/_deps/tinyobjloader-src'
-- extracting... [tar xf]
CMake Error: Problem with archive_read_open_file(): Unrecognized archive format
CMake Error: Problem extracting tar: /Users/jedumas/Downloads/cmake-mve/build/_deps/tinyobjloader-subbuild/tinyobjloader-populate-prefix/src/archive.tar
-- extracting... [error clean up]
CMake Error at tinyobjloader-subbuild/tinyobjloader-populate-prefix/src/tinyobjloader-populate-stamp/extract-tinyobjloader-populate.cmake:33 (message):
error: extract of
'/Users/jedumas/Downloads/cmake-mve/build/_deps/tinyobjloader-subbuild/tinyobjloader-populate-prefix/src/archive.tar'
failed
make[2]: *** [tinyobjloader-populate-prefix/src/tinyobjloader-populate-stamp/tinyobjloader-populate-download] Error 1
make[1]: *** [CMakeFiles/tinyobjloader-populate.dir/all] Error 2
make: *** [all] Error 2
CMake Error at /usr/local/Cellar/cmake/3.17.0_1/share/cmake/Modules/FetchContent.cmake:912 (message):
Build step for tinyobjloader failed: 2
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.17.0_1/share/cmake/Modules/FetchContent.cmake:1003 (__FetchContent_directPopulate)
CMakeLists.txt:14 (FetchContent_Populate)
-- Configuring incomplete, errors occurred!
See also "/Users/jedumas/Downloads/cmake-mve/build/CMakeFiles/CMakeOutput.log".
I know there is an option DOWNLOAD_NO_EXTRACT
to force CMake not to extract the content, but 1) I think one shouldn't have to use it, and 2) there is no way to properly retrieve where the downloaded file is located (there is no foo_DOWNLOADED_FILE
property available for the FetchContent project, seems it's only available for ExternalProject_Add).