While FetchContent happens during configuration, ExternalProject_Add defers the download and build process to the . This is the preferred method for "super-builds" or complex projects that have their own distinct build systems and shouldn't pollute your main project's configuration. file(DOWNLOAD) FetchContent ExternalProject Execution Time Configuration Configuration Best For Static Data / Assets Libraries / Subdirectories Independent Projects Complexity Extraction 4. Best Practices for Developers
: Ensures the server certificate is validated for https:// URLs. As of CMake 3.31, this is on by default. 2. The Modern Standard: FetchContent file download cmake
: It helps manage transitive dependencies, ensuring that multiple subprojects share the same version of a library like Eigen or GTest. 3. Alternative: ExternalProject_Add Best Practices for Developers : Ensures the server
: Use this to verify the file's integrity using algorithms like SHA256 . If the local file already matches the hash, CMake will skip the download to save time. The Modern Standard: FetchContent : It helps manage
: Captures the result of the operation into a list (e.g., 0;"No error" ), allowing you to handle errors gracefully .
The file(DOWNLOAD) command is the most direct way to fetch a file from a URL during the configuration phase. It is ideal for one-off assets that aren't necessarily C++ source code. Basic Syntax file(DOWNLOAD [OPTIONS]) Use code with caution. Key Options for Robust Downloads: