### Basic CMake Project Setup Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/CMakeLists.txt Initializes the CMake version, project name, and binary name. Sets the installation rpath for runtime libraries. ```cmake cmake_minimum_required(VERSION 3.15) project(zego_express_engine_example LANGUAGES CXX) set(BINARY_NAME "zego_express_engine_example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Installation Bundle Configuration Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Configures the installation prefix to create a relocatable bundle and ensures the build bundle directory is clean before installation. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Installation Rules Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/CMakeLists.txt Defines installation directories and components for the application binary, ICU data, Flutter library, bundled plugin libraries, and assets. Ensures assets are re-copied on each build. ```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(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() # 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) ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Installs Flutter assets by removing the existing directory and then copying the new assets. This is part of the Runtime component installation. ```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 Application Executable and Data Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Installs the application executable to the bundle's root and ICU data to the data directory. ```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) ``` -------------------------------- ### Basic CMake Setup Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/flutter/CMakeLists.txt Sets the minimum CMake version and defines a directory for ephemeral files. Includes generated configuration from the Flutter tool. ```cmake cmake_minimum_required(VERSION 3.15) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Installing Flutter Library and Bundled Libraries Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Installs the main Flutter library and any bundled plugin libraries to the bundle's lib directory. ```cmake 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) ``` -------------------------------- ### Installing Native Assets Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Installs native assets provided by build.dart from all packages into the bundle's lib directory. ```cmake # Copy the native assets provided by the build.dart from all packages. set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) # Fully re-copy the assets directory on each build to avoid having stale files ``` -------------------------------- ### Install AOT Library for Non-Debug Builds Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Installs the AOT (Ahead-Of-Time) compiled library only when the build type is not Debug. This ensures optimized performance for release builds. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Configure Flutter Library and Headers Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/flutter/CMakeLists.txt Sets variables for the Flutter library path, ICU data file, project build directory, and AOT library. These are published to the parent scope for use in installation steps. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) ``` -------------------------------- ### Flutter Library Configuration Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/flutter/CMakeLists.txt Defines the Flutter library path, ICU data file, project build directory, and AOT library path. These are published to the parent scope for installation. ```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) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/linux/CMakeLists.txt Applies standard build settings configured in the application-level CMakeLists.txt. This can be removed if the plugin requires full control over build settings. ```cmake apply_standard_settings(${PLUGIN_NAME}) ``` -------------------------------- ### System Dependencies and Application ID Definition Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Finds PkgConfig and checks for GTK, then defines the APPLICATION_ID preprocessor macro. ```cmake # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Include Additional Library Files (cacert.pem) Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/windows/CMakeLists.txt This section iterates through all files in the 'libs/x64' directory and specifically adds 'cacert.pem' to the list of bundled libraries. This is crucial for handling certificate-related operations within the ZegoExpress engine. ```cmake file(GLOB LIBRARY_FILES "${CMAKE_CURRENT_LIST_DIR}/libs/x64/*") foreach(LIB_FILE ${LIBRARY_FILES}) if(LIB_FILE MATCHES "cacert\.pem") # 添加库文件路径到变量 list(APPEND zego_express_engine_bundled_libraries ${LIB_FILE}) endif() endforeach() ``` -------------------------------- ### Find System Dependencies Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/flutter/CMakeLists.txt Uses PkgConfig to find and check for required GTK and GLib libraries (gtk+-3.0, glib-2.0, gio-2.0). These are essential for the GTK backend of the Flutter application. ```cmake # === Flutter Library === # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Configure Include Directories Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/linux/CMakeLists.txt Specifies the include directories for the plugin library. This includes public headers and platform-specific internal headers. ```cmake target_include_directories(${PLUGIN_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/libs/${FLUTTER_TARGET_PLATFORM}/include" "${CMAKE_CURRENT_SOURCE_DIR}/libs/${FLUTTER_TARGET_PLATFORM}/include/internal" ) ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/runner/CMakeLists.txt This snippet defines the build configuration for the Windows runner executable. It includes source files, applies standard settings, sets compiler definitions, links necessary libraries, and specifies include directories. ```cmake cmake_minimum_required(VERSION 3.15) project(runner LANGUAGES CXX) add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "run_loop.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) apply_standard_settings(${BINARY_NAME}) target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Project and Executable Configuration Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Sets the minimum CMake version, project name, executable name, and application ID. It also opts into modern CMake behaviors and sets the runtime path for bundled libraries. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "code_example") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "com.example.code") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(SET CMP0063 NEW) # Load bundled libraries from the lib/ directory relative to the binary. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Plugin Source Files Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/linux/CMakeLists.txt Appends all necessary source files to the PLUGIN_SOURCES list. Any new source files added to the plugin should be included here. ```cmake list(APPEND PLUGIN_SOURCES "zego_express_engine_plugin.cc" "internal/ZegoLog.h" "internal/ZegoLog.cpp" # "internal/DataToImageTools.hpp" "internal/ZegoExpressEngineInterface.h" "internal/ZegoExpressEngineMethodHandler.cpp" "internal/ZegoExpressEngineMethodHandler.h" "internal/ZegoExpressEngineEventHandler.h" "internal/ZegoExpressEngineEventHandler.cpp" "internal/ZegoTextureRendererController.h" "internal/ZegoTextureRendererController.cpp" "internal/ZegoTextureRenderer.h" "internal/ZegoTextureRenderer.cpp" "internal/ZegoTexture.h" "internal/ZegoTexture.cc" "internal/ZegoUtils.h" "internal/ZegoDataUtils.h" "internal/ZegoDataUtils.cpp" ) ``` -------------------------------- ### Flutter Wrapper App Library Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/flutter/CMakeLists.txt Creates a static library for the Flutter wrapper application, including core and application sources. It applies standard settings, links against the Flutter library, and adds include directories. ```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) ``` -------------------------------- ### Project and Plugin Naming Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/linux/CMakeLists.txt Sets the project name and the plugin library name. The plugin name must not be changed as it is used for build generation. ```cmake set(PROJECT_NAME "zego_express_engine") project(${PROJECT_NAME} LANGUAGES CXX) set(PLUGIN_NAME "zego_express_engine_plugin") ``` -------------------------------- ### Find DLL Libraries for Windows x64 Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/windows/CMakeLists.txt This snippet uses the 'file(GLOB ...)' command to find all .dll files within the specified 'libs/x64' directory. These libraries are essential for the ZegoExpress engine's functionality on Windows x64. ```cmake file(GLOB zego_express_engine_bundled_libraries "${CMAKE_CURRENT_LIST_DIR}/libs/x64/*.dll" ) ``` -------------------------------- ### Runtime Output Directory Configuration Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Sets the runtime output directory for the executable to a subdirectory to prevent accidental execution of unbundled copies. ```cmake # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Profile Build Settings Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/CMakeLists.txt Copies Release build flags to Profile build flags for linker and compiler 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}") ``` -------------------------------- ### Link Library Dependencies Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/linux/CMakeLists.txt Links the plugin library to essential dependencies like 'flutter' and 'PkgConfig::GTK'. Add any other plugin-specific dependencies here. ```cmake target_link_libraries(${PLUGIN_NAME} PRIVATE flutter PkgConfig::GTK ) ``` -------------------------------- ### C++ Wrapper Sources Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/flutter/CMakeLists.txt Defines lists of C++ source files for the wrapper, categorized by core, plugin, and application components. Paths are prepended with the wrapper root directory. ```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}/") ``` -------------------------------- ### Flutter Wrapper Plugin Library Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/flutter/CMakeLists.txt Creates a static library for the Flutter wrapper plugin, including core and plugin sources. It applies standard settings, sets position-independent code and visibility, links against the Flutter library, and adds include directories. ```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) ``` -------------------------------- ### Bundled Libraries List Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/linux/CMakeLists.txt Sets the list of absolute paths to libraries that will be bundled with the plugin. This list can include prebuilt libraries or those created by external builds. ```cmake set(zego_express_engine_bundled_libraries ${zego_express_engine_bundled_libraries} PARENT_SCOPE ) ``` -------------------------------- ### Check H265 Hardware Encoding Support Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/CHANGELOG.md Verifies if the current device supports H.265 hardware encoding. Returns 1 if supported, 0 if not supported, and 2 if undetermined. ```dart ZegoExpressEngine.instance.isVideoEncoderSupported(ZegoVideoCodecID.H265, codecBackend: ZegoVideoCodecBackend.Hardware) ``` -------------------------------- ### Cross-Building System Root Configuration Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Configures CMake for cross-building by setting the system root and adjusting find root path modes when a Flutter target platform sysroot is defined. ```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() ``` -------------------------------- ### Build Configuration Options Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/CMakeLists.txt Configures build types (Debug, Profile, Release) based on whether the generator is multi-configuration. Ensures a default build type is set if none is specified. ```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() ``` -------------------------------- ### Flutter Integration Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/CMakeLists.txt Specifies the directory for Flutter managed files and includes the Flutter library and tool build rules. Also includes generated plugin build rules. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") # Flutter library and tool build rules. add_subdirectory(${FLUTTER_MANAGED_DIR}) # Application build add_subdirectory("runner") # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Flutter Interface Library Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/flutter/CMakeLists.txt Creates an interface library for Flutter, setting include directories and linking the Flutter library. It also adds a dependency on flutter_assemble. ```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 Tool Backend Custom Command Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/flutter/CMakeLists.txt Configures a custom command to run the Flutter tool backend. It uses a phony output file to ensure execution and sets environment variables. This command generates the Flutter library and headers. ```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 ) ``` -------------------------------- ### Include Custom CMake Scripts Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/linux/CMakeLists.txt Includes external CMake scripts for downloading the native SDK and copying common code. These scripts are essential for setting up the project's dependencies. ```cmake include(${CMAKE_CURRENT_SOURCE_DIR}/download.cmake) download_native_sdk("${CMAKE_CURRENT_SOURCE_DIR}") include(${CMAKE_CURRENT_SOURCE_DIR}/setup.cmake) copy_common_code("${CMAKE_CURRENT_SOURCE_DIR}") ``` -------------------------------- ### Flutter Library Headers Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/flutter/CMakeLists.txt Appends Flutter library header files to a list and prepends the ephemeral directory path to each. ```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}/") ``` -------------------------------- ### Flutter Managed Directory and Subdirectory Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Sets the path for Flutter managed files and adds the Flutter subdirectory to the build. ```cmake # Flutter library and tool build rules. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Unicode and Standard Compilation Settings Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/windows/CMakeLists.txt Enables Unicode support and applies standard compilation features, options, and definitions for C++17, warning levels, exception handling, and debug definitions. ```cmake # Use Unicode for all projects. add_definitions(-DUNICODE -D_UNICODE) # Compilation settings that should be applied to most targets. 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() ``` -------------------------------- ### Configure Flutter Tool Backend Custom Command Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/flutter/CMakeLists.txt Defines a custom command to execute the Flutter tool backend script. This command is responsible for generating the Flutter library and headers. It's set to run every time by using a dummy output file '_phony_'. ```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 ) ``` -------------------------------- ### Create Flutter Interface Library Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/flutter/CMakeLists.txt Creates an INTERFACE library target named 'flutter'. This target includes the necessary include directories and links against the Flutter library and 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 ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Generated Plugin Build Rules Inclusion Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Includes the CMake script for managing the build of generated plugins. ```cmake # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Linking Libraries and Dependencies Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Links the application executable with the Flutter library and GTK, and adds a dependency on the Flutter assembly process. ```cmake # Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Set Bundled Libraries for Parent Scope Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/windows/CMakeLists.txt This command exports the list of bundled libraries (DLLs and cacert.pem) to the PARENT_SCOPE. This makes the list accessible to higher-level CMake build configurations. ```cmake set(zego_express_engine_bundled_libraries ${zego_express_engine_bundled_libraries} PARENT_SCOPE) ``` -------------------------------- ### Link Shared Object Libraries Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/linux/CMakeLists.txt Iterates through shared object (.so) files in the platform-specific libraries directory and links them to the plugin target. It also collects these library paths for bundling. ```cmake file(GLOB LIBRARY_FILES "${CMAKE_CURRENT_SOURCE_DIR}/libs/${FLUTTER_TARGET_PLATFORM}/*") foreach(LIB_FILE ${LIBRARY_FILES}) if(LIB_FILE MATCHES ".*\\.so.*good") # 链接库文件到目标 target_link_libraries(${PLUGIN_NAME} PRIVATE ${LIB_FILE}) # 添加库文件路径到变量 list(APPEND zego_express_engine_bundled_libraries ${LIB_FILE}) endif() endforeach() ``` -------------------------------- ### Application Executable Target Definition Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Defines the main executable target for the application, including source files and applying standard settings. ```cmake # Define the application target. To change its name, change BINARY_NAME above, # not the value here, or `flutter run` will no longer work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Build Type Configuration Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already defined, ensuring a consistent build mode for the project. ```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() ``` -------------------------------- ### Set Runtime Path (RPATH) Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/linux/CMakeLists.txt Adds '$ORIGIN' to the RPATH of the plugin target. This ensures that the plugin library can find other shared libraries (like libZegoExpressEngine.so) at runtime when they are located in the same directory. ```cmake set_property( TARGET ${PLUGIN_NAME} PROPERTY BUILD_RPATH "$ORIGIN" ) ``` -------------------------------- ### Standard Compilation Settings Function Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/CMakeLists.txt Defines a function to apply common compilation settings like C++ standard, warning levels, optimization, and NDEBUG definition. ```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 -Wall -Werror) target_compile_options(${TARGET} PRIVATE "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Define Plugin Library Target Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/linux/CMakeLists.txt Defines the plugin library target as a SHARED library. The name must match PLUGIN_NAME to ensure correct build generation. ```cmake add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SOURCES} ) ``` -------------------------------- ### Define List Prepend Function Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/linux/flutter/CMakeLists.txt Defines a custom CMake function 'list_prepend' to add a prefix to each element in a list. This is used as a fallback for older CMake versions that do not support 'list(TRANSFORM ... PREPEND ...)'. ```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() ``` -------------------------------- ### Web Service Worker Integration for Flutter SDK Source: https://github.com/zegoim/zego-express-flutter-sdk/blob/main/example/web/index.html This script handles the loading of the main Dart JS file for a Flutter web application. It prioritizes using a service worker for caching and faster loading, with a fallback to a direct script tag if service workers are unavailable or fail. ```javascript var serviceWorkerVersion = null; var scriptLoaded = false; function loadMainDartJs() { if (scriptLoaded) { return; } scriptLoaded = true; var scriptTag = document.createElement('script'); scriptTag.src = 'main.dart.js'; scriptTag.type = 'application/javascript'; document.body.append(scriptTag); } if ('serviceWorker' in navigator) { // Service workers are supported. Use them. window.addEventListener('load', function () { // Wait for registration to finish before dropping the