### Installing Application Executable in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Installs the main application executable to the specified installation prefix. ```CMake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Installing Application Binary Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Installs the application's executable binary to the installation prefix as part of the Runtime component. ```CMake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Installing Flutter Library in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Installs the main Flutter library file to the library directory within the installation prefix. ```CMake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installing Flutter Library Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Installs the main Flutter library file to the library directory within the application bundle. ```CMake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Configuring Installation Paths and Defaults in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Sets the build bundle directory based on the target executable's location, makes the 'install' step default in Visual Studio, and sets the default installation prefix to the build bundle directory. ```CMake 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}") ``` -------------------------------- ### Installing Flutter Assets Directory in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Removes any existing installed assets directory to ensure a clean copy, then installs the Flutter assets directory from the build output to the data directory within the installation prefix. ```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) ``` -------------------------------- ### Installing Bundled Plugin Libraries Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Iterates through a list of bundled plugin libraries and installs each one to the library directory within the application bundle. ```CMake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Setting Installation Prefix for Bundle Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Defines the default installation prefix to be a "bundle" subdirectory within the build directory, creating a relocatable application 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() ``` -------------------------------- ### Initial CMake Setup Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/flutter/CMakeLists.txt Sets the minimum required CMake version and defines the path to the ephemeral build directory. It then includes a generated configuration file provided by the Flutter tool. ```CMake cmake_minimum_required(VERSION 3.10) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Installing Flutter Single Instance Package (YAML) Source: https://github.com/necodeit/flutter_single_instance/blob/main/README.md Command to add the `flutter_single_instance` package as a dependency to your Flutter project using `flutter pub add`. This updates the `pubspec.yaml` file. ```yaml flutter pub add flutter_single_instance ``` -------------------------------- ### Installing AOT Library for Profile/Release in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the data directory within the installation prefix, but only for Profile and Release build configurations. ```CMake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Installing Flutter Assets Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Defines the name for the Flutter assets directory, cleans the destination directory in the bundle, and then copies the built assets into the 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) ``` -------------------------------- ### Setting Bundle Data and Library Directories Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Defines variables for the standard data and library subdirectories within the installation bundle prefix. ```CMake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Installing Native Assets Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Sets the path to the built native assets directory and installs its contents to the library directory within the application bundle. ```CMake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Checking for Existing Instance and Focusing (Dart) Source: https://github.com/necodeit/flutter_single_instance/blob/main/README.md Example Dart code demonstrating how to use `flutter_single_instance` in the `main` function. It checks if the current instance is the first one and either runs the app or focuses the existing instance and exits. ```dart import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_single_instance/flutter_single_instance.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await windowManager.ensureInitialized(); if (await FlutterSingleInstance().isFirstInstance()) { runApp(const MyApp()); } else { print("App is already running"); final err = await FlutterSingleInstance().focus(); if (err != null) { print("Error focusing running instance: $err"); } exit(0); } } ``` -------------------------------- ### Installing Plugin Bundled Libraries in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Conditionally installs any bundled plugin libraries to the library directory within the installation prefix if they exist. ```CMake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Installing AOT Library (Non-Debug) Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the bundle's library directory, but only for non-Debug build configurations (Profile or Release). ```CMake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Installing Native Assets in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Copies the directory containing native assets provided by the build.dart script to the library directory within the installation prefix. ```CMake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installing Flutter ICU Data File in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Installs the Flutter ICU data file to the data directory within the installation prefix. ```CMake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installing Flutter ICU Data Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Installs the Flutter ICU data file to the data directory within the application bundle. ```CMake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Cleaning Build Bundle Directory Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Adds an installation step to recursively remove the contents of the build bundle directory before installing new files, ensuring a clean bundle. ```CMake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Define Flutter Wrapper App Static Library Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/flutter/CMakeLists.txt Creates a STATIC library containing the core and application C++ wrapper sources. It applies standard settings, links against the 'flutter' interface library, adds the wrapper include directory, and adds a dependency on the 'flutter_assemble' target. ```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) ``` -------------------------------- ### Configure Flutter Desktop C++ Runner Build (CMake) Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/runner/CMakeLists.txt This CMake script sets the minimum required CMake version, defines the project name and language, specifies the executable target with its source files, applies standard build settings, adds preprocessor definitions for the application ID, links required libraries (flutter and GTK), and includes necessary source directories for the build. ```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}") ``` -------------------------------- ### Including Flutter Build Rules Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Sets the path to the Flutter managed directory and includes its CMakeLists.txt file as a subdirectory to incorporate Flutter build rules. ```CMake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Define Flutter Wrapper Plugin Static Library Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/flutter/CMakeLists.txt Creates a STATIC library containing the core and plugin C++ wrapper sources. It applies standard settings, sets properties for position-independent code and visibility, links against the 'flutter' interface library, and adds a dependency on the 'flutter_assemble' target. ```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) ``` -------------------------------- ### Find System Dependencies (GTK, GLIB, GIO) Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/flutter/CMakeLists.txt Uses PkgConfig to find required system libraries: GTK 3.0, GLIB 2.0, and GIO 2.0. These libraries are essential for the Flutter Linux desktop embedding. ```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) ``` -------------------------------- ### Applying Standard Build Settings Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/runner/CMakeLists.txt Applies a predefined set of standard build settings to the specified target (${BINARY_NAME}). This command encapsulates common configurations and can be customized or removed if different settings are needed. ```CMake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Finding and Checking GTK Dependency Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Uses PkgConfig to find and check for the required GTK 3.0 library, creating an imported target for it. ```CMake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Define and Transform C++ Wrapper Source Lists Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/flutter/CMakeLists.txt Creates lists of C++ source files for the core, plugin, and application parts of the client wrapper. It then transforms each list by prepending the wrapper root directory path to the filenames. ```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}/") ``` -------------------------------- ### Linking Libraries and Including Directories Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/runner/CMakeLists.txt Links necessary libraries to the target (${BINARY_NAME}), including Flutter-specific libraries ('flutter', 'flutter_wrapper_app') and Windows API libraries ('dwmapi.lib'). It also adds the source directory (${CMAKE_SOURCE_DIR}) to the include paths. ```CMake 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}") ``` -------------------------------- ### Configuring macOS Entitlements for Single Instance (XML) Source: https://github.com/necodeit/flutter_single_instance/blob/main/README.md XML configuration required in `DebugProfile.entitlements` and `Release.entitlements` files on macOS to disable sandboxing and enable network access for the single instance functionality. This allows the app to listen for and send focus requests. ```xml com.apple.security.app-sandbox com.apple.security.network.server com.apple.security.network.client ``` -------------------------------- ### Define and Configure Flutter Interface Library Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/flutter/CMakeLists.txt Defines an INTERFACE library target named `flutter`. It specifies the include directories and links the necessary libraries, including the Flutter engine library and the previously found system dependencies (GTK, GLIB, GIO). It also adds a dependency on the `flutter_assemble` target. ```CMake 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) ``` -------------------------------- ### Setting Binary Output Directory Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Configures the runtime output directory for the application binary to a subdirectory to prevent users from running the unbundled executable directly. ```CMake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Including Generated Plugin Rules Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Includes the CMake file generated by the Flutter tool that contains build rules for any detected plugins. ```CMake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Including Generated Plugins CMake File Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Includes the `generated_plugins.cmake` file, which contains build rules and configurations for any plugins used by the Flutter application. ```CMake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Configuring Basic Project Settings in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Sets the minimum required CMake version, defines the project name and languages, and specifies the desired executable name for the application. ```CMake cmake_minimum_required(VERSION 3.14) project(example 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") ``` -------------------------------- ### Setting Runtime Path for Libraries Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Configures the runtime search path for bundled libraries to be relative to the executable. ```CMake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Defining Executable Target and Source Files Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/runner/CMakeLists.txt Defines the main executable target for the Windows application using the variable ${BINARY_NAME}. It lists all the source files required to build the executable, including C++, resource, and manifest files. ```CMake 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" ) ``` -------------------------------- ### Setting Binary Name and Application ID Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Defines the output executable name and the unique GTK application identifier for the application. ```CMake set(BINARY_NAME "example") set(APPLICATION_ID "com.example.example") ``` -------------------------------- ### Setting Minimum CMake Version and Project Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Specifies the minimum required version of CMake and defines the project name and enabled languages. ```CMake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) ``` -------------------------------- ### Define Custom Command for Flutter Tool Backend Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/flutter/CMakeLists.txt Sets up a custom command that invokes the Flutter tool backend script. This command is responsible for generating necessary build artifacts. A phony output is used to ensure the command runs every time. ```CMake 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 ) ``` -------------------------------- ### Defining Standard Compilation Settings Function Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Defines a CMake function to apply standard compilation settings (C++14, warnings, optimization, NDEBUG) to a specified target. ```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() ``` -------------------------------- ### Configuring Sysroot for Cross-Building Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Sets the CMake sysroot and find root path modes when cross-building is enabled via FLUTTER_TARGET_PLATFORM_SYSROOT. ```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() ``` -------------------------------- ### Setting CMake Policy CMP0063 Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Explicitly opts into modern CMake behavior for policy CMP0063 to avoid warnings with recent CMake versions. ```CMake cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Setting Minimum CMake Version and Project Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/runner/CMakeLists.txt Specifies the minimum required CMake version for the project and defines the project name ('runner') and the primary language used ('CXX'). This is typically the first command in a CMakeLists.txt file. ```CMake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) ``` -------------------------------- ### Adding Unicode Definitions in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Adds preprocessor definitions to enable Unicode support for all projects. ```CMake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Add Custom Commands for Flutter Tool Backend Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/flutter/CMakeLists.txt Adds a custom command that invokes the Flutter tool backend script to generate build artifacts like the Flutter engine library and headers. It uses a phony output file to ensure the command runs every time. A custom target `flutter_assemble` is defined with dependencies on the generated artifacts, ensuring they are built before targets that depend on `flutter_assemble`. ```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. 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} ) ``` -------------------------------- ### Define and Transform Flutter Library Headers List Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/flutter/CMakeLists.txt Creates a list of required Flutter library header files and then transforms the list by prepending the ephemeral directory path to each header file name. ```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}/") ``` -------------------------------- ### Including Runner Subdirectory Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Adds the "runner" subdirectory to the build, which typically contains the application's main source code and its CMakeLists.txt. ```CMake add_subdirectory("runner") ``` -------------------------------- ### Include Generated Configuration Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/flutter/CMakeLists.txt Includes a CMake configuration file generated by the Flutter tool. This file typically contains build-specific settings and paths determined by the Flutter build process. ```CMake include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Adding Dependency on Flutter Assemble Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Ensures that the main application binary depends on the `flutter_assemble` target, which handles the Flutter build process. ```CMake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Define and Prefix Flutter Library Headers Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/flutter/CMakeLists.txt Appends a list of Flutter library header files to the `FLUTTER_LIBRARY_HEADERS` variable. It then uses the custom `list_prepend` function to add the ephemeral directory path as a prefix to each header file name. ```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/") ``` -------------------------------- ### Set C++ Wrapper Root Directory Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/flutter/CMakeLists.txt Defines a variable pointing to the root directory of the C++ client wrapper code, which provides the interface between the native application and the Flutter engine. ```CMake set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") ``` -------------------------------- ### Adding Compile Definitions Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/runner/CMakeLists.txt Adds preprocessor definitions to the target (${BINARY_NAME}). This includes defining Flutter version information (major, minor, patch, build) and disabling the Windows NOMINMAX macro to prevent conflicts with C++ standard library functions. ```CMake 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}") target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` -------------------------------- ### Adding Application Runner Subdirectory in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Includes the 'runner' directory as a subdirectory, which typically contains the platform-specific entry point and build logic for the application executable. ```CMake add_subdirectory("runner") ``` -------------------------------- ### Adding Build Dependencies Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/runner/CMakeLists.txt Adds a dependency on the 'flutter_assemble' target for the executable target (${BINARY_NAME}). This ensures that the Flutter tool's build steps are completed before the application executable is built. ```CMake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Defining Standard Compile Settings Function in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Defines a CMake function `APPLY_STANDARD_SETTINGS` that applies common compilation settings to a specified target, including C++ 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() ``` -------------------------------- ### Adding Flutter Subdirectories in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Sets the path to the Flutter managed directory and includes it as a subdirectory in the build, incorporating Flutter's build rules. ```CMake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Open iOS Project in Xcode Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md This command opens the iOS part of your Flutter project in Xcode. This is necessary to access and modify the project's assets, including the launch screen images, using Xcode's graphical interface. ```Shell open ios/Runner.xcworkspace ``` -------------------------------- ### Define list_prepend Function Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/flutter/CMakeLists.txt Defines a custom CMake function `list_prepend` that adds a specified prefix to each element in a list. This function serves as a workaround for the `list(TRANSFORM ... PREPEND ...)` command which is not available in CMake 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() ``` -------------------------------- ### Setting CMake Policy Version Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Explicitly opts into modern CMake behaviors by setting the policy version range, avoiding warnings with recent CMake versions. ```CMake cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Configuring Profile Build Flags in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Sets the linker and compiler flags for the Profile build mode to match those of the Release build mode. ```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 Minimum CMake Version and Ephemeral Directory Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/flutter/CMakeLists.txt Specifies the minimum required CMake version for the project and defines a variable for the ephemeral build directory, which contains generated files. ```CMake cmake_minimum_required(VERSION 3.14) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") ``` -------------------------------- ### Setting Default Build Type Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/CMakeLists.txt Defines the default build type (Debug) if it's not already set, allowing selection between Debug, Profile, and Release. ```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() ``` -------------------------------- ### Define Flutter Interface Library Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/flutter/CMakeLists.txt Defines an INTERFACE library named 'flutter'. This library is used to specify include directories and link libraries required for interacting with the Flutter engine without adding source files directly to this target. ```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) ``` -------------------------------- ### Define Flutter Assemble Custom Target Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/flutter/CMakeLists.txt Creates a custom target named 'flutter_assemble'. This target depends on the outputs of the custom command that runs the Flutter tool backend, ensuring that the necessary build artifacts are generated before targets that depend on 'flutter_assemble' are built. ```CMake add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Set Fallback Flutter Target Platform Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/flutter/CMakeLists.txt Checks if the FLUTTER_TARGET_PLATFORM variable is defined (usually by the Flutter tool) and sets a default value ('windows-x64') if it is not, providing compatibility with older tool versions. ```CMake if (NOT DEFINED FLUTTER_TARGET_PLATFORM) set(FLUTTER_TARGET_PLATFORM "windows-x64") endif() ``` -------------------------------- ### Handling Build Configuration Types in CMake Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/CMakeLists.txt Detects if the generator supports multiple configurations and sets the available build types (Debug, Profile, Release) accordingly. If not a multi-config generator, it sets the default build type to Debug. ```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() ``` -------------------------------- ### Set and Export Flutter Library Paths Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/windows/flutter/CMakeLists.txt Defines variables for key Flutter build artifacts like the engine library, ICU data file, project build directory, and AOT library. These variables are then exported to the parent scope for use in other CMakeLists.txt files. ```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) ``` -------------------------------- ### Define Flutter Build Variables Source: https://github.com/necodeit/flutter_single_instance/blob/main/example/linux/flutter/CMakeLists.txt Sets various CMake variables pointing to key build artifacts like the Flutter engine library, ICU data file, project build directory, and the AOT compiled application library. These variables are published to the parent scope for use in other CMake files. ```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) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.