### Install Application Executable to Bundle Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Installs the main application executable target to the installation prefix directory as part of the 'Runtime' component. ```CMake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Define Installation Directories within Bundle Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Sets variables for the 'data' and 'lib' subdirectories within the installation prefix, which are used as destinations for installing application resources and libraries. ```CMake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Install Application Components (CMake) Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/CMakeLists.txt Defines the installation rules for the application, including the executable target, ICU data file, Flutter library, bundled plugin libraries, native assets, and the Flutter assets directory, copying them to the configured installation paths. ```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) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() # Copy the native assets provided by the build.dart from all packages. set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") 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. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Configure Installation Prefix for Bundle Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Sets the default installation prefix to a 'bundle' directory within the build directory if it hasn't been explicitly set, defining where the final application bundle will be created. ```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 Bundled Plugin Libraries Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Iterates through a list of bundled plugin libraries and installs each one to the 'lib' directory within the bundle. ```CMake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Initial CMake Configuration and Ephemeral Directory Setup Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/flutter/CMakeLists.txt Sets the minimum required CMake version and defines the path to the ephemeral directory where generated files are located. It also includes a generated configuration file. ```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) ``` -------------------------------- ### Install Flutter Engine Library Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Installs the main Flutter engine library file to the 'lib' directory within the bundle. ```CMake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installing Flutter Assets Directory - CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Installs the built Flutter asset directory from the project build location into the specified destination directory within the install bundle, marked for the Runtime component. ```CMake install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"\n DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Initialize CMake Project for Flutter Desktop Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Sets the minimum required CMake version and defines the project name and enabled languages. This is the standard starting point for any CMake project. ```CMake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) ``` -------------------------------- ### Clean Build Bundle Directory on Install Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Defines an installation step that uses CMake code to recursively remove the contents of the build bundle directory before installing new files, ensuring a clean bundle each time. ```CMake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Removing Previous Flutter Assets During Install - CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Uses an install(CODE) block to execute CMake script code during installation, specifically removing any existing Flutter asset directory from a previous build to ensure a clean install. ```CMake install(CODE "\n file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")\n " COMPONENT Runtime) ``` -------------------------------- ### Configure Installation Paths (CMake) Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/CMakeLists.txt Sets various CMake variables to define the destination directories for installing the application executable, data files, and libraries, typically placing them within the build output directory. ```CMake # === Installation === # Support files are copied into place next to the executable, so that it can # run in place. This is done instead of making a separate bundle (as on Linux) # so that building and running from within Visual Studio will work. set(BUILD_BUNDLE_DIR "$") # Make the "install" step default, as it's required to run. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Install Native Assets to Bundle Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Sets a variable for the directory containing native assets built by the build.dart script and installs the entire directory content to the 'lib' directory within the bundle. ```CMake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" ``` -------------------------------- ### Install Flutter ICU Data File Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Installs the Flutter International Components for Unicode (ICU) data file to the 'data' directory within the bundle. ```CMake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Conditionally Installing AOT Library - CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Checks if the current CMake build type is *not* 'Debug'. If it's a release or profile build, it installs the Ahead-Of-Time (AOT) compiled Flutter library into the bundle's library directory for the Runtime component. ```CMake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")\n install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"\n COMPONENT Runtime)\nendif() ``` -------------------------------- ### Set Flutter Library and Data File Paths Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/flutter/CMakeLists.txt Defines CMake variables for the paths to the Flutter engine library, the ICU data file, the project build directory, and the AOT application library. These variables are set in the parent scope for use in installation steps. ```CMake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) ``` -------------------------------- ### Initializing CMake and Paths Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/flutter/CMakeLists.txt Sets the minimum required CMake version, defines key directory variables for ephemeral build artifacts and the C++ wrapper, includes a generated configuration file, and provides a fallback value for the target platform if not already defined. ```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() ``` -------------------------------- ### Setting up the Flutter Tool Backend Command Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/flutter/CMakeLists.txt Defines a phony output file to force the custom command to run every time. It sets up a custom command that executes the Flutter tool backend script (`tool_backend.bat`) via `cmake -E env`, passing the target platform and configuration. This command is responsible for generating necessary build artifacts like the Flutter library and wrapper sources. ```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 ) ``` -------------------------------- ### Configure Runtime Path for Libraries Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Sets the CMAKE_INSTALL_RPATH to "$ORIGIN/lib", instructing the linker to look for bundled libraries in the 'lib' directory relative to the executable at runtime. ```CMake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Find System Dependencies with PkgConfig Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Uses PkgConfig to find required system libraries, specifically GTK+-3.0, and imports them as a target for linking. ```CMake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Project Initialization and Naming (CMake) Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/CMakeLists.txt Sets the minimum required CMake version, defines the project name and supported languages, and specifies the desired name for the output executable binary. ```CMake cmake_minimum_required(VERSION 3.14) project(fx_2_folder 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 "fx_2_folder") ``` -------------------------------- ### Configuring the App Wrapper Library Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/flutter/CMakeLists.txt Creates a STATIC library named `flutter_wrapper_app` using the core and app wrapper source files. It applies standard settings, links against the `flutter` interface library, includes the wrapper header directory, and adds a dependency on `flutter_assemble` to ensure build artifacts are ready. ```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) ``` -------------------------------- ### Defining C++ Wrapper Source Files Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/flutter/CMakeLists.txt Defines separate lists of C++ source files for the core, plugin, and app components of the C++ client wrapper. It then uses the `list(TRANSFORM ... PREPEND ...)` command to add the `WRAPPER_ROOT` path to the beginning of each file name in these lists. ```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}/") ``` -------------------------------- ### Configuring the Plugin Wrapper Library Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/flutter/CMakeLists.txt Creates a STATIC library named `flutter_wrapper_plugin` using the core and plugin wrapper source files. It applies standard settings, sets target properties for position-independent code and visibility, links against the `flutter` interface library, includes the wrapper header directory, and adds a dependency on `flutter_assemble`. ```CMake # 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 System Dependencies using PkgConfig Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/flutter/CMakeLists.txt Uses PkgConfig to find required system libraries: GTK 3.0, GLIB 2.0, and GIO 2.0. These are imported as CMake targets. ```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) ``` -------------------------------- ### Defining Application Executable and Sources - CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/runner/CMakeLists.txt Creates the main executable target named ${BINARY_NAME} (defined elsewhere), specifying it's a Windows application (WIN32). Lists all source files, resource files, and manifest files required to build the executable. ```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" ) ``` -------------------------------- ### Apply Standard Settings to Executable Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Calls the previously defined APPLY_STANDARD_SETTINGS function to apply common compilation flags and features to the main application executable target. ```CMake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Include Flutter Build Rules Subdirectory Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Sets a variable for the path to the Flutter managed directory and includes the CMakeLists.txt file within that directory, which contains rules for building Flutter-specific components. ```CMake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Link Libraries to Application Executable Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Links the required libraries (Flutter and GTK) to the application executable target. These libraries provide the necessary dependencies for the application to run. ```CMake target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Applying Standard Build Settings - CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/runner/CMakeLists.txt Calls a custom CMake function `apply_standard_settings` to apply a predefined set of build configurations to the specified target ${BINARY_NAME}. This function is likely defined in another CMake file. ```CMake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Define Application Executable Target Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Defines the main executable target for the application using the BINARY_NAME variable and lists the source files that comprise the executable. ```CMake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) ``` -------------------------------- ### Include Generated Plugin Build Rules Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Includes a CMake file generated by the Flutter tool that contains build rules for any plugins used by the application. ```CMake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Add Dependency on Flutter Assemble Step Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Ensures that the flutter_assemble target is built before the application executable, guaranteeing that Flutter assets and generated files are ready. ```CMake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Configuring the Flutter Interface Library Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/flutter/CMakeLists.txt Creates an INTERFACE library named `flutter`. This library specifies the include directories needed for compiling against the Flutter embedding headers and links against the Flutter library import file (`flutter_windows.dll.lib`). It also adds a dependency on the `flutter_assemble` target to ensure the necessary files are generated before compilation. ```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 Function to Apply Standard Build Settings Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Defines a CMake function APPLY_STANDARD_SETTINGS that applies common compilation features (C++14) and options (-Wall, -Werror, -O3 for non-Debug, NDEBUG for non-Debug) to a given 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() ``` -------------------------------- ### Configure Executable Output Directory Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Sets the RUNTIME_OUTPUT_DIRECTORY property for the executable to a subdirectory, preventing users from accidentally running the unbundled executable which lacks necessary resources. ```CMake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Include Flutter and Runner Subdirectories (CMake) Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/CMakeLists.txt Includes the CMakeLists.txt files located in the 'flutter' and 'runner' subdirectories, incorporating their build rules into the main project configuration. ```CMake # Flutter library and tool build rules. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) # Application build; see runner/CMakeLists.txt. add_subdirectory("runner") ``` -------------------------------- ### Linking Required Libraries - CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/runner/CMakeLists.txt Links necessary libraries to the target ${BINARY_NAME}. This includes Flutter-specific libraries (flutter, flutter_wrapper_app) and the Windows Desktop Window Manager API library (dwmapi.lib), which are required for the application to run. ```CMake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") ``` -------------------------------- ### Define Application Metadata in CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Sets variables for the executable binary name and the unique GTK application identifier. These variables are used throughout the build process and for application identification. ```CMake set(BINARY_NAME "fx_2_folder") set(APPLICATION_ID "com.example.fx_2_folder") ``` -------------------------------- ### Setting CMake Version and Project - CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/runner/CMakeLists.txt Specifies the minimum required CMake version (3.14) and defines the project name as "runner" with C++ as the primary language for the build. ```CMake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) ``` -------------------------------- ### Define Standard Compilation Settings Function (CMake) Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/CMakeLists.txt Defines a CMake function `APPLY_STANDARD_SETTINGS` that applies common compilation features (C++17) and options (warnings, exceptions, debug definitions) to a specified target. This function is intended for use by most project targets, including plugins. ```CMake # Compilation settings that should be applied to most targets. # # Be cautious about adding new options here, as plugins use this function by # default. In most cases, you should add new options to specific targets instead # of modifying this function. function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_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() ``` -------------------------------- ### List and Prepend Prefix to Flutter Library Headers Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/flutter/CMakeLists.txt Appends a list of Flutter library header filenames to the `FLUTTER_LIBRARY_HEADERS` variable. Then, it uses the custom `list_prepend` function to add the ephemeral directory path as a prefix to each header filename. ```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/") ``` -------------------------------- ### Define Flutter Interface Library Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/flutter/CMakeLists.txt Defines an `INTERFACE` library named `flutter`. This library specifies include directories and links to the generated Flutter engine library and the required system dependencies (GTK, GLIB, GIO). ```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 ) ``` -------------------------------- ### Adding Version Preprocessor Definitions - CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/runner/CMakeLists.txt Adds several preprocessor definitions (FLUTTER_VERSION, FLUTTER_VERSION_MAJOR, etc.) to the target ${BINARY_NAME}. These definitions make Flutter version information available in the C++ source code during compilation. ```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}") ``` -------------------------------- ### Define Custom Command for Flutter Tool Backend Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/flutter/CMakeLists.txt Defines a custom command that runs the Flutter tool backend script. This command is responsible for generating the Flutter engine library and headers. It uses a phony output file to ensure it runs every time. ```CMake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) ``` -------------------------------- ### Include Generated Plugin Rules (CMake) Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/CMakeLists.txt Includes the `generated_plugins.cmake` file, which contains build rules automatically generated for any Flutter plugins used by the application. ```CMake # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Define Preprocessor Macro for Application ID Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Adds a preprocessor definition APPLICATION_ID using the value set earlier, making the application ID available in the C++ source code. ```CMake add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Defining the Flutter Assemble Target Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/flutter/CMakeLists.txt Defines a custom target named `flutter_assemble`. This target depends on the outputs specified in the `add_custom_command` for the Flutter tool backend. This ensures that the custom command runs and generates the required Flutter library, headers, and wrapper source files before any other 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} ) ``` -------------------------------- ### Adding Source Include Directory - CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/runner/CMakeLists.txt Adds the main source directory (${CMAKE_SOURCE_DIR}) as a private include directory for the target ${BINARY_NAME}. This allows the compiler to find header files located directly in the project's source root. ```CMake target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Adding Flutter Assembly Dependency - CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/runner/CMakeLists.txt Establishes a build dependency, ensuring that the flutter_assemble target (which prepares Flutter assets and code) is built before the ${BINARY_NAME} executable target. This is crucial for integrating the Flutter build process with the native build. ```CMake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Define list_prepend CMake Function Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/flutter/CMakeLists.txt Defines a custom CMake function `list_prepend` that prepends a given prefix to each element in a list and updates the list in the parent scope. This is a workaround for `list(TRANSFORM ... PREPEND ...)` not being 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() ``` -------------------------------- ### CMake Policy and Build Type Configuration (CMake) Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/CMakeLists.txt Opts into modern CMake policies and configures build types (Debug, Profile, Release) based on whether the generator supports multiple configurations. It also sets profile build flags to match release flags. ```CMake # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(VERSION 3.14...3.25) # Define build configuration option. get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) elif(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 settings for the Profile build mode. 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 Dependency on flutter_assemble Target Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/flutter/CMakeLists.txt Adds a dependency to the `flutter` interface library on the `flutter_assemble` custom target. This ensures that the `flutter_assemble` target runs before the `flutter` library is configured, guaranteeing that the necessary generated files (like the engine library and headers) are available. ```CMake add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Defining Flutter Library Assets Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/flutter/CMakeLists.txt Defines CMake variables pointing to essential Flutter library files (DLL, ICU data, AOT library) and the project build directory. It also lists the required Flutter library header files and transforms the list to include the ephemeral directory path. These variables are set with PARENT_SCOPE for use in parent CMakeLists files. ```CMake # === 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}/") ``` -------------------------------- ### Set CMake Policy for Modern Behavior Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Explicitly opts into modern CMake behavior for policy CMP0063, which affects how target properties are handled. This helps avoid warnings with newer CMake versions. ```CMake cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Configure CMake for Cross-Compilation Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Sets CMake variables like CMAKE_SYSROOT and CMAKE_FIND_ROOT_PATH based on the FLUTTER_TARGET_PLATFORM_SYSROOT variable, which is used when cross-compiling for a specific target platform. ```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() ``` -------------------------------- ### Set Default CMake Build Type Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Configures the default CMAKE_BUILD_TYPE to "Debug" if it hasn't been set, and defines the allowed string values for this cache variable (Debug, Profile, 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 Custom Target flutter_assemble Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/flutter/CMakeLists.txt Defines 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 command is executed when `flutter_assemble` is built. ```CMake add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Setting Flutter Asset Directory Name - CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/linux/CMakeLists.txt Defines a CMake variable to hold the standard directory name for Flutter assets, making the path reusable throughout the script. ```CMake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") ``` -------------------------------- ### Disabling Windows NOMINMAX Macro - CMake Source: https://github.com/flutterfx/flutterfx_widgets/blob/main/windows/runner/CMakeLists.txt Adds the NOMINMAX preprocessor definition to the target ${BINARY_NAME}. This is a common practice on Windows to prevent conflicts between Windows header macros (like min and max) and C++ standard library functions. ```CMake 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.