### Basic CMake Project Setup and Configuration Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/example/linux/CMakeLists.txt Initializes the CMake version and project name, sets application-specific identifiers, and configures modern CMake behaviors. It also defines installation paths for bundled libraries and manages build type settings. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) set(BINARY_NAME "example") set(APPLICATION_ID "com.example.example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 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() 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() ``` -------------------------------- ### CMake Installation Rules for Flutter Application Bundle Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/linux/CMakeLists.txt Defines the installation rules for the Flutter application bundle. It sets the installation prefix, cleans the build bundle directory, and installs the main executable, ICU data, Flutter library, bundled plugin libraries, and native assets. ```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() 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) set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) 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) if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Installation Rules for Windows Executable Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/windows/CMakeLists.txt Configures installation rules for the application's runtime components on Windows. This includes setting the installation prefix, copying the executable, data files, libraries, and assets to their respective locations next to the executable. ```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(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) 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) ``` -------------------------------- ### CMake Project Setup and Configuration Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/linux/CMakeLists.txt Initializes the CMake project, defines the project name and languages, sets the binary and application IDs, and configures modern CMake behaviors. It also sets the installation path for bundled libraries. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) set(BINARY_NAME "example") set(APPLICATION_ID "com.example.example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Installing Application Components in CMake Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/example/linux/CMakeLists.txt Installs the main executable, ICU data file, Flutter library, bundled plugin libraries, and native assets into the designated installation bundle directories. It also ensures assets are copied correctly and handles AOT library installation for non-Debug builds. ```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) set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) 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) if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Configuring Installation Bundle in CMake Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/example/linux/CMakeLists.txt Sets up the installation prefix to create a relocatable bundle in the build directory. It also ensures a clean build bundle directory on each installation and defines paths for data and library files within the bundle. ```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() 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") ``` -------------------------------- ### CMake Project Setup and Build Configuration Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/apps/app_a/windows/CMakeLists.txt Initializes the CMake project, sets the project name and language, defines the binary name, and configures build types (Debug, Profile, Release) based on whether the generator supports multi-configuration builds. It also sets default build type if not already defined. ```cmake cmake_minimum_required(VERSION 3.14) project(app_a LANGUAGES CXX) set(BINARY_NAME "app_a") cmake_policy(VERSION 3.14...3.25) 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() set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Dart Sample Variable Assignment Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/README.md This snippet demonstrates a basic variable assignment in Dart. It declares a constant string variable named 'like' and assigns it the value 'sample'. This is a foundational example for Dart syntax. ```dart const like = 'sample'; ``` -------------------------------- ### Install Application Bundle Contents (CMake) Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/apps/app_a/linux/CMakeLists.txt Configures the installation of the application bundle, including the executable, data files, libraries, and assets. It ensures a clean bundle directory on each build and specifies destinations for various components. ```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) # Copy the native assets provided by the build.dart from all packages. set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) # 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 the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Execute Flutter Pub Commands on Local Path Dependencies (Dart) Source: https://context7.com/linxunfeng/local_pub_workspace/llms.txt This Dart script executes 'flutter pub upgrade' or 'flutter pub get' on local path dependencies defined in 'dependency_overrides'. It specifically targets dependencies configured with a 'path' and skips Git or version-based dependencies. The script utilizes the 'args' package for argument parsing and custom modules for workspace management. ```dart import 'dart:io'; import 'package:args/args.dart'; import 'tool/commands/dependency_overrides.dart'; import 'tool/core/workspace_manager.dart'; void main() async { final workspaceManager = WorkspaceManager( rootDir: Directory.current, verbose: true, ); final command = DependencyOverridesCommand(workspaceManager); // Execute flutter pub upgrade on all local path dependencies final upgradeParser = ArgParser() ..addFlag('upgrade', defaultsTo: false) ..addFlag('get', defaultsTo: false); final upgradeArgs = upgradeParser.parse(['--upgrade']); await command.execute(upgradeArgs); // Execute flutter pub get on all local path dependencies final getArgs = upgradeParser.parse(['--get']); await command.execute(getArgs); // Result: Runs 'flutter pub upgrade' or 'flutter pub get' in each directory: // - packages/chat_bottom_container // - packages/getx_helper // Only for dependencies with path: configuration (ignores git/version deps) } ``` -------------------------------- ### Configure Build Type and Paths (CMake) Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/apps/app_a/linux/CMakeLists.txt Configures build-related settings, including the installation prefix and RPATH for bundled libraries. It also handles setting the CMAKE_BUILD_TYPE to Debug if not already specified and configures sysroot for cross-compiling. ```cmake # 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() ``` -------------------------------- ### CMake Build Configuration for Executable Target Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/apps/app_a/linux/runner/CMakeLists.txt Defines the main executable target for the project, specifying source files and linking necessary libraries. It also sets up include directories and preprocessor definitions for the application ID. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) # Define the application target. To change its name, change BINARY_NAME in the # top-level CMakeLists.txt, 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 preprocessor definitions for the application ID. add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") # Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Configure Flutter Application Build with CMake Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/linux/runner/CMakeLists.txt This snippet sets up the CMake build environment for a Flutter application. It defines the project, the main executable target, includes source files, applies standard build settings, adds preprocessor definitions for the application ID, and links necessary libraries (flutter and GTK). ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) # Define the application target. To change its name, change BINARY_NAME in the # top-level CMakeLists.txt, 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 preprocessor definitions for the application ID. add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") # Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### CMake Project Initialization and Basic Settings Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/example/windows/CMakeLists.txt Initializes the CMake project, sets the minimum version, defines the project name and languages, and configures the executable name. It also includes policies to opt into modern CMake behaviors and handles multi-configuration generators. ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) set(BINARY_NAME "example") cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Applying Standard Compilation Settings in CMake Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/example/linux/CMakeLists.txt Defines a CMake function to apply common compilation settings to targets, including C++ standard version, warning flags, optimization levels, and preprocessor definitions based on the build configuration. ```cmake 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() ``` -------------------------------- ### CMake Unicode and Standard Compiler Settings Function Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/example/windows/CMakeLists.txt Adds definitions for Unicode support and defines a function `APPLY_STANDARD_SETTINGS` to apply common compilation features and options to targets. This includes C++17 standard, warning levels, exception handling, and debug definitions. ```cmake add_definitions(-DUNICODE -D_UNICODE) function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$:_DEBUG") endfunction() ``` -------------------------------- ### CMake: Find and Link System Libraries for Flutter GTK Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/apps/app_a/linux/flutter/CMakeLists.txt This snippet finds necessary system libraries (GTK, GLIB, GIO) using PkgConfig and sets up the Flutter interface library. It includes specifying include directories and linking against the found libraries and the Flutter engine library (`libflutter_linux_gtk.so`). ```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) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Integrating Flutter and System Dependencies in CMake Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/example/linux/CMakeLists.txt Includes the Flutter build directory and finds PkgConfig modules, specifically checking for GTK. It then adds the 'runner' subdirectory for application-specific build rules and defines dependencies on Flutter assembly. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_subdirectory("runner") add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Melos Integration Scripts for Workspace Operations (Bash) Source: https://context7.com/linxunfeng/local_pub_workspace/llms.txt These Melos commands provide convenient shortcuts for common workspace operations. They automate tasks such as bootstrapping the workspace, cleaning dependencies, upgrading packages, updating VSCode configurations and analysis options, managing pubspec_overrides.yaml files, and executing dependency override commands. ```bash # Bootstrap workspace and run all post-hooks melos prepare # Clean workspace dependencies melos clean # Upgrade all packages in workspace melos run pub_upgrade # Update VSCode launch.json melos run update_launch_json # Update VSCode settings.json melos run update_settings_json # Update analysis_options.yaml files melos run update_analysis_options_yaml # Update app pubspec_overrides.yaml melos run update_app_pubspec_overrides # Restore app pubspec_overrides.yaml melos run restore_app_pubspec_overrides # Execute flutter pub get on dependency_overrides paths melos run deps_overrides_get # Execute flutter pub upgrade on dependency_overrides paths melos run deps_overrides_upgrade # Setup workspace dependencies melos run setup_workspace # Setup non-workspace mode melos run setup_workspace_no ``` -------------------------------- ### CMake: Custom command for Flutter tool backend Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/linux/flutter/CMakeLists.txt Defines a custom command that executes the Flutter tool backend script. This command is designed to run every time by outputting a dummy file `_phony_`. It sets necessary environment variables and passes build parameters to the tool. The output of this command includes the Flutter library and its headers. ```cmake # _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. 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 ) ``` -------------------------------- ### Apply Standard Build Settings in CMake Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/windows/runner/CMakeLists.txt Applies a predefined set of standard build settings to the specified target. This simplifies configuration for projects that adhere to common build practices. It can be customized or removed for applications with unique build requirements. ```cmake # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### CMake: Find and link system libraries (GTK, GLIB, GIO) Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/linux/flutter/CMakeLists.txt Uses PkgConfig to find and check for the presence of GTK, GLIB, and GIO libraries. It then imports these as targets and links them to the Flutter library. This ensures that the necessary system dependencies for a GTK application are available. ```cmake # System-level dependencies. 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) ``` -------------------------------- ### Standard Compilation Settings Function Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/windows/CMakeLists.txt Defines a reusable function `APPLY_STANDARD_SETTINGS` to apply common compilation features and options to targets, including C++17 standard, warning levels, exception handling, and debug definitions. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Project and Executable Configuration (CMake) Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/apps/app_a/linux/CMakeLists.txt Sets up the basic project structure and configuration for a CMake project. It specifies the minimum required CMake version, the project name, supported languages, and defines the executable name and GTK application ID. ```cmake # Project-level configuration. cmake_minimum_required(VERSION 3.13) 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 "app_a") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "com.example.app_a") ``` -------------------------------- ### Main CLI Tool for Workspace Management (Bash) Source: https://context7.com/linxunfeng/local_pub_workspace/llms.txt This set of bash commands utilizes the main Dart CLI tool to manage various aspects of the Flutter workspace. It allows for updating VSCode settings and launch configurations, updating analysis options, managing app-specific pubspec_overrides.yaml files, setting up the workspace, and executing dependency override commands. ```bash # Update VSCode settings.json with workspace configuration dart tool/main.dart update-settings # Update VSCode launch.json with debug configurations dart tool/main.dart update-launch # Update analysis_options.yaml across workspace dart tool/main.dart update-analysis # Update app pubspec_overrides.yaml files dart tool/main.dart update-app-pubspec-overrides # Restore app pubspec_overrides.yaml to original state dart tool/main.dart update-app-pubspec-overrides --restore # Setup workspace (delete pubspec_overrides.yaml) dart tool/main.dart setup-workspace # Setup non-workspace mode (create pubspec_overrides.yaml) dart tool/main.dart setup-workspace --no-workspace # Execute flutter pub get on local dependencies dart tool/main.dart dependency-overrides --get # Execute flutter pub upgrade on local dependencies dart tool/main.dart dependency-overrides --upgrade # Enable verbose output dart tool/main.dart update-settings --verbose ``` -------------------------------- ### Configuring Runtime Output Directory in CMake Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/example/linux/CMakeLists.txt Sets the runtime output directory for the main binary to a specific intermediate location to prevent users from running unbundled copies. This ensures the executable is placed correctly for proper resource loading. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Profile Build Mode Settings Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/windows/CMakeLists.txt Configures linker and compiler flags for the 'Profile' build mode, inheriting settings from the 'Release' configuration to ensure consistent performance optimization. ```cmake set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Plugin Integration Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/windows/CMakeLists.txt Includes the generated_plugins.cmake file, which manages the building of plugins and integrates them into the application, ensuring all necessary native dependencies are included. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Manage Workspace Dependency Resolution with SetupWorkspaceCommand Source: https://context7.com/linxunfeng/local_pub_workspace/llms.txt The SetupWorkspaceCommand manages pubspec_overrides.yaml files across the workspace to control dependency resolution. It can either remove these files to enable natural workspace resolution or create them with specific 'resolution:' settings to force non-workspace behavior for certain projects. It depends on 'dart:io', 'package:args', and 'tool/core/workspace_manager'. ```dart import 'dart:io'; import 'package:args/args.dart'; import 'tool/commands/setup_workspace.dart'; import 'tool/core/workspace_manager.dart'; void main() async { final workspaceManager = WorkspaceManager( rootDir: Directory.current, verbose: true, ); final command = SetupWorkspaceCommand(workspaceManager); // Delete mode: Remove pubspec_overrides.yaml from workspace projects // Allows workspace resolution to work naturally final deleteParser = ArgParser() ..addFlag('workspace', defaultsTo: true) ..addFlag('no-workspace', defaultsTo: false); final deleteArgs = deleteParser.parse(['--workspace']); await command.execute(deleteArgs); // Create mode: Delete and recreate pubspec_overrides.yaml with 'resolution:' // Forces non-workspace behavior for specific projects final createParser = ArgParser() ..addFlag('workspace', defaultsTo: true) ..addFlag('no-workspace', defaultsTo: false); final createArgs = createParser.parse(['--no-workspace']); await command.execute(createArgs); // Result: All workspace paths now have pubspec_overrides.yaml with: // resolution: } ``` -------------------------------- ### Configure Flutter Library and Headers (CMake) Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/apps/app_a/windows/flutter/CMakeLists.txt Sets up the Flutter library and its associated header files. It defines the path to the Flutter DLL, ICU data file, and project build directory. This configuration is essential for linking against the Flutter engine. ```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") # Set fallback configurations for older versions of the flutter tool. if (NOT DEFINED FLUTTER_TARGET_PLATFORM) set(FLUTTER_TARGET_PLATFORM "windows-x64") endif() # === 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) ``` -------------------------------- ### Flutter Build Integration and System Dependencies in CMake Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/linux/CMakeLists.txt Includes the Flutter managed directory and finds system-level dependencies like GTK using PkgConfig. It also adds the application runner subdirectory and establishes a dependency on the flutter_assemble target. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_subdirectory("runner") add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Configure Flutter Tool Backend Command (CMake) Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/apps/app_a/windows/flutter/CMakeLists.txt Sets up a custom command to invoke the Flutter tool backend. This command is responsible for generating necessary build artifacts, including the Flutter library and headers. A phony target is used to ensure the command runs on every build. ```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} ) ``` -------------------------------- ### Build Flutter C++ Wrapper for Plugins (CMake) Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/example/windows/flutter/CMakeLists.txt This snippet defines a static library 'flutter_wrapper_plugin' for use in Flutter plugins. It includes core C++ wrapper sources and plugin-specific sources, applies standard build settings, and configures properties like position-independent code and C++ visibility. It links against the 'flutter' library and sets include directories. ```cmake # === Wrapper === list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/.") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/.") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/.") # Wrapper sources needed for a plugin. add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Find and Link GTK, GLIB, GIO Packages in CMake Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/example/linux/flutter/CMakeLists.txt This CMake code uses PkgConfig to find and check for the presence of GTK, GLIB, and GIO system libraries. It then defines imported targets for these packages, which can be used later 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) ``` -------------------------------- ### CMake: Build Flutter C++ Wrapper for Plugins Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/windows/flutter/CMakeLists.txt This snippet defines a static library target 'flutter_wrapper_plugin' for the C++ client wrapper used by Flutter plugins. It includes core wrapper sources, plugin-specific sources, and links against the main Flutter library. ```cmake # === Wrapper === list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/ ") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/ ") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/ ") # Wrapper sources needed for a plugin. add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Configure Flutter Library and Headers (CMake) Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/example/windows/flutter/CMakeLists.txt This snippet configures the Flutter library and its associated headers for a Windows build. It sets the path to the Flutter library DLL and ICU data file, along with project build directories and AOT library paths. It also defines the interface library 'flutter' and links the Flutter DLL. ```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") # Set fallback configurations for older versions of the flutter tool. if (NOT DEFINED FLUTTER_TARGET_PLATFORM) set(FLUTTER_TARGET_PLATFORM "windows-x64") endif() # === 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) ``` -------------------------------- ### Integrate Flutter and System Dependencies (CMake) Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/apps/app_a/linux/CMakeLists.txt Integrates Flutter build components and system-level dependencies into the CMake build process. It adds the Flutter managed directory as a subdirectory and finds the necessary GTK+ 3.0 libraries using PkgConfig. ```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) # Application build; see runner/CMakeLists.txt. add_subdirectory("runner") # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Workspace Configuration (YAML) Source: https://context7.com/linxunfeng/local_pub_workspace/llms.txt This YAML configuration within pubspec.yaml defines the structure and behavior of the local Flutter workspace. It specifies which packages are included in the workspace for unified dependency resolution and analysis context, and it can optionally define dependency overrides. ```yaml name: local_pub_workspace publish_to: none environment: sdk: ^3.6.0 dev_dependencies: melos: 7.0.0-dev.8 args: ^2.5.0 path: ^1.9.0 yaml: ^3.1.2 yaml_edit: ^2.2.1 io: ^1.0.4 collection: ^1.18.0 # Workspace configuration for unified analysis context workspace: - apps/app_a - packages/package_a - packages/package_a/example # Optional: Override dependencies for independent analysis # dependency_overrides: # scrollview_observer: ^1.26.2 # chat_bottom_container: # path: packages/chat_bottom_container # package_from_git: # git: # url: https://github.com/user/repo.git # ref: main melos: scripts: prepare: melos bootstrap command: bootstrap: hooks: post: | melos run update_settings_json melos run update_launch_json melos run update_analysis_options_yaml melos run deps_overrides_upgrade ``` -------------------------------- ### Build C++ Wrapper for Application Runner (CMake) Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/apps/app_a/windows/flutter/CMakeLists.txt Compiles the C++ wrapper library for the Flutter application runner. It includes core implementations and application-specific sources like the Flutter engine and view controller. This is used by the main application to embed and run Flutter. ```cmake # Wrapper sources needed for the runner. add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Link Libraries and Include Directories in CMake Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/windows/runner/CMakeLists.txt Configures the build target by linking necessary libraries and specifying include directories. This allows the application to use external libraries like 'flutter' and 'flutter_wrapper_app', and access header files from the source directory. ```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}") ``` -------------------------------- ### CMake Build Type and Compilation Settings Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_a/example/linux/CMakeLists.txt Defines the build type (Debug, Profile, Release) if not already set and applies standard compilation settings to targets. These include C++ standard version, warning flags, optimization levels, and preprocessor definitions. ```cmake 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() 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() ``` -------------------------------- ### Build C++ Wrapper for Plugins (CMake) Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/apps/app_a/windows/flutter/CMakeLists.txt Compiles the C++ wrapper library for Flutter plugins. It includes core implementation sources and plugin-specific registration sources. This library facilitates communication between the Flutter Dart code and native C++ plugins. ```cmake # === Wrapper === list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") # Wrapper sources needed for a plugin. add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Configure Flutter Library and Headers in CMake Source: https://github.com/linxunfeng/local_pub_workspace/blob/main/packages/package_b/example/linux/flutter/CMakeLists.txt This CMake snippet defines the path to the Flutter Linux GTK shared library and ICU data file. It also sets up include directories for Flutter headers and links the necessary system libraries (GTK, GLIB, GIO) to a Flutter interface library. ```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) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ```