### Install Application Bundle Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/CMakeLists.txt Configures the installation process to create a relocatable application bundle. It cleans the bundle directory, installs the executable, and copies necessary data and libraries. ```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(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 Application Executable Source: https://github.com/stacked-org/stacked/blob/master/example/router_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) ``` -------------------------------- ### Define Installation Directories Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Sets variables for the installation paths of data and library files within the bundle. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Installs any bundled libraries associated with plugins to the library directory. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Flutter Library Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Installs the main Flutter library file to the library directory within the bundle. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Assets Directory Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Removes and then installs the Flutter assets directory to ensure it's up-to-date. This is done on each build. ```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) ``` -------------------------------- ### Basic CMake Setup Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/flutter/CMakeLists.txt Sets the minimum CMake version and defines the ephemeral directory path. This is standard practice for CMake projects. ```cmake cmake_minimum_required(VERSION 3.14) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") ``` -------------------------------- ### Install AOT Library Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the data directory, but only for Profile and Release configurations. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Set Installation Prefix for Bundled App Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Configures the installation prefix to be next to the executable for running in place, essential for Visual Studio builds. ```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() ``` -------------------------------- ### Install ICU Data File Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Installs the ICU data file to the data directory within the bundle. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Set Installation RPATH Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/CMakeLists.txt Configures the runtime search path for libraries, ensuring bundled libraries in the 'lib' directory relative to the executable can be found. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Define Flutter library and headers Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/flutter/CMakeLists.txt Sets the path to the Flutter Linux GTK shared library and its header files. These are then made available to the parent scope for installation. ```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) ``` -------------------------------- ### Conditional AOT Library Installation in CMake Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/CMakeLists.txt Installs the AOT library to the runtime component directory only when the build type is not 'Debug'. This ensures that debug builds do not include the AOT library, potentially reducing build size or complexity for debugging purposes. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/runner/CMakeLists.txt Applies a predefined set of standard build settings to the application target. This can be customized for projects requiring different build configurations. ```cmake # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Enable Unicode Support Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Adds preprocessor definitions to enable Unicode support for all projects. ```cmake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Find GTK, GLIB, and GIO packages Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/flutter/CMakeLists.txt Uses PkgConfig to find and check for the required GTK, GLIB, and GIO libraries. These are essential system-level dependencies for Flutter on Linux with GTK. ```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 Cross-Building Sysroot Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/CMakeLists.txt Sets up the sysroot and search paths for cross-compiling Flutter applications to different Linux targets. ```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() ``` -------------------------------- ### Define C++ Wrapper Sources Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/flutter/CMakeLists.txt Lists and prepends source files for the C++ wrapper. These are categorized into core, plugin, and app-specific sources. ```cmake 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}/") ``` -------------------------------- ### Configure Build Configurations Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Sets the available build configurations (Debug, Profile, Release) based on whether the generator supports multi-configuration builds. ```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() ``` -------------------------------- ### Include Generated Plugins Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Includes the CMake script that manages the building and integration of generated plugins. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Define Application Executable Target Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/CMakeLists.txt Creates the main executable target for the application, listing its source files. New source files should be added here. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) ``` -------------------------------- ### Link Dependencies and Include Directories Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/runner/CMakeLists.txt Specifies the libraries and include directories required for the application. This includes Flutter core libraries, wrapper libraries, and Windows-specific libraries like dwmapi.lib. ```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 Flutter Wrapper Plugin Library Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/flutter/CMakeLists.txt Creates a static library target for the Flutter C++ wrapper used by plugins. It applies standard settings and sets visibility properties. ```cmake 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) ``` -------------------------------- ### Define Executable Name Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Sets the name for the application's executable file. This name will be used on disk. ```cmake set(BINARY_NAME "router_example") ``` -------------------------------- ### Include Generated Configuration Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/flutter/CMakeLists.txt Includes the generated configuration file provided by the Flutter tool. This file contains project-specific settings. ```cmake include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Create Flutter Wrapper App Library Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/flutter/CMakeLists.txt Creates a static library target for the Flutter C++ wrapper used by the application runner. It links against the Flutter library and sets include directories. ```cmake 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) ``` -------------------------------- ### Include Runner Subdirectory Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Adds the runner subdirectory, which contains the application's specific build rules. ```cmake add_subdirectory("runner") ``` -------------------------------- ### Link Application Dependencies Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/CMakeLists.txt Links the application executable against the Flutter library and GTK system libraries. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Custom command to assemble Flutter library Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/flutter/CMakeLists.txt Defines a custom command to run the Flutter tool backend script. This command generates the Flutter library and header files. The '_phony_' target ensures the command runs on every build. ```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 ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Create Flutter Interface Library Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/flutter/CMakeLists.txt Creates an interface library target for Flutter and sets its include directories and link libraries. This allows other targets to easily depend on Flutter. ```cmake 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 Web Entrypoint Loading Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/web/index.html This snippet shows the standard JavaScript code used to load the main Dart entrypoint for a Flutter web application. It includes service worker configuration and engine initialization. ```javascript var serviceWorkerVersion = null; window.addEventListener('load', function(ev) { // Download main.dart.js _flutter.loader.loadEntrypoint({ serviceWorker: { serviceWorkerVersion: serviceWorkerVersion, }, onEntrypointLoaded: function(engineInitializer) { engineInitializer.initializeEngine().then(function(appRunner) { appRunner.runApp(); }); } }); }); ``` -------------------------------- ### Define Profile Build Mode Settings Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Sets linker and compiler flags for the Profile build mode, typically inheriting from Release settings. ```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}") ``` -------------------------------- ### Set Runtime Output Directory Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/CMakeLists.txt Configures the output directory for the executable to a subdirectory within the build directory, preventing direct execution of unbundled copies. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Specifies the minimum required CMake version and names the C++ project. ```cmake cmake_minimum_required(VERSION 3.14) project(router_example LANGUAGES CXX) ``` -------------------------------- ### Include Flutter Subdirectory Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Adds the Flutter managed directory as a subdirectory for building Flutter-specific components. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Apply Standard Compilation Settings Function Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Defines a reusable function to apply common compilation features, options, and definitions to a target. ```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() ``` -------------------------------- ### Opt-in to Modern CMake Behaviors Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/CMakeLists.txt Explicitly enables modern CMake behaviors to prevent warnings in newer CMake versions. ```cmake cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Flutter Tool Backend Custom Command Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/flutter/CMakeLists.txt Defines a custom command to execute the Flutter tool backend script. This command generates build artifacts like DLLs and 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. 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 ) ``` -------------------------------- ### Define Flutter Library Headers Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/flutter/CMakeLists.txt Lists and prepends the Flutter library header files with the ephemeral directory path. These are used for compiling against the Flutter library. ```cmake 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}/") ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/CMakeLists.txt Defines a function to apply common compilation features and options to targets, including C++14 standard, warnings, and optimization levels. ```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() ``` -------------------------------- ### Add Preprocessor Definitions for Build Version Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/runner/CMakeLists.txt Adds preprocessor definitions to the build configuration, embedding Flutter version information directly into the compiled executable. This allows runtime access to version details. ```cmake # Add preprocessor definitions for the build version. target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") ``` -------------------------------- ### Define list_prepend function for CMake < 3.10 Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/flutter/CMakeLists.txt This function prepends a prefix to each element in a list. It is used because the list(TRANSFORM ... PREPEND ...) command is not available in CMake version 3.10. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Define Application Identifier Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/CMakeLists.txt Sets the unique GTK application identifier. This is crucial for application registration and integration within the GNOME desktop environment. ```cmake set(APPLICATION_ID "com.example.router_example") ``` -------------------------------- ### Add Flutter library interface target Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/flutter/CMakeLists.txt Creates an INTERFACE library target for Flutter, including its header directories and linking against system libraries (GTK, GLIB, GIO) and the Flutter library itself. It also adds a dependency on the flutter_assemble target. ```cmake 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) ``` -------------------------------- ### Define Flutter Library Paths Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/flutter/CMakeLists.txt Sets variables for the Flutter library and ICU data file paths. These are essential for linking and runtime. ```cmake 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) ``` -------------------------------- ### Add Flutter Tool Build Dependency Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/runner/CMakeLists.txt Ensures that the Flutter tool's assembly process (`flutter_assemble`) is completed before the runner executable is built. This is a mandatory step for Flutter applications. ```cmake # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Set Default Build Type Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/CMakeLists.txt Ensures a build type (Debug, Profile, or Release) is set if none is explicitly provided, defaulting to 'Debug'. ```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() ``` -------------------------------- ### Flutter Assemble Custom Target Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/flutter/CMakeLists.txt Creates a custom target 'flutter_assemble' that depends on the output of the Flutter tool backend command. This ensures build artifacts are generated before they are needed. ```cmake add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Define Executable Target Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/runner/CMakeLists.txt Defines the main executable target for the Windows runner application. Source files and resources are listed here. The binary name is controlled by the top-level CMakeLists.txt to ensure `flutter run` compatibility. ```cmake cmake_minimum_required(VERSION 3.14) 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} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ``` -------------------------------- ### Add Flutter Assemble Dependency Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/linux/CMakeLists.txt Ensures that the Flutter assembly process is completed before the application target is built. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Disable Conflicting Windows Macros Source: https://github.com/stacked-org/stacked/blob/master/example/router_example/windows/runner/CMakeLists.txt Disables Windows-specific macros (NOMINMAX) that might conflict with standard C++ library functions, preventing potential naming collisions. ```cmake # Disable Windows macros that collide with C++ standard library functions. target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.