Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: examples: cpp: CMake Standalone auto fetch latest available tag [todo] #68

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion examples/cpp/CMakeLists_Standalone.txt
Expand Up @@ -2,9 +2,19 @@ cmake_minimum_required(VERSION 3.10)
project(example)

include(ExternalProject)
include(FetchContent)

# Function to fetch latest release version from GitHub
function(fetch_latest_release owner_name repo_name out_variable)
file(DOWNLOAD "https://api.github.com/repos/${owner_name}/${repo_name}/releases/latest" "${CMAKE_BINARY_DIR}/latest_release.json" TLS_VERIFY ON)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use CMAKE_BUILD_DIR over CMAKE_BINARY_DIR, otherwise the artifact folder will also contain the json file as well. it's a temporary file, it should exist in a temporary folder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't use CMAKE_BUILD_DIR,
tried CMAKE_CACHEFILE_DIR, but to make it works you need to run twice (something related to permissions)

was unable to find CMAKE_BUILD_DIR
https://cmake.org/cmake/help/latest/search.html?q=CMAKE_BUILD_

file(READ "${CMAKE_BINARY_DIR}/latest_release.json" latest_release_json)
string(REGEX MATCH "\"tag_name\": \"([^\"]+)\"" _ ${latest_release_json})
set(${out_variable} "${CMAKE_MATCH_1}" PARENT_SCOPE)
endfunction()

if(NOT DEFINED NAVIGATOR_VERSION)
set(NAVIGATOR_VERSION "0.0.1")
fetch_latest_release("bluerobotics" "navigator-lib" NAVIGATOR_VERSION)
message(STATUS "Latest Navigator lib version: ${NAVIGATOR_VERSION}")
endif()

set(ZIP_URL "https://github.com/bluerobotics/navigator-lib/releases/download/${NAVIGATOR_VERSION}/cpp.zip")
Expand Down