### Install Application Bundle Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/linux/CMakeLists.txt Configures the installation process to create a relocatable application bundle. It ensures a clean build directory and installs the executable, libraries, and assets. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Application Executable and Data Files Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/windows/CMakeLists.txt Installs the main executable, ICU data file, Flutter library, and any bundled plugin libraries to the specified installation directories. ```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() ``` -------------------------------- ### Install Application Executable and Core Files Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/CMakeLists.txt Installs the main application executable, ICU data, and the Flutter library to their designated locations within the installation prefix. ```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) ``` -------------------------------- ### Installation Bundle Configuration Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/linux/CMakeLists.txt Configures the installation prefix to a build bundle directory and ensures it's cleared on each build. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Install Temurin8 JDK and Set JAVA_HOME Source: https://github.com/flet-dev/serious-python/wiki/Configuring-Kivy-p4a-on-macOS Installs the Temurin8 JDK using Homebrew and sets the JAVA_HOME environment variable. Ensure Temurin8 is installed before proceeding. ```bash brew install --cask temurin8 export JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home ``` -------------------------------- ### Configure Installation Directory for Windows Bundle Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/CMakeLists.txt Sets up installation directories to place files next to the executable for in-place running on Windows, facilitating Visual Studio development. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Installation Rules for Application Bundle Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/linux/CMakeLists.txt Defines how the application bundle is installed, including cleaning the build directory, setting installation destinations for the executable, data, and libraries, and copying native assets and Flutter assets. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) # Copy the native assets provided by the build.dart from all packages. set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Android SDK and NDK using sdkmanager Source: https://github.com/flet-dev/serious-python/wiki/Configuring-Kivy-p4a-on-macOS Installs the specified Android SDK platform and NDK version using the `sdkmanager` command. The `--channel=3` flag is used for the NDK installation. ```bash echo "y" | sdkmanager --install "ndk;$NDK_VERSION" --channel=3 echo "y" | sdkmanager --install "platforms;$SDK_VERSION" ``` -------------------------------- ### Install Dependencies from Requirements File Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/README.md Command to package an app for iOS, installing dependencies from a requirements.txt file. Requires passing -r three times. ```bash dart run serious_python:main package app/src -p iOS \ -r -r -r app/src/requirements.txt ``` -------------------------------- ### Install Executable and Runtime Files Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/windows/CMakeLists.txt Configures the installation of the main executable, ICU data, Flutter library, bundled plugin libraries, and native assets. Ensures the application can run in place by copying necessary files next to the executable. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/CMakeLists.txt Installs any bundled libraries associated with plugins to the application's library directory. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Flutter Library and Bundled Libraries Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_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) ``` -------------------------------- ### Set Environment Variables and Package for iOS Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/README.md Example of setting environment variables for site-packages and app directory, then packaging for iOS with a requirements file. ```bash export SERIOUS_PYTHON_SITE_PACKAGES=$(pwd)/build/site-packages export SERIOUS_PYTHON_APP=$(pwd)/build/app dart run serious_python:main package app/src -p iOS -r -r -r app/src/requirements.txt ``` -------------------------------- ### Install Application Executable and Data Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/linux/CMakeLists.txt Installs the main application executable to the bundle's root and Flutter's ICU data file 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) ``` -------------------------------- ### Install Native Assets Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_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) ``` -------------------------------- ### Install Multiple Dependencies Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/README.md Command to package an app for Darwin, specifying multiple dependencies using the -r flag for each. Supports version specifiers. ```bash dart run serious_python:main package app/src -p Darwin \ -r flet -r 'pandas>=2.2,<3' -r numpy==2.1.1 ``` -------------------------------- ### Install AOT Library Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the bundle's lib directory, but only for non-Debug build types. ```cmake # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/windows/CMakeLists.txt Installs Flutter assets by first removing any existing directory and then copying the new assets. This ensures that the assets directory is always up-to-date. ```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) ``` -------------------------------- ### Install pip on Host Python Source: https://github.com/flet-dev/serious-python/wiki/Configuring-Kivy-p4a-on-macOS Installs pip into the host Python 3 environment. This is necessary for managing packages within the build environment. ```bash ~/.python-for-android/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 -m ensurepip ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/linux/CMakeLists.txt Sets up the minimum CMake version, project name, executable name, application ID, and modern CMake behaviors. It also defines the installation path for bundled libraries. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "flask_example") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "com.example.flask_example") # 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") ``` -------------------------------- ### Prepare App and Get Path Source: https://github.com/flet-dev/serious-python/blob/main/README.md Call `SeriousPython.prepareApp()` to get the path to the unpacked app directory. This performs the one-time Android unpack if needed. ```dart SeriousPython.prepareApp() ``` -------------------------------- ### Set Python Version and Package for Android Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/README.md Example of setting the Python version using an environment variable and then packaging the app for Android. ```bash export SERIOUS_PYTHON_VERSION=3.13 dart run serious_python:main package app/src -p Android -r flet ``` -------------------------------- ### Install Python Runtime Directory Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python_linux/linux/CMakeLists.txt Installs the Python runtime directory into the build bundle. This ensures the necessary Python files are available at runtime. ```cmake install(DIRECTORY "${PYTHON_PACKAGE}/lib/python${PYTHON_VERSION}" DESTINATION "${CMAKE_BINARY_DIR}/bundle") ``` -------------------------------- ### Run the Bridge Example Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/README.md Launches the Flutter application on a specified platform. Use the `-d` flag followed by the target platform (e.g., macos, linux, windows). ```sh flutter run -d macos # or -d linux / windows / ``` -------------------------------- ### Install Native Assets Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/CMakeLists.txt Copies native assets generated during the build process to the application's library directory. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Python for Android (p4a) Source: https://github.com/flet-dev/serious-python/wiki/Configuring-Kivy-p4a-on-macOS Installs the `python-for-android` package using pip. This tool is used to build Android Python applications. ```bash pip install python-for-android ``` -------------------------------- ### Install AOT Library for Release Builds Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library only for Profile and Release build configurations. This is typically used to improve performance in non-debug builds. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Prepare Python App Directory Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/README.md Get the path to the unpacked app directory, performing Android unpacking if necessary. Useful for manual runtime control. ```dart SeriousPython.prepareApp(); ``` -------------------------------- ### Install Python App to Bundle Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python_linux/linux/CMakeLists.txt Conditionally installs the Python application source code to the bundle directory. This is used when the SERIOUS_PYTHON_APP environment variable is set and points to an existing directory. ```cmake if(DEFINED ENV{SERIOUS_PYTHON_APP} AND EXISTS "$ENV{SERIOUS_PYTHON_APP}") install(CODE " file(REMOVE_RECURSE \"${CMAKE_BINARY_DIR}/bundle/app\") file(MAKE_DIRECTORY \"${CMAKE_BINARY_DIR}/bundle/app\") file(COPY \"$ENV{SERIOUS_PYTHON_APP}/\" DESTINATION \"${CMAKE_BINARY_DIR}/bundle/app\") ") endif() ``` -------------------------------- ### Conditionally Install External Site-Packages Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python_linux/linux/CMakeLists.txt Mirrors an external site-packages directory into the bundle if the SERIOUS_PYTHON_SITE_PACKAGES environment variable is set and points to an existing directory. This allows for custom Python package installations. ```cmake if(DEFINED ENV{SERIOUS_PYTHON_SITE_PACKAGES} AND EXISTS "$ENV{SERIOUS_PYTHON_SITE_PACKAGES}") install(CODE " file(REMOVE_RECURSE \"${CMAKE_BINARY_DIR}/bundle/site-packages\") file(MAKE_DIRECTORY \"${CMAKE_BINARY_DIR}/bundle/site-packages\") file(COPY \"$ENV{SERIOUS_PYTHON_SITE_PACKAGES}/\" DESTINATION \"${CMAKE_BINARY_DIR}/bundle/site-packages\") ") endif() ``` -------------------------------- ### Download and Extract Python Runtime Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python_linux/linux/CMakeLists.txt This snippet downloads the Python runtime tarball from a specified URL and extracts it to the build directory. It includes logic to re-extract if the existing installation is outdated or missing, using a marker file to track the build ID. ```cmake set(PYTHON_PACKAGE ${CMAKE_BINARY_DIR}/python) set(PYTHON_URL https://github.com/flet-dev/python-build/releases/download/${PYTHON_BUILD_DATE}/python-linux-dart-${PYTHON_FULL_VERSION}-${PYTHON_ARCH}.tar.gz) set(PYTHON_FILE "${PB_CACHE}/python-linux-dart-${PYTHON_FULL_VERSION}-${PYTHON_ARCH}.tar.gz") _sp_download("${PYTHON_URL}" "${PYTHON_FILE}") set(_py_build_id "${PYTHON_FULL_VERSION}-${PYTHON_BUILD_DATE}") set(_py_marker "${PYTHON_PACKAGE}/.python_build_id") set(_py_extract TRUE) if(EXISTS "${_py_marker}") file(READ "${_py_marker}" _py_cur) string(STRIP "${_py_cur}" _py_cur) if(_py_cur STREQUAL "${_py_build_id}") set(_py_extract FALSE) endif() endif() if(_py_extract) file(REMOVE_RECURSE "${PYTHON_PACKAGE}") file(ARCHIVE_EXTRACT INPUT "${PYTHON_FILE}" DESTINATION "${PYTHON_PACKAGE}") file(WRITE "${_py_marker}" "${_py_build_id}") endif() ``` -------------------------------- ### Find and Link GTK, GLIB, and GIO Libraries in CMake Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/linux/flutter/CMakeLists.txt This CMake code uses PkgConfig to find GTK, GLIB, and GIO libraries and makes them available as imported targets for linking. Ensure these libraries are installed on your system. ```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) ``` -------------------------------- ### Create and Activate Python Virtual Environment Source: https://github.com/flet-dev/serious-python/wiki/Configuring-Kivy-p4a-on-macOS Sets up a new Python virtual environment named `.venv` and activates it. This isolates project dependencies. ```bash python3 -m venv .venv source .venv/bin/activate ``` -------------------------------- ### Build Python App Bundle Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/README.md Sets environment variables for Python version and site-packages, then packages the Python app for a specific platform. Ensure SERIOUS_PYTHON_VERSION is set as an environment variable. ```sh # From this directory: export SERIOUS_PYTHON_VERSION=3.14 # read by BOTH the package step and `flutter build` export SERIOUS_PYTHON_SITE_PACKAGES=$(pwd)/build/site-packages export SERIOUS_PYTHON_APP=$(pwd)/build/python-app dart run serious_python:main package app/src --platform Darwin ``` -------------------------------- ### Basic CMake Configuration Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/windows/flutter/CMakeLists.txt Sets the minimum CMake version required and defines the ephemeral directory path. ```cmake cmake_minimum_required(VERSION 3.14) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") ``` -------------------------------- ### Login to pub.dev Source: https://github.com/flet-dev/serious-python/blob/main/CONTRIBUTING.md Use this command to log in to your pub.dev account for publishing packages. ```bash flutter pub login ``` -------------------------------- ### Set Flutter Library Path Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/flutter/CMakeLists.txt Defines the path to the Flutter library DLL. This is published to the parent scope for use in the install step. ```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 library path Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/windows/flutter/CMakeLists.txt Specifies the location of the Flutter Windows DLL. This is published to the parent scope for use in the install step. ```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) ``` -------------------------------- ### Create Python Distributive with p4a Source: https://github.com/flet-dev/serious-python/wiki/Configuring-Kivy-p4a-on-macOS Uses `p4a create` to build a Python distributive for Android, including specified requirements like `numpy` and targeting multiple architectures. The `--sdk-dir` and `--ndk-dir` flags are essential. ```bash p4a create --requirements numpy --arch arm64-v8a --arch armeabi-v7a --arch x86_64 --sdk-dir $ANDROID_SDK_ROOT --ndk-dir $ANDROID_SDK_ROOT/ndk/$NDK_VERSION --dist-name serious_python ``` -------------------------------- ### Upgrade Cython Source: https://github.com/flet-dev/serious-python/wiki/Configuring-Kivy-p4a-on-macOS Ensures that Cython is installed or upgraded to the latest version. Cython is often a dependency for Python packages compiled for Android. ```bash pip install --upgrade cython ``` -------------------------------- ### Run Python App with Custom Entry Point Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/README.md Run a Python application with a specified entry point file name. ```dart SeriousPython.run(appFileName: "my_app.py"); ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/runner/CMakeLists.txt Applies a predefined set of standard build settings to the specified target. This can be removed if custom build settings are required. ```cmake # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Export Flutter Library and ICU Data Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/windows/flutter/CMakeLists.txt Exports the Flutter library path and the ICU data file to the parent scope for use in the install step. ```cmake # 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) ``` -------------------------------- ### Project and CMake Policy Configuration Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python_windows/windows/CMakeLists.txt Initializes the CMake project with CXX language support and explicitly opts into modern CMake behaviors to ensure compatibility with recent CMake versions. ```cmake project(${PROJECT_NAME} LANGUAGES CXX) # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Find and link system dependencies Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/linux/flutter/CMakeLists.txt Uses PkgConfig to find and check for required system libraries such as GTK, GLIB, and GIO. These are essential for Flutter's Linux integration. ```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) ``` -------------------------------- ### Execute Integration Tests Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/README.md Runs specific integration tests for the bridge example. The `--dart-define` flag can be used to pass build-time variables, such as the expected Python version. ```sh # After `dart run serious_python:main package …`: flutter test integration_test/throughput_test.dart -d macos flutter test integration_test/memory_test.dart -d macos flutter test integration_test/interactivity_test.dart -d macos \ --dart-define=EXPECTED_PYTHON_VERSION=3.14 ``` -------------------------------- ### Package for Web with Custom Asset Path Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/README.md Command to package a Python app for the Emscripten (web) target, specifying a custom asset path for the zip file. ```bash dart run serious_python:main package --asset assets/myapp.zip app/src -p Emscripten ``` -------------------------------- ### Project-Level CMake Configuration Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/linux/CMakeLists.txt Sets up the minimum CMake version, project name, and executable name. It also defines the application ID and enables modern CMake behaviors. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "run_example") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "com.example.run_example") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(SET CMP0063 NEW) # Load bundled libraries from the lib/ directory relative to the binary. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Root filesystem for cross-building. if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() # Define build configuration options. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() # 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_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() # Flutter library and tool build rules. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) # Application build; see runner/CMakeLists.txt. add_subdirectory("runner") # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) # 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" ) # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python_linux/linux/CMakeLists.txt Applies a standard set of build settings to the plugin target, configured at the application level. This can be removed if the plugin requires custom build settings. ```cmake apply_standard_settings(${PLUGIN_NAME}) ``` -------------------------------- ### Define custom command for Flutter tool backend in CMake Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/linux/flutter/CMakeLists.txt This `add_custom_command` defines a build step that executes the Flutter tool backend script. It's configured to run every time due to the `_phony_` output, as there's no direct way to get a full input/output list from the Flutter tool. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_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 ) ``` -------------------------------- ### Build Android App Bundle (.aab) with p4a Source: https://github.com/flet-dev/serious-python/wiki/Configuring-Kivy-p4a-on-macOS Builds a release-ready Android App Bundle using `p4a aab`. This command specifies the private app code, package details, requirements, architectures, and build settings. It also includes steps to clean and bundle the release using Gradle. ```bash export JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home p4a aab --private $HOME/projects/samples/kivy_android/service_app --package org.example.myapp --name "My App" --version 0.1 --bootstrap sdl2 --requirements python3,kivy --arch arm64-v8a --arch armeabi-v7a --release --sdk-dir $HOME/Library/Android/sdk --ndk-dir $HOME/Library/Android/sdk/ndk/25.2.9519653 export JAVA_HOME="" cd ~/.python-for-android/dists/unnamed_dist_1 ./gradlew clean bundleRelease ``` -------------------------------- ### Set macOSX Deployment Target in project.pbxproj Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/README.md Ensure `macos/Runner.xcodeproj/project.pbxproj` includes the `MACOSX_DEPLOYMENT_TARGET` setting for macOS compatibility. ```objc MACOSX_DEPLOYMENT_TARGET = 11.0; ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/linux/runner/CMakeLists.txt Applies a standard set of build settings to the specified target. This can be customized or removed if the application requires different build configurations. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/windows/runner/CMakeLists.txt Applies a standard set of build settings to the specified target. This can be customized for applications requiring different build configurations. ```cmake # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### List Bundled Libraries Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python_windows/windows/CMakeLists.txt Defines a list of absolute paths to libraries that should be bundled with the plugin. This can include prebuilt or generated libraries. ```cmake # List of absolute paths to libraries that should be bundled with the plugin. # This list could contain prebuilt libraries, or libraries created by an ``` -------------------------------- ### Enable Unicode Support Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/CMakeLists.txt Adds preprocessor definitions to enable Unicode support in the project. ```cmake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Flutter and System Dependencies Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/linux/CMakeLists.txt Includes the Flutter managed directory and finds necessary system libraries like GTK+ 3.0 using PkgConfig. ```cmake # Flutter library and tool build rules. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Define Python Package and Download URL Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python_windows/windows/CMakeLists.txt Sets the target directory for the Python package and the URL for downloading the Python distribution. Ensure PYTHON_BUILD_DATE and PYTHON_FULL_VERSION are defined before this. ```cmake set(PYTHON_PACKAGE ${CMAKE_BINARY_DIR}/python) set(PYTHON_URL "https://github.com/flet-dev/python-build/releases/download/${PYTHON_BUILD_DATE}/python-windows-for-dart-${PYTHON_FULL_VERSION}.zip") # Tarball lives in the shared cache; extraction targets the per-plugin build # tree so a `flutter clean` doesn't force a re-download. set(PYTHON_FILE "${PB_CACHE}/python-windows-for-dart-${PYTHON_FULL_VERSION}.zip") ``` -------------------------------- ### Create Static Library for Flutter Wrapper Plugin Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/windows/flutter/CMakeLists.txt Builds a static library for the Flutter wrapper plugin, applying standard settings and visibility presets, and linking against the Flutter library. ```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) ``` -------------------------------- ### Package Python App for Pyodide Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/README.md Use this command to package your Python app for Pyodide (Emscripten). ```bash dart run serious_python:main package app/src -p Emscripten -r -r -r app/src/requirements.txt ``` -------------------------------- ### Add Plugin Source Files Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python_windows/windows/CMakeLists.txt Appends new source files to the PLUGIN_SOURCES list. Ensure any new .cpp or .h files are added here. ```cmake list(APPEND PLUGIN_SOURCES "serious_python_windows_plugin.cpp" "serious_python_windows_plugin.h" ) ``` -------------------------------- ### Define Flutter Tool Backend Custom Command Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/flutter/CMakeLists.txt Sets up a custom command to run the Flutter tool backend. A phony output file is used to ensure the command runs every time. It sets environment variables and specifies the command to execute. ```cmake # _phony_ is a non-existent file to force this command to run every time, since currently there's no way to get a full input/output list from the flutter tool. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/windows/runner/CMakeLists.txt Links necessary libraries and adds include directories for the application target. Custom application-specific dependencies should be added here. ```cmake # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Android Native Library Configuration Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/README.md Configure the Android build to use a minimum SDK version of 23 or higher. This ensures native libraries are not compressed and remain page-aligned in the APK. ```kotlin android { defaultConfig { minSdk = 23 } } ``` -------------------------------- ### Open Xcode Project Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md Open your Flutter project's Xcode workspace to access and modify asset files. ```bash open ios/Runner.xcworkspace ``` -------------------------------- ### Set Source Include Directories Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python_windows/windows/CMakeLists.txt Specifies interface include directories for the plugin, including the current source directory's include folder. ```cmake target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") ``` -------------------------------- ### Package Python App for Specific Platform Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/README.md Command to package a Python app for a specified platform. Replace {platform} with Android, iOS, Darwin, Windows, Linux, or Emscripten. ```bash dart run serious_python:main package app/src -p {platform} ``` -------------------------------- ### List application wrapper sources Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/windows/flutter/CMakeLists.txt Appends C++ source files for the application runner wrapper. These files handle Flutter engine and view controller implementations. ```cmake list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Set Project Name and Plugin Name Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python_linux/linux/CMakeLists.txt Sets the project name and the specific plugin name for the serious-python Linux build. ```cmake project(${PROJECT_NAME} LANGUAGES CXX) # This value is used when generating builds using this plugin, so it must # not be changed. set(PLUGIN_NAME "serious_python_linux_plugin") ``` -------------------------------- ### Include Generated Configuration Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/windows/flutter/CMakeLists.txt Includes the generated configuration file provided by the Flutter tool. ```cmake # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Build plugin wrapper library Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/windows/flutter/CMakeLists.txt Creates a static library for the Flutter C++ wrapper intended for plugins. It includes core and plugin-specific sources and links against the Flutter library. ```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) ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/windows/CMakeLists.txt Applies common compilation features and options to a target. Use this for general settings applicable to most targets, but add specific options to individual targets when necessary. ```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() ``` -------------------------------- ### Create Flutter Interface Library Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/flutter/CMakeLists.txt Creates an interface library target named 'flutter' and sets its include directories and link libraries. ```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) ``` -------------------------------- ### Package Python App for Windows Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/README.md Use this command to package your Python application for Windows. Ensure the SERIOUS_PYTHON environment variables are set. ```bash export SERIOUS_PYTHON_SITE_PACKAGES=$(pwd)/build/site-packages export SERIOUS_PYTHON_APP=$(pwd)/build/python-app dart run serious_python:main package app/src -p Windows -r -r -r app/src/requirements.txt ``` -------------------------------- ### Build application wrapper library Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/windows/flutter/CMakeLists.txt Creates a static library for the Flutter C++ wrapper intended for the application runner. It includes core and application-specific sources and links against the Flutter library. ```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) ``` -------------------------------- ### Define Standard Compilation Settings Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/linux/CMakeLists.txt Applies common compilation features and options to a target. Use this for settings that apply to most targets, but be cautious as plugins use it by default. ```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() ``` -------------------------------- ### Include Flutter and Plugin Build Rules Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/windows/CMakeLists.txt Includes the Flutter managed directory and generated plugin CMake files to integrate Flutter's build system and plugins. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Include Generated Plugin Rules Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/CMakeLists.txt Includes CMake rules for building and integrating generated plugins into the application. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Add Plugin Source Files Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python_linux/linux/CMakeLists.txt Appends new source files to the PLUGIN_SOURCES list. These files will be compiled as part of the plugin library. ```cmake list(APPEND PLUGIN_SOURCES "serious_python_linux_plugin.cc" ) ``` -------------------------------- ### Generate Python Version Tables Source: https://github.com/flet-dev/serious-python/blob/main/CONTRIBUTING.md Run this command to regenerate version tables after updating `manifest.json` in the python-build repository. Omit `--release-date` to use the currently pinned release. ```bash cd src/serious_python dart run serious_python:gen_version_tables --release-date ``` -------------------------------- ### Create Static Library for Flutter Wrapper Application Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/windows/flutter/CMakeLists.txt Builds a static library for the Flutter wrapper application runner, applying standard settings and linking against the Flutter library. ```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) ``` -------------------------------- ### Include Generated Plugins Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/flask_example/linux/CMakeLists.txt Includes the CMake file that defines build rules for generated plugins. ```cmake # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Include Flutter and Runner Build Rules Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/CMakeLists.txt Includes the build rules for the Flutter framework and the application's runner. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) add_subdirectory("runner") ``` -------------------------------- ### Set Android Development Environment Variables Source: https://github.com/flet-dev/serious-python/wiki/Configuring-Kivy-p4a-on-macOS Configures essential environment variables for the Android SDK and NDK. These paths are crucial for p4a to locate necessary build tools. ```bash export ANDROID_SDK_ROOT="$HOME/Library/Android/sdk" export NDK_VERSION=25.2.9519653 export SDK_VERSION=android-33 ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/runner/CMakeLists.txt Links the application target against necessary libraries, including Flutter-specific ones and system libraries like `dwmapi.lib`. It also specifies include directories for the project. ```cmake # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Set wrapper root directory Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/bridge_example/windows/flutter/CMakeLists.txt Defines the root directory for the C++ client wrapper source files. ```cmake set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") ``` -------------------------------- ### Define Executable Target and Source Files Source: https://github.com/flet-dev/serious-python/blob/main/src/serious_python/example/run_example/windows/runner/CMakeLists.txt Defines the main executable target for the application and lists all source files, including generated ones and resource files. Ensure BINARY_NAME is consistent with the top-level CMakeLists.txt for `flutter run` compatibility. ```cmake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) # Define the application target. To change its name, change BINARY_NAME in the # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer # work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ```