### Setup Example Project with Melos Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/README.md Installs Melos and bootstraps the example project dependencies. This is a prerequisite for running the example project locally. ```bash flutter pub global activate melos # if you don't have melos already installed git clone https://github.com/superlistapp/super_native_extensions.git cd super_native_extensions melos bootstrap ``` -------------------------------- ### Installation Bundle Setup Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_keyboard_layout/example/linux/CMakeLists.txt Configures the installation prefix to create a relocatable bundle and ensures a clean build bundle directory on each installation. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Installation Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/example/linux/CMakeLists.txt Configures the installation process for the application bundle, including cleaning the build directory, installing the executable, data files, libraries, and assets. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Configure Installation Directory and Default Build Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/windows/CMakeLists.txt Sets up installation paths and ensures the 'install' step is part of the default build process for Visual Studio. ```cmake # Support files are copied into place next to the executable, so that it can # run in place. This is done instead of making a separate bundle (as on Linux) # so that building and running from within Visual Studio will work. set(BUILD_BUNDLE_DIR "$") # Make the "install" step default, as it's required to run. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Install Application Executable Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/windows/CMakeLists.txt Installs the main application executable to the runtime destination. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Installing Application and Data Files Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_keyboard_layout/example/linux/CMakeLists.txt Installs the application executable, ICU data file, Flutter library, and bundled plugin libraries to their respective destinations within the installation bundle. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Install Flutter Library Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/windows/CMakeLists.txt Installs the main Flutter library file to the root of the installation bundle. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installation Bundle Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/linux/CMakeLists.txt Configures the installation process to create a relocatable application bundle, including cleaning the bundle directory and installing the executable, ICU data, and libraries. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/windows/CMakeLists.txt Installs any additional libraries bundled with plugins to the installation bundle. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Setting Installation Prefix Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/linux/CMakeLists.txt Configures the installation prefix, defaulting to a build bundle directory for relocatability. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Installation Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/example/windows/CMakeLists.txt Configures installation paths and components for the application executable, data files, libraries, and assets, ensuring the application can run in place. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Defining Installation Directories Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/linux/CMakeLists.txt Sets variables for the installation paths of data and libraries within the bundle. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/linux/CMakeLists.txt Initializes the CMake build system, sets the minimum required version, and defines the project name and languages. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) ``` -------------------------------- ### Installing Bundled Libraries Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/linux/CMakeLists.txt Installs any bundled libraries required by plugins to the library directory. ```cmake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Cargokit Configuration Example Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/cargokit/docs/architecture.md Example cargokit.yaml file for configuring Rust crate builds, including debug and release toolchains, extra cargo flags, and precompiled binary settings. ```yaml cargo: debug: # Configuration of cargo execution during debug builds toolchain: stable # default release: # Configuration of cargo execution for release builds toolchain: nightly # rustup will be invoked with nightly toolchain extra_flags: # extra arguments passed to cargo build - -Z - build-std=panic_abort,std # If crate ships with precompiled binaries, they can be configured here. precompiled_binaries: # Uri prefix used when downloading precompiled binaries. url_prefix: https://github.com/superlistapp/super_native_extensions/releases/download/precompiled_ # Public key for verifying downloaded precompiled binaries. public_key: 3a257ef1c7d72d84225ac4658d24812ada50a7a7a8a2138c2a91353389fdc514 ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/example/linux/CMakeLists.txt Sets up the CMake version, project name, executable name, application ID, and installation paths. It also defines build type and standard compilation settings. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "example") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "com.example.example") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(SET CMP0063 NEW) # Load bundled libraries from the lib/ directory relative to the binary. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Root filesystem for cross-building. if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() # Define build configuration options. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() # Compilation settings that should be applied to most targets. # # Be cautious about adding new options here, as plugins use this function by # default. In most cases, you should add new options to specific targets instead # of modifying this function. function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() # Flutter library and tool build rules. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") # Define the application target. To change its name, change BINARY_NAME above, # not the value here, or `flutter run` will no longer work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) # Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Bootstrap Super Native Extensions Source: https://github.com/superlistapp/super_native_extensions/blob/main/README.md Clone the repository and bootstrap the project using melos. This command installs all necessary dependencies. ```bash git clone https://github.com/superlistapp/super_native_extensions.git cd super_native_extensions melos bootstrap ``` -------------------------------- ### Install Rust for macOS or Linux Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/README.md Installs Rust using the official script for macOS and Linux. This is required if you want to compile the Rust code from source. ```bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` -------------------------------- ### Install AOT Library Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the data directory, but only for Profile and Release build configurations. ```cmake # Install the AOT library on non-Debug builds only. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Basic Context Menu Widget Usage Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/README.md Demonstrates the basic usage of the ContextMenuWidget. This example shows how to define a simple context menu with actions and a submenu. ```dart return ContextMenuWidget( // force to use dark brightness // mobileMenuWidgetBuilder: DefaultMobileMenuWidgetBuilder(brightness: Brightness.dark), child: const Item( child: Text('Base Context Menu'), ), menuProvider: (_) { return Menu( children: [ MenuAction(title: 'Menu Item 2', callback: () {}), MenuAction(title: 'Menu Item 3', callback: () {}), MenuSeparator(), Menu(title: 'Submenu', children: [ MenuAction(title: 'Submenu Item 1', callback: () {}), MenuAction(title: 'Submenu Item 2', callback: () {}), Menu(title: 'Nested Submenu', children: [ MenuAction(title: 'Submenu Item 1', callback: () {}), MenuAction(title: 'Submenu Item 2', callback: () {}), ]), ]), ], ); }, ); ``` -------------------------------- ### Installing Flutter Assets Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/linux/CMakeLists.txt Removes stale assets and copies the latest Flutter assets to the installation bundle's data directory. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### GitHub Action to Precompile and Upload Binaries Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/cargokit/docs/precompiled_binaries.md Example GitHub Actions workflow to automatically precompile Rust binaries for supported targets and upload them as GitHub releases. Requires `RELEASE_GITHUB_TOKEN` and `RELEASE_PRIVATE_KEY` secrets. ```yaml on: push: branches: [ main ] name: Precompile Binaries jobs: Precompile: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: - ubuntu-latest - macOS-latest - windows-latest steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v1 - name: Install GTK if: (matrix.os == 'ubuntu-latest') run: sudo apt-get update && sudo apt-get install libgtk-3-dev - name: Precompile if: (matrix.os == 'macOS-latest') || (matrix.os == 'windows-latest') run: dart run build_tool precompile-binaries -v --manifest-dir=../../rust --repository=superlistapp/super_native_extensions working-directory: super_native_extensions/cargokit/build_tool env: GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} PRIVATE_KEY: ${{ secrets.RELEASE_PRIVATE_KEY }} - name: Precompile (with Android) if: (matrix.os == 'ubuntu-latest') run: dart run build_tool precompile-binaries -v --manifest-dir=../../rust --repository=superlistapp/super_native_extensions --android-sdk-location=/usr/local/lib/android/sdk --android-ndk-version=24.0.8215888 --android-min-sdk-version=23 working-directory: super_native_extensions/cargokit/build_tool env: GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} PRIVATE_KEY: ${{ secrets.RELEASE_PRIVATE_KEY }} ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/windows/CMakeLists.txt Removes stale assets and then installs the application's assets directory to the data directory. This ensures assets are up-to-date on each build. ```cmake # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/linux/CMakeLists.txt Sets the minimum CMake version, project name, executable name, and application ID. It also enables modern CMake behaviors and sets the installation rpath. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "example") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "com.example.example") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(SET CMP0063 NEW) # Load bundled libraries from the lib/ directory relative to the binary. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Install ICU Data File Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/windows/CMakeLists.txt Installs the ICU data file, which is necessary for internationalization, to the data directory. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Cross-Building Setup Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_keyboard_layout/example/linux/CMakeLists.txt Configures CMake for cross-building by setting the sysroot and adjusting find root path modes when FLUTTER_TARGET_PLATFORM_SYSROOT is defined. ```cmake # Root filesystem for cross-building. if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() ``` -------------------------------- ### Cleaning Build Bundle Directory Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/linux/CMakeLists.txt Ensures the build bundle directory is clean before installation by removing existing files. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Update Rust Installation Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/README.md Updates an existing Rust installation to the latest version. Ensure your Rust toolchain is up-to-date. ```bash rustup update ``` -------------------------------- ### Conditional AOT Library Installation Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/example/linux/CMakeLists.txt Installs the AOT library to the runtime destination directory only if the build type is not 'Debug'. This ensures the library is available for release or other non-debug configurations. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Finding and checking system dependencies with PkgConfig Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/example/linux/flutter/CMakeLists.txt This snippet uses PkgConfig to find and check for required system libraries (GTK, GLIB, GIO) and makes their imported targets available for linking. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Configure cargokit.yaml for Precompiled Binaries Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/cargokit/docs/precompiled_binaries.md Place this file alongside `Cargo.toml` in your Rust crate. It specifies the URL prefix for downloading binaries and the public key for verification. ```yaml precompiled_binaries: # Uri prefix used when downloading precompiled binaries. url_prefix: https://github.com///releases/download/precompiled_ # Public key for verifying downloaded precompiled binaries. public_key: ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/windows/CMakeLists.txt Applies a standard set of build settings from the application-level CMakeLists.txt. This can be removed if full control over build settings is desired. ```cmake apply_standard_settings(${PLUGIN_NAME}) ``` -------------------------------- ### Include Directories and Library Dependencies Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/windows/CMakeLists.txt Configures include directories for the plugin and links essential libraries. 'flutter' and 'flutter_wrapper_plugin' are required for Flutter integration. ```cmake target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) ``` -------------------------------- ### Finding System Dependencies Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/linux/CMakeLists.txt Checks for required system libraries, specifically GTK, using PkgConfig. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Set Source Include Directories and Library Dependencies Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/linux/CMakeLists.txt Configures include directories for source files and links necessary libraries, including Flutter, GTK via PkgConfig, and Rust dependencies managed by CargoKit. ```cmake target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter) target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Flutter Library Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/example/windows/flutter/CMakeLists.txt Defines the Flutter library, its headers, and ICU data file. It also sets project build directory and AOT library path for use in install steps. ```cmake cmake_minimum_required(VERSION 3.14) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) # TODO: Move the rest of this into files in ephemeral. See # https://github.com/flutter/flutter/issues/57146. set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") # === Flutter Library === set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "flutter_export.h" "flutter_windows.h" "flutter_messenger.h" "flutter_plugin_registrar.h" "flutter_texture_registrar.h" ) list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/windows/runner/CMakeLists.txt Applies a predefined set of standard build settings to the specified target. This can be customized for applications requiring different build configurations. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Defining Flutter library and related paths Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/example/linux/flutter/CMakeLists.txt Sets variables for the Flutter library path, ICU data file, project build directory, and the AOT (Ahead-Of-Time) compiled library. These are published to the parent scope for use in installation steps. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) ``` -------------------------------- ### Enable Unicode Support Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/windows/CMakeLists.txt Adds preprocessor definitions to enable Unicode support for all projects. ```cmake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Configuring Flutter Library and Dependencies Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/linux/flutter/CMakeLists.txt This section sets up the Flutter library and its associated headers, linking against system-level dependencies required for GTK integration. It ensures that all necessary components are correctly identified and made available for the build process. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) ``` -------------------------------- ### Executable Output Directory Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/linux/CMakeLists.txt Sets the runtime output directory for the executable to a subdirectory to ensure correct resource loading. ```cmake # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Generate Key Pair with build_tool Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/cargokit/docs/precompiled_binaries.md Use the `build_tool` to generate a public and private key pair for signing precompiled binaries. Store the private key securely as a secret for CI/CD. ```dart dart run build_tool gen-key ``` -------------------------------- ### Flutter Tool Backend Integration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/windows/flutter/CMakeLists.txt Sets up a custom command to integrate with the Flutter tool backend for assembly. This command is designed to run every time due to a phony target, ensuring up-to-date build artifacts. ```cmake # === Flutter tool backend === # _phony_ is a non-existent file to force this command to run every time, # since currently there's no way to get a full input/output list from the # flutter tool. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/example/windows/runner/CMakeLists.txt Specifies the libraries and include directories required for the build. Application-specific dependencies should be added here. ```cmake # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Create and Register a System-Wide Hotkey Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_hot_key/README.md Use this snippet to create a hotkey that triggers a callback when a specific key combination (e.g., Meta + Alt + Minus) is pressed, regardless of application focus. Remember to dispose of the hotkey when it's no longer needed. ```dart final hotKey = await HotKey.create( definition: HotKeyDefinition( key: PhysicalKeyboardKey.minus, alt: true, meta: true, ), callback: () { print('hot key pressed'); }, ); // .. Meta + Alt + Minus will trigger the callback regardless of whether // the application is in focus // Unregister the hot key hotKey.dispose(); ``` -------------------------------- ### Writing to Clipboard with DataWriterItem Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/README.md Demonstrates writing plain text, HTML text, and PNG image data to the system clipboard using DataWriterItem. Ensure the SystemClipboard instance is available before proceeding. ```dart import 'package:super_clipboard/super_clipboard.dart'; // ... final clipboard = SystemClipboard.instance; if (clipboard == null) { return; // Clipboard API is not supported on this platform. } final item = DataWriterItem(); item.add(Formats.htmlText('HTML text')); item.add(Formats.plainText('plain text')); item.add(Formats.png(imageData)); await clipboard.write([item]); ``` -------------------------------- ### Flutter Keyboard Layout Manager Usage Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_keyboard_layout/README.md Demonstrates how to initialize and use the KeyboardLayoutManager in a Flutter application. It shows how to check for platform support, listen for layout changes, and retrieve key mappings. ```dart import 'package:super_keyboard_layout/super_keyboard_layout.dart'; void main() async { final manager = await KeyboardLayoutManager.instance(); if (manager.supported) { // Running on supported platform manager.onLayoutChanged.addListener(() { // Keyboard layout changed print('Keyboard layout changed'); }); } final layout = manager.currentLayout; // Getting logical key for physical key 1 with shift for current layout final logicalKey = layout.getLogicalKeyForPhysicalKey(PhysicalKeyboardKey.digit1, shift: true); // Getting physical key for logical key final physicalKey = layout.getPhysicalKeyForLogicalKey(LogicalKeyboardKey.keyA); // Getting platform spcific key code for either logical or physical key final playformCode = layout.getPlatformKeyCode(PhysicalKeyboardKey.digit1); } ``` -------------------------------- ### Project Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/windows/CMakeLists.txt Defines the project name and the languages it uses. The project name 'super_native_extensions' is used for build system identification. ```cmake set(PROJECT_NAME "super_native_extensions") project(${PROJECT_NAME} LANGUAGES CXX) ``` -------------------------------- ### Project and Plugin Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/linux/CMakeLists.txt Sets the project name and the specific name for the plugin library. The PLUGIN_NAME must not be changed due to its importance in build generation. ```cmake set(PROJECT_NAME "super_native_extensions") project(${PROJECT_NAME} LANGUAGES CXX) # This value is used when generating builds using this plugin, so it must # not be changed. set(PLUGIN_NAME "super_native_extensions_plugin") ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/windows/runner/CMakeLists.txt Adds necessary dependency libraries and include directories for the target. Application-specific dependencies should also be added here. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Runtime Output Directory Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_keyboard_layout/example/linux/CMakeLists.txt Sets the runtime output directory for the executable to a subdirectory to ensure correct resource loading and prevent execution of unbundled copies. ```cmake # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Setting Runtime Library Path Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/linux/CMakeLists.txt Configures the runtime search path for libraries to include the 'lib' directory relative to the binary. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Cross-Building System Root Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/linux/CMakeLists.txt Configures the sysroot and find root path for cross-compiling Flutter applications on Linux. ```cmake if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() ``` -------------------------------- ### Include Generated Plugin Build Rules Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/windows/CMakeLists.txt Includes a CMake file that manages the building of plugins and their integration into the application. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Writing to Clipboard with Lazy Data Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/README.md Shows how to provide clipboard data asynchronously using lazy callbacks for HTML text, plain text, and PNG images. Callbacks should execute quickly to avoid blocking the main thread. ```dart final item = DataWriterItem(); item.add(Formats.htmlText.lazy(() => 'HTML text')); item.add(Formats.plainText.lazy(() => 'plain text')); item.add(Formats.png.lazy(() => imageData)); await clipboard.write([item]); ``` -------------------------------- ### Defining the Application Executable Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/linux/CMakeLists.txt Defines the main executable target for the application, listing its source files. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) ``` -------------------------------- ### Custom command for Flutter tool backend integration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/example/linux/flutter/CMakeLists.txt This custom command is designed to run the Flutter tool backend script. It's configured to output the Flutter library and headers, and a dummy file '_phony_' to ensure it runs on every build due to the lack of a direct input/output list for the tool. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) ``` -------------------------------- ### Loading Flutter Subdirectory Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/linux/CMakeLists.txt Includes the Flutter managed directory, which contains Flutter's build rules. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Flutter Project Integration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/windows/CMakeLists.txt Includes the Flutter managed directory and generated plugin configurations, essential for building Flutter applications with native extensions. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) add_subdirectory("runner") include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Application Executable Definition Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_keyboard_layout/example/linux/CMakeLists.txt Defines the main executable target for the application, listing its source files and applying standard build settings. ```cmake # Define the application target. To change its name, change BINARY_NAME above, # not the value here, or `flutter run` will no longer work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Flutter and System Dependencies Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/linux/CMakeLists.txt Includes the Flutter managed directory and checks for GTK+ 3.0 using PkgConfig. Defines the APPLICATION_ID for the build. ```cmake # Flutter library and tool build rules. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Application Executable Definition Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/linux/CMakeLists.txt Defines the main executable target for the application, including source files and generated plugin registration. ```cmake # Define the application target. To change its name, change BINARY_NAME above, # not the value here, or `flutter run` will no longer work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) # Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Linking Dependencies Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/linux/CMakeLists.txt Links the application executable against the Flutter library and GTK. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/example/windows/CMakeLists.txt Sets the minimum CMake version, project name, and executable name. It also configures build types based on whether the generator is multi-config. ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) set(BINARY_NAME "example") cmake_policy(SET CMP0063 NEW) get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() ``` -------------------------------- ### Load Flutter Web App with Service Worker Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/web/index.html This snippet is responsible for loading the main Dart entry point for a Flutter web application. It configures the service worker and initializes the Flutter engine. ```javascript var serviceWorkerVersion = null; window.addEventListener('load', function(ev) { // Download main.dart.js _flutter.loader.loadEntrypoint({ serviceWorker: { serviceWorkerVersion: serviceWorkerVersion, } }).then(function(engineInitializer) { return engineInitializer.initializeEngine(); }).then(function(appRunner) { return appRunner.runApp(); }); }); ``` -------------------------------- ### Bundled Libraries Configuration Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/windows/CMakeLists.txt Defines a list of absolute paths to libraries that should be bundled with the plugin. This includes the CargoKit-generated library. ```cmake set(super_native_extensions_bundled_libraries "${${PLUGIN_NAME}_cargokit_lib}" PARENT_SCOPE ) ``` -------------------------------- ### Plugin Name and Source Files Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/windows/CMakeLists.txt Sets the internal plugin name and lists the source files for the plugin library. The PLUGIN_NAME must not be changed due to external dependencies. ```cmake set(PLUGIN_NAME "super_native_extensions_plugin") list(APPEND PLUGIN_SOURCES "super_native_extensions_plugin.cpp" "super_native_extensions_plugin.h" ) ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/windows/runner/CMakeLists.txt Links necessary libraries (flutter, flutter_wrapper_app) and adds include directories to the target. Custom application-specific dependencies should also be added here. ```cmake # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Define Build Configuration Types Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/example/windows/CMakeLists.txt Sets the available build configurations (Debug, Profile, Release) for multi-configuration generators or the default build type for single-configuration generators. ```cmake get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() ``` -------------------------------- ### Plugin Registration Inclusion Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_keyboard_layout/example/linux/CMakeLists.txt Includes the CMake script for generated plugin build rules, which manages building plugins and adding them to the application. ```cmake # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Declare Content Provider for Android Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_clipboard/README.md Declares a content provider in AndroidManifest.xml to enable writing custom data formats like images to the clipboard. Replace `` with your actual package name. ```xml ... ... ``` -------------------------------- ### Flutter Tool Backend Custom Command Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_context_menu/example/windows/flutter/CMakeLists.txt Defines a custom command to execute the Flutter tool backend script. This command is set up to run every time by using a phony output file, as direct input/output tracking is not available. ```cmake # === Flutter tool backend === # _phony_ is a non-existent file to force this command to run every time, since currently there's no way to get a full input/output list from the # flutter tool. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" windows-x64 $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Defining Application ID Macro Source: https://github.com/superlistapp/super_native_extensions/blob/main/super_drag_and_drop/example/linux/CMakeLists.txt Adds a preprocessor definition for the application ID. ```cmake add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ```