ExternalProject runs during the make or ninja step. This is useful for large archives that you don't want to download every time you re-configure your project. 3. Manual Download and Extraction
Since CMake 3.11, the FetchContent module is the standard way to download files. It populates dependencies at , meaning the files are ready before you even start compiling. To download a TAR file, add this to your CMakeLists.txt :
Here is a comprehensive guide on how to use CMake to download, verify, and extract TAR archives automatically during your build process. 1. The Modern Approach: FetchContent cmake tar download
If you are working with a legacy project or need to download the file at (rather than configure time), use the ExternalProject module.
⚡ If you delete your build folder frequently, CMake will re-download the TAR file. Set the FETCHCONTENT_BASE_DIR environment variable to a global path to share downloads across multiple projects. If you’d like, I can help you: Write a script to verify the SHA256 hash of your file Configure a private repository login for downloads Set up conditional downloads based on the Operating System ExternalProject runs during the make or ninja step
Ensures the file hasn't been tampered with or corrupted.
execute_process( COMMAND ${CMAKE_COMMAND} -E tar xzf ${CMAKE_BINARY_DIR}/data.tar.gz WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/extracted_data ) Use code with caution. 4. Essential Tips for TAR Downloads Manual Download and Extraction Since CMake 3
CMake automatically detects the .tar.gz , .tar.xz , or .zip extension and extracts it. 2. The Classic Approach: ExternalProject_Add