Skip to content

Commit

Permalink
Document the SLINT_FEATURE_XXX pre-processor variables
Browse files Browse the repository at this point in the history
and sync them with the existing features.
  • Loading branch information
tronical committed Jul 4, 2024
1 parent 7ab7dd6 commit 6d79ca1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function(define_cargo_dependent_feature cargo_feature description default depend
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.
# defaults need to be kept in sync with the Rust bit (cpp/Cargo.toml and cbindgen.rs)

define_cargo_feature(freestanding "Enable use of freestanding environment. This is only for bare-metal systems. Most other features are incompatible with this one" OFF)

Expand Down
2 changes: 1 addition & 1 deletion api/cpp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ crate-type = ["lib", "cdylib", "staticlib"]
name = "slint_cpp"

# Note, these features need to be kept in sync (along with their defaults) in
# the C++ crate's CMakeLists.txt
# the C++ crate's CMakeLists.txt as well as cbindgen.rs
[features]
interpreter = ["slint-interpreter", "std"]
# Enable some function used by the integration tests
Expand Down
21 changes: 20 additions & 1 deletion api/cpp/cbindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,26 @@ macro_rules! declare_features {
};
}

declare_features! {interpreter backend_qt freestanding renderer_software renderer_skia experimental gettext testing}
declare_features! {
interpreter
testing
backend_qt
backend_winit
backend_winit_x11
backend_winit_wayland
backend_linuxkms
backend_linuxkms_noseat
renderer_femtovg
renderer_skia
renderer_skia_opengl
renderer_skia_vulkan
renderer_software
gettext
accessibility
system_testing
freestanding
experimental
}

/// Generate the headers.
/// `root_dir` is the root directory of the slint git repo
Expand Down
11 changes: 11 additions & 0 deletions api/cpp/docs/cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ if ("BACKEND_WINIT" IN_LIST slint_enabled_features)
endif()
```

Similarly, if you need to check for features at compile-time, check for the existence
of `SLINT_FEATURE_<NAME>` pre-processor macros:

```
#include <slint.h>
#if defined(SLINT_FEATURE_BACKEND_WINIT)
// ...
#endif
```

### Rust Flags

Slint uses [Corrosion](https://github.com/corrosion-rs/corrosion) to build Slint, which is developed in Rust. You can utilize [Corrosion's global CMake variables](https://corrosion-rs.github.io/corrosion/usage.html#global-corrosion-options) to control certain aspects of the Rust build process.
Expand Down
18 changes: 14 additions & 4 deletions xtask/src/cppdocs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,23 @@ pub fn generate(show_warnings: bool) -> Result<(), Box<dyn std::error::Error>> {
let generated_headers_dir = docs_build_dir.join("generated_include");
let enabled_features = cbindgen::EnabledFeatures {
interpreter: true,
testing: true,
backend_qt: false,
freestanding: false,
renderer_software: true,
backend_winit: true,
backend_winit_x11: false,
backend_winit_wayland: false,
backend_linuxkms: false,
backend_linuxkms_noseat: false,
renderer_femtovg: true,
renderer_skia: true,
experimental: false,
renderer_skia_opengl: false,
renderer_skia_vulkan: false,
renderer_software: true,
gettext: true,
testing: true,
accessibility: true,
system_testing: false,
freestanding: false,
experimental: false,
};
cbindgen::gen_all(&root, &generated_headers_dir, enabled_features)?;

Expand Down

0 comments on commit 6d79ca1

Please sign in to comment.