Files
slint-cpp-template/CMakeLists.txt
Olivier Goffart b18889fec7 Add Android C++ support
Build a shared library on Android (NDK auto-detected by Slint's CMake)
and provide an extern "C" slint_main() entry point. Add a Gradle
wrapper under android/ so users can run ./gradlew installDebug.
2026-05-29 10:15:07 +00:00

30 lines
1.1 KiB
CMake

cmake_minimum_required(VERSION 3.21)
project(my_application LANGUAGES CXX)
find_package(Slint QUIET)
if (NOT Slint_FOUND)
message("Slint could not be located in the CMake module search path. Downloading it from Git and building it locally")
include(FetchContent)
FetchContent_Declare(
Slint
GIT_REPOSITORY https://github.com/slint-ui/slint.git
# `release/1` will auto-upgrade to the latest Slint >= 1.0.0 and < 2.0.0
# `release/1.0` will auto-upgrade to the latest Slint >= 1.0.0 and < 1.1.0
GIT_TAG release/1
SOURCE_SUBDIR api/cpp
)
FetchContent_MakeAvailable(Slint)
endif (NOT Slint_FOUND)
if(ANDROID)
add_library(my_application SHARED src/main.cpp)
else()
add_executable(my_application src/main.cpp)
endif()
target_link_libraries(my_application PRIVATE Slint::Slint)
slint_target_sources(my_application ui/app-window.slint)
# On Windows, copy the Slint DLL next to the application binary so that it's found.
if (WIN32)
add_custom_command(TARGET my_application POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:my_application> $<TARGET_FILE_DIR:my_application> COMMAND_EXPAND_LISTS)
endif()