Make it possible to configure a CMake build with the slint-compiler to be downloaded at app configure time

This commit is contained in:
Simon Hausmann 2024-08-28 16:03:14 +02:00 committed by Simon Hausmann
parent b428ca1297
commit 90b2058e49
3 changed files with 42 additions and 4 deletions

View file

@ -14,8 +14,41 @@ endif()
add_library(@slint_cpp_impl@ @cmake_lib_type@ IMPORTED)
set_target_properties(@slint_cpp_impl@ PROPERTIES @SLINT_LIB_PROPERTIES@)
set(SLINT_COMPILER @SLINT_COMPILER@ CACHE FILEPATH "Path to the slint-compiler executable")
function(_slint_download_compiler_and_cache)
set(SLINT_GITHUB_RELEASE @SLINT_VERSION@ CACHE STRING "GitHub Release to use for Slint Binary Artifact Downloads")
if (CMAKE_HOST_WIN32)
set(compiler_exe_suffix ".exe")
set(platform_suffix "windows")
else()
set(platform_suffix "${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
set(prebuilt_archive_filename "slint-compiler-${platform_suffix}.tar.gz")
set(download_url "https://github.com/slint-ui/slint/releases/download/${SLINT_GITHUB_RELEASE}/${prebuilt_archive_filename}")
set(download_directory "${CMAKE_BINARY_DIR}/slint-prebuilt")
message(STATUS "Downloading pre-built Slint compiler binary from ${download_url}")
file(DOWNLOAD "${download_url}" "${download_directory}/${prebuilt_archive_filename}" STATUS download_status)
list(GET download_status 0 download_code)
if (NOT download_code EQUAL 0)
list(GET download_status 1 download_message)
message(FATAL_ERROR "Download of Slint compiler binary package failed: ${download_message}")
else()
file(ARCHIVE_EXTRACT INPUT "${download_directory}/${prebuilt_archive_filename}" DESTINATION "${download_directory}")
file(REMOVE "${download_directory}/${prebuilt_archive_filename}")
set(SLINT_COMPILER "${download_directory}/slint-compiler${compiler_exe_suffix}")
set(SLINT_COMPILER "${SLINT_COMPILER}" CACHE STRING "Path to the slint-compiler executable" FORCE)
set(SLINT_COMPILER "${SLINT_COMPILER}" PARENT_SCOPE)
endif()
endfunction()
set(SLINT_COMPILER @SLINT_COMPILER@ CACHE STRING "Path to the slint-compiler executable")
if (SLINT_COMPILER)
if (SLINT_COMPILER STREQUAL "download")
_slint_download_compiler_and_cache(_)
endif()
add_executable(Slint::slint-compiler IMPORTED GLOBAL)
set_target_properties(Slint::slint-compiler PROPERTIES IMPORTED_LOCATION ${SLINT_COMPILER})
include("${CMAKE_CURRENT_LIST_DIR}/SlintMacro.cmake")