GitHub API with CMake
CMake can use the GitHub REST API to fetch the latest release download URL from GitHub in the form of JSON data. The API is useful to download the latest release of a GitHub project using CMake. The API used in this example specifically ignore pre-releases and draft releases. The example CMake code shows how to parse the JSON data to get the download URL.
CMake
file(DOWNLOAD …)
has HTTPHEADER
option that can be repeated to add multiple headers to the HTTP request.
In GitHubRelease.cmake linked above, a specific version of the GitHub API and format is used to get the latest release download URL.
Authentication parameters can also be passed if API limits are exceeded.
Don’t save/commit API credentials to a public repository!
file(DOWNLOAD ...
HTTPHEADER "Accept: application/vnd.github+json"
HTTPHEADER "X-GitHub-Api-Version: 2022-11-28"
)