Skip to content

Commit

Permalink
Make it possible to configure a CMake build with the slint-compiler t…
Browse files Browse the repository at this point in the history
…o be downloaded at app configure time
  • Loading branch information
tronical committed Aug 28, 2024
1 parent 45c639a commit 3133b4c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/upgrade_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
# Update the version in CmakeLists.txt
sed -i 's/ VERSION [0-9]*\.[0-9]*\.[0-9]*$/ VERSION ${{ github.event.inputs.new_version }}/' api/cpp/CMakeLists.txt
sed -i 's/SLINT_VERSION [0-9]*\.[0-9]*\.[0-9]*$/SLINT_VERSION ${{ github.event.inputs.new_version }}/' api/cpp/CMakeLists.txt
sed -i "s/(CPACK_PACKAGE_VERSION_MAJOR [0-9]*)/(CPACK_PACKAGE_VERSION_MAJOR `echo ${{ github.event.inputs.new_version }} | sed "s/\([0-9]*\)\.\([0-9]*\).\([0-9]*\)/\1/"`)/" api/cpp/CMakeLists.txt
sed -i "s/(CPACK_PACKAGE_VERSION_MINOR [0-9]*)/(CPACK_PACKAGE_VERSION_MINOR `echo ${{ github.event.inputs.new_version }} | sed "s/\([0-9]*\)\.\([0-9]*\).\([0-9]*\)/\2/"`)/" api/cpp/CMakeLists.txt
sed -i "s/(CPACK_PACKAGE_VERSION_PATCH [0-9]*)/(CPACK_PACKAGE_VERSION_PATCH `echo ${{ github.event.inputs.new_version }} | sed "s/\([0-9]*\)\.\([0-9]*\).\([0-9]*\)/\3/"`)/" api/cpp/CMakeLists.txt
Expand Down
10 changes: 7 additions & 3 deletions api/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ add_feature_info(SLINT_FEATURE_COMPILER SLINT_FEATURE_COMPILER "Enable support f
option(SLINT_BUILD_RUNTIME "Actually build the Slint runtime libraries (Disable that to only build the compiler)" ON)
add_feature_info(SLINT_BUILD_RUNTIME SLINT_BUILD_RUNTIME "Actually build the Slint runtime libraries (Disable that to only build the compiler)")

set(SLINT_COMPILER "" CACHE FILEPATH "Path to the slint-compiler executable. When unset, it the compiler will be build as part of the build process")
set(SLINT_COMPILER "" CACHE STRING "Path to the slint-compiler executable. When unset, it the compiler will be build as part of the build process. When set to 'download', the compiler will be downloaded from GitHub.")
set(SLINT_LIBRARY_CARGO_FLAGS "" CACHE STRING
"Flags to pass to cargo when building the Slint runtime library")

Expand Down Expand Up @@ -431,8 +431,12 @@ if(SLINT_BUILD_RUNTIME)
endforeach()

get_property(_SLINT_STYLE GLOBAL PROPERTY SLINT_STYLE)
get_target_property(_slint_compiler_location slint-compiler IMPORTED_LOCATION)
cmake_path(GET _slint_compiler_location FILENAME SLINT_COMPILER_FILE_NAME)
if (TARGET slint-compiler)
get_target_property(_slint_compiler_location slint-compiler IMPORTED_LOCATION)
cmake_path(GET _slint_compiler_location FILENAME SLINT_COMPILER_FILE_NAME)
endif()

set(SLINT_VERSION 1.8.0)

configure_package_config_file("cmake/SlintConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/Slint/SlintConfig.cmake" INSTALL_DESTINATION lib/cmake/Slint)
endfunction()
Expand Down
35 changes: 34 additions & 1 deletion api/cpp/cmake/SlintConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3133b4c

Please sign in to comment.