New user - Can't get file(ARCHIVE_EXTRACT ...) to work


I am a new user of CMake (literally day one) and everything has gone swimmingly so far except for one thing - I am getting an error when use file(ARCHIVE_EXTRACT). I am guessing it is something pretty obvious, but if someone could point me in the right direction I would be most grateful.

I can demo the problem very simply with the following CMakeLists.txt: (Note I have really stripped this down to the bare minimum!)

cmake_minimum_required(VERSION 3.25)

project(arctest VERSION 1.0 DESCRIPTION “Archive Extract test” LANGUAGES C CXX)

file(ARCHIVE_EXTRACT INPUT “test.tar.gz”)

The “test.tar.gz” file is a simple archive with a couple of text files in it, created using “tar -czvf …”

When I run “cmake -B build” I get the following error:

CMake Error: Problem with archive_read_open_file(): Failed to open ‘test.tar.gz’

CMake Error at CMakeLists.txt:3 (file):

file failed to extract: test.tar.gz

However, if I change line 3 of the CMakeLists file to


it completes fine - listing the files in the archive.

BTW the system I am running on is fully updated Ubuntu and CMake 3.28.3

Best regards

LIST_ONLY doesn’t change the working directory while extraction does (to the DESTINATION). This causes the relative path to work for LIST_ONLY but fail for the extraction case. Use an absolute path to the INPUT file. I’ve filed an MR to update documentation here:

Many thanks for the explanation - I knew it must be a simple ‘newbie’ thing!