mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Allow selecting features in the CMake integration
Provide the same features as in the Rust API crate, as CMake options.
This commit is contained in:
parent
4f1eacd6d8
commit
5a81976f3b
4 changed files with 61 additions and 4 deletions
|
@ -14,7 +14,7 @@ include(FetchContent)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
Corrosion
|
Corrosion
|
||||||
GIT_REPOSITORY https://github.com/AndrewGaspar/corrosion.git
|
GIT_REPOSITORY https://github.com/AndrewGaspar/corrosion.git
|
||||||
GIT_TAG b7a78deb2632b502717c7b636a925677a99e06a1
|
GIT_TAG 9ea8f6ba30750926b622bab6d4c89b8ab78abe04
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(Corrosion)
|
FetchContent_MakeAvailable(Corrosion)
|
||||||
corrosion_import_crate(MANIFEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../Cargo.toml"
|
corrosion_import_crate(MANIFEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../Cargo.toml"
|
||||||
|
@ -59,6 +59,39 @@ add_library(SixtyFPS::SixtyFPS ALIAS SixtyFPS)
|
||||||
target_link_libraries(SixtyFPS INTERFACE sixtyfps-cpp)
|
target_link_libraries(SixtyFPS INTERFACE sixtyfps-cpp)
|
||||||
target_compile_features(SixtyFPS INTERFACE cxx_std_17)
|
target_compile_features(SixtyFPS INTERFACE cxx_std_17)
|
||||||
|
|
||||||
|
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.19.0)
|
||||||
|
function(define_cargo_feature cargo-feature description default)
|
||||||
|
# turn foo-bar into SIXTYFPS_FEATURE_FOO_BAR
|
||||||
|
string(TOUPPER "${cargo-feature}" cmake_option)
|
||||||
|
string(REPLACE "-" "_" cmake_option "${cmake_option}")
|
||||||
|
set(cmake_option "SIXTYFPS_FEATURE_${cmake_option}")
|
||||||
|
option("${cmake_option}" "${description}" ${default})
|
||||||
|
if(${cmake_option})
|
||||||
|
list(APPEND features ${cargo-feature})
|
||||||
|
endif()
|
||||||
|
set(features "${features}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# Features that are mapped to features in the Rust crate. These and their
|
||||||
|
# defaults need to be kept in sync with the Rust bit.
|
||||||
|
define_cargo_feature(interpreter "Enable support for the SixtyFPS interpeter to load .60 files at run-time" ON)
|
||||||
|
define_cargo_feature(x11 "Enable X11 support when using GL backend" ON)
|
||||||
|
define_cargo_feature(wayland "Enable Wayland support when using the GL backend" OFF)
|
||||||
|
define_cargo_feature(backend-gl "Enable OpenGL ES 2.0 based rendering backend" ON)
|
||||||
|
define_cargo_feature(backend-qt "Enable Qt based rendering backend" ON)
|
||||||
|
|
||||||
|
set_property(
|
||||||
|
TARGET sixtyfps-cpp
|
||||||
|
PROPERTY CORROSION_FEATURES
|
||||||
|
${features}
|
||||||
|
)
|
||||||
|
set_property(
|
||||||
|
TARGET sixtyfps-cpp
|
||||||
|
PROPERTY CORROSION_NO_DEFAULT_FEATURES
|
||||||
|
${features}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
file(GLOB api_headers RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/include/"
|
file(GLOB api_headers RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/include/"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,14 @@ publish = false
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
crate-type = ["lib", "cdylib"]
|
crate-type = ["lib", "cdylib"]
|
||||||
|
|
||||||
|
# Note, these features need to be kept in sync (along with their defaults) in
|
||||||
|
# the C++ crate's CMakeLists.txt
|
||||||
[features]
|
[features]
|
||||||
# In the future, this shouldn't be a default feature, but should be enabled by cmake
|
interpreter = ["sixtyfps-interpreter"]
|
||||||
default = ["sixtyfps-interpreter"]
|
x11 = ["sixtyfps-rendering-backend-default/x11"]
|
||||||
|
wayland = ["sixtyfps-rendering-backend-default/wayland"]
|
||||||
|
backend-gl = ["sixtyfps-rendering-backend-default/sixtyfps-rendering-backend-gl"]
|
||||||
|
backend-qt = ["sixtyfps-rendering-backend-default/sixtyfps-rendering-backend-qt"]
|
||||||
# Enable some function used by the integration tests
|
# Enable some function used by the integration tests
|
||||||
testing = ["sixtyfps-rendering-backend-testing"]
|
testing = ["sixtyfps-rendering-backend-testing"]
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,24 @@ FetchContent_MakeAvailable(SixtyFPS)
|
||||||
If you prefer to treat SixtyFPS as an external CMake package, then you can also build SixtyFPS from source like a regular
|
If you prefer to treat SixtyFPS as an external CMake package, then you can also build SixtyFPS from source like a regular
|
||||||
CMake project, install it into a prefix directory of your choice and use `find_package(SixtyFPS)` in your `CMakeLists.txt`.
|
CMake project, install it into a prefix directory of your choice and use `find_package(SixtyFPS)` in your `CMakeLists.txt`.
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
The SixtyFPS run-time library supports different features that can be toggled. You might want to enable a feature that is
|
||||||
|
not enabled by default but that is revelant for you, or you may want to disable a feature that you know you do not need and
|
||||||
|
therefore reduce the size of the resulting library.
|
||||||
|
|
||||||
|
The CMake configure step offers CMake options for various feature that are all prefixed with `SIXTYFPS_FEATURE_`. For example
|
||||||
|
you can enable support for the Wayland windowing system on Linux by enabling the `SIXTYFPS_FEATURE_WAYLAND` feature. There are
|
||||||
|
different ways of toggling CMake options. For example on the command line using the `-D` parameter:
|
||||||
|
|
||||||
|
`cmake -DSIXTYFPS_FEATURE_WAYLAND=ON ...`
|
||||||
|
|
||||||
|
Alternatively, after the configure step you can use `cmake-gui` or `ccmake` on the build directory for a list of all features
|
||||||
|
and their description.
|
||||||
|
|
||||||
|
This works when compiling SixtyFPS as a package, using `cmake --build` and `cmake --install`, or when including SixtyFPS
|
||||||
|
using `FetchContent`.
|
||||||
|
|
||||||
### Cross-compiling
|
### Cross-compiling
|
||||||
|
|
||||||
It is possible to cross-compile SixtyFPS to a different target architecture when building with CMake. In order to complete
|
It is possible to cross-compile SixtyFPS to a different target architecture when building with CMake. In order to complete
|
||||||
|
|
|
@ -11,6 +11,8 @@ homepage = "https://sixtyfps.io"
|
||||||
[lib]
|
[lib]
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|
||||||
|
# Note, these features need to be kept in sync (along with their defaults) in
|
||||||
|
# the C++ crate's CMakeLists.txt
|
||||||
[features]
|
[features]
|
||||||
x11 = ["winit/x11", "glutin/x11", "copypasta/x11"]
|
x11 = ["winit/x11", "glutin/x11", "copypasta/x11"]
|
||||||
wayland = ["winit/wayland", "glutin/wayland", "copypasta/wayland"]
|
wayland = ["winit/wayland", "glutin/wayland", "copypasta/wayland"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue