From 02c3e84cb676bb59ec91e055eee86ebaf7f85811 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 8 Dec 2022 15:21:08 -0600 Subject: [PATCH] updates to build system --- .envrc | 3 +- CMakeLists.txt | 71 +++++++++++++++++++++++++++--- flake.lock | 12 ++--- shell.nix | 16 ++++--- src/CMakeLists.txt | 19 +------- src/main.cpp | 4 ++ src/qml/main.qml | 6 +++ src/qml/presenter/Presentation.qml | 2 + 8 files changed, 97 insertions(+), 36 deletions(-) diff --git a/.envrc b/.envrc index 3550a30..476cb0a 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,2 @@ -use flake +export NIXPKGS_ALLOW_INSECURE=1 +use flake . --impure diff --git a/CMakeLists.txt b/CMakeLists.txt index e2643d6..e096aef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,13 @@ cmake_minimum_required(VERSION 3.16) project(presenter) +set(APP_NAME ${PROJECT_NAME}) include(FeatureSummary) set(QT5_MIN_VERSION 5.15) set(KF5_MIN_VERSION 5.83) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) @@ -26,7 +29,7 @@ include(ECMPoQmTools) kde_enable_exceptions() -find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui QuickControls2 Widgets Sql X11Extras) +find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui QuickControls2 Widgets Sql X11Extras QmlImportScanner) find_package(KF5 ${KF_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 I18n Archive CoreAddons) find_package(Libmpv) @@ -51,12 +54,68 @@ INCLUDE_DIRECTORIES( ${LIBPODOFO_CONFIG_H} ) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# find_program(XDG-DESKTOP-MENU_EXECUTABLE xdg-desktop-menu) +# execute_process(COMMAND ${XDG-DESKTOP-MENU_EXECUTABLE} install --novender librepresenter.desktop) + +get_target_property(QMAKE Qt::qmake IMPORTED_LOCATION) +find_package(Corrosion QUIET) +if(NOT Corrosion_FOUND) + include(FetchContent) + FetchContent_Declare( + Corrosion + GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git + GIT_TAG v0.3.0 + ) + + FetchContent_MakeAvailable(Corrosion) +endif() add_subdirectory(src) +set(CRATE qml-minimal) + +# Corrosion creates a CMake target with the same name as the crate. +corrosion_import_crate(MANIFEST_PATH src/rust/Cargo.toml CRATES ${CRATE}) + +# The Rust library's build script needs to be told where to output the +# generated headers so CMake can find them. To do this, tell Corrosion +# to set the CXXQT_EXPORT_DIR environment variable when calling `cargo build`. +# Also, set the QMAKE environment variable to ensure the Rust library uses +# the same installation of Qt as CMake. +set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt") +corrosion_set_env_vars(${CRATE} + "CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}" + "QMAKE=${QMAKE}" +) + +# Include the headers generated by the Rust library's build script. Each +# crate gets its own subdirectory under CXXQT_EXPORT_DIR. This allows you +# to include headers generated by multiple crates without risk of one crate +# overwriting another's files. +target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}") + +# Link the Rust INTERFACE library target to Qt. Do this on the library target +# rather than the main executable. This way, CMake targets besides the main +# executable which link the Rust library, for example tests, will also link Qt. +target_link_libraries(${CRATE} INTERFACE + Qt5::Quick + Qt5::Qml + Qt5::Gui + Qt5::QuickControls2 + Qt5::Widgets + Qt5::Sql + Qt5::X11Extras + KF5::Kirigami2 + KF5::I18n + KF5::Archive + podofo + mpv +) + +# Link to the Rust library +target_link_libraries(${APP_NAME} PRIVATE ${CRATE}) + +# If we are using a statically linked Qt then we need to import any qml plugins +qt_import_qml_plugins(${APP_NAME}) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) - -find_program(XDG-DESKTOP-MENU_EXECUTABLE xdg-desktop-menu) -execute_process(COMMAND ${XDG-DESKTOP-MENU_EXECUTABLE} install --novender librepresenter.desktop) diff --git a/flake.lock b/flake.lock index cfe0b68..6aad4dc 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "flake-utils": { "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", "owner": "numtide", "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", "type": "github" }, "original": { @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1666282307, - "narHash": "sha256-O1T2HGLARLKDLfdOmjPBfn3eC4cSIaQD71wUN4I/6/s=", + "lastModified": 1670332253, + "narHash": "sha256-O5SmhlIUt1s+vK4NXeGYqwcBIMwbBPAEZ3GHE3XT28c=", "owner": "nixos", "repo": "nixpkgs", - "rev": "b7d8c687782c8f9a1d425a7e486eb989654f6468", + "rev": "1c9ffcf70786f0966982ce0fc76ec05df2e1dec2", "type": "github" }, "original": { diff --git a/shell.nix b/shell.nix index a5847e0..c953f48 100644 --- a/shell.nix +++ b/shell.nix @@ -7,7 +7,6 @@ mkShell rec { gcc gnumake clang - clang-tools qtcreator cmake extra-cmake-modules @@ -19,7 +18,7 @@ mkShell rec { buildInputs = [ clang-tools # clang-format - qt5.full + qt5.qtbase qt5.qttools qt5.qtquickcontrols2 qt5.qtx11extras @@ -35,17 +34,22 @@ mkShell rec { libsForQt5.kcoreaddons libsForQt5.kguiaddons - # This is only here because apparently it doesn't pick up the icon theme from the base system - # papirus-icon-theme - lightly-qt - podofo mpv # libsForQt5.kconfig # ffmpeg-full # yt-dlp + + # Rust tools + clippy + rustc + cargo + rustfmt + rust-analyzer + corrosion ]; + RUST_BACKTRACE = 1; # This creates the proper qt env so that plugins are found right. shellHook = '' setQtEnvironment=$(mktemp --suffix .setQtEnvironment.sh) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7df5f22..08879ca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,5 @@ -add_executable(presenter) + +add_executable(presenter main.cpp resources.qrc) target_sources(presenter PRIVATE @@ -15,20 +16,4 @@ target_sources(presenter mpv/qthelper.hpp mpv/mpvhelpers.h ) -target_link_libraries(presenter - Qt5::Quick - Qt5::Qml - Qt5::Gui - Qt5::QuickControls2 - Qt5::Widgets - Qt5::Sql - Qt5::X11Extras - KF5::Kirigami2 - KF5::CoreAddons - KF5::I18n - KF5::Archive - podofo - mpv -) - target_compile_options (presenter PUBLIC -fexceptions) diff --git a/src/main.cpp b/src/main.cpp index 77b375a..a2a5bd5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,6 +43,9 @@ #include "filemanager.h" #include "slide.h" +// RUST +#include "cxx-qt-gen/my_object.cxxqt.h" + static void connectToDatabase() { // let's setup our sql database QSqlDatabase db = QSqlDatabase::database(); @@ -128,6 +131,7 @@ int main(int argc, char *argv[]) qmlRegisterType("org.presenter", 1, 0, "ImageSqlModel"); qmlRegisterType("org.presenter", 1, 0, "PresentationSqlModel"); qmlRegisterType("org.presenter", 1, 0, "ServiceItemModel"); + qmlRegisterType("org.presenter", 1, 0, "MyObject"); qmlRegisterSingletonInstance("org.presenter", 1, 0, "SlideObject", slide.get()); qmlRegisterSingletonInstance("org.presenter", 1, 0, "FileManager", filemanager.get()); diff --git a/src/qml/main.qml b/src/qml/main.qml index 54ad3cb..4da9bd5 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -180,6 +180,12 @@ Kirigami.ApplicationWindow { /* print(loaded[0].audio); */ } + MyObject { + id: myObject + number: 7 + string: "HI from rust in my proj: " + myObject.number + } + Component.onCompleted: { /* showPassiveNotification(Kirigami.Settings.style); */ /* Kirigami.Settings.style = "Plasma"; */ diff --git a/src/qml/presenter/Presentation.qml b/src/qml/presenter/Presentation.qml index 0bd4b30..7be9c74 100644 --- a/src/qml/presenter/Presentation.qml +++ b/src/qml/presenter/Presentation.qml @@ -50,11 +50,13 @@ FocusScope { text: "Grid" icon.name: "view-app-grid-symbolic" hoverEnabled: true + onClicked: myObject.sayHi(myObject.string, myObject.number); } Controls.ToolButton { text: "Details" icon.name: "view-list-details" hoverEnabled: true + onClicked: showPassiveNotification(myObject.string); } Controls.ToolSeparator {} Item { Layout.fillWidth: true }