diff --git a/api/sixtyfps-cpp/CMakeLists.txt b/api/sixtyfps-cpp/CMakeLists.txt index efcb38179..eb0bbd785 100644 --- a/api/sixtyfps-cpp/CMakeLists.txt +++ b/api/sixtyfps-cpp/CMakeLists.txt @@ -14,7 +14,7 @@ include(FetchContent) FetchContent_Declare( Corrosion GIT_REPOSITORY https://github.com/AndrewGaspar/corrosion.git - GIT_TAG b7a78deb2632b502717c7b636a925677a99e06a1 + GIT_TAG 9ea8f6ba30750926b622bab6d4c89b8ab78abe04 ) FetchContent_MakeAvailable(Corrosion) 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_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/" "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") diff --git a/api/sixtyfps-cpp/Cargo.toml b/api/sixtyfps-cpp/Cargo.toml index 7ffebbed1..b61ec224e 100644 --- a/api/sixtyfps-cpp/Cargo.toml +++ b/api/sixtyfps-cpp/Cargo.toml @@ -13,10 +13,14 @@ publish = false path = "lib.rs" 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] -# In the future, this shouldn't be a default feature, but should be enabled by cmake -default = ["sixtyfps-interpreter"] - +interpreter = ["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 testing = ["sixtyfps-rendering-backend-testing"] diff --git a/api/sixtyfps-cpp/docs/cmake.md b/api/sixtyfps-cpp/docs/cmake.md index 279c77420..d84212fe6 100644 --- a/api/sixtyfps-cpp/docs/cmake.md +++ b/api/sixtyfps-cpp/docs/cmake.md @@ -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 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 It is possible to cross-compile SixtyFPS to a different target architecture when building with CMake. In order to complete diff --git a/sixtyfps_runtime/rendering_backends/gl/Cargo.toml b/sixtyfps_runtime/rendering_backends/gl/Cargo.toml index b5c868369..7ee29a0fa 100644 --- a/sixtyfps_runtime/rendering_backends/gl/Cargo.toml +++ b/sixtyfps_runtime/rendering_backends/gl/Cargo.toml @@ -11,6 +11,8 @@ homepage = "https://sixtyfps.io" [lib] path = "lib.rs" +# Note, these features need to be kept in sync (along with their defaults) in +# the C++ crate's CMakeLists.txt [features] x11 = ["winit/x11", "glutin/x11", "copypasta/x11"] wayland = ["winit/wayland", "glutin/wayland", "copypasta/wayland"]