### Install realm_dart package Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/example/README.md Command to install the realm_dart package and its native binaries. ```bash dart run realm_dart install ``` -------------------------------- ### Get Dependencies Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/example/README.md Command to fetch all project dependencies. ```bash dart pub get ``` -------------------------------- ### Install Realm Dart Extension Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/bin/README.md Command to install the Realm Dart native extension. ```bash pub run realm_dart install ``` -------------------------------- ### Install Flutter and Dart Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/CONTRIBUTING.md Steps to install Flutter and Dart by cloning the Flutter repository and creating worktrees for different branches. ```shell cd ~/development mkdir flutter cd flutter git clone git@github.com:flutter/flutter.git master cd master git worktree add ../stable stable git worktree add ../beta beta ``` -------------------------------- ### Run the application Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/example/README.md Command to execute the Dart application. ```bash dart run ``` -------------------------------- ### Install Flutter and Dart Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/CONTRIBUTING.md Installs Flutter and Dart by cloning the Flutter repository and creating worktrees for different branches. ```shell cd ~/development mkdir flutter cd flutter git clone git@github.com:flutter/flutter.git master cd master git worktree add ../stable stable git worktree add ../beta beta cd bin ./flutter ``` -------------------------------- ### Execute Realm Install Command Source: https://github.com/realm/realm-dart/blob/main/packages/realm/linux/CMakeLists.txt Runs the Realm installation command using the Dart tool. ```cmake # message ("FLUTTER_TOOL_ENVIRONMENT is ${FLUTTER_TOOL_ENVIRONMENT}") # message ("FLUTTER_ROOT is ${FLUTTER_ROOT}") execute_process(COMMAND "${FLUTTER_ROOT}/bin/dart" "run" "realm" "install" "--target-os-type" "linux" # "--debug" WORKING_DIRECTORY ${ABSOLUTE_PATH_APP_DIR} OUTPUT_VARIABLE output RESULT_VARIABLE result # COMMAND_ERROR_IS_FATAL ANY ) message(STATUS "cmd output: ${output}") message(STATUS "cmd result: ${result}") ``` -------------------------------- ### Full contents of catalog.dart Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Complete example of a catalog.dart file demonstrating Realm model definition and usage. ```dart import 'package:realm/realm.dart'; part 'catalog.realm.dart'; @RealmModel() class _Item { @PrimaryKey() late int id; late String name; int price = 42; } // Create a Configuration object var config = Configuration.local([Item.schema]); // Open a Realm var realm = Realm(config); var myItem = Item(0, 'Pen', price: 4); // Open a write transaction realm.write(() { realm.add(myItem); var item = realm.add(Item(1, 'Pencil')..price = 20); }); // Objects `myItem` and `item` are now managed and persisted in the realm // Read object properties from realm print(myItem.name); print(myItem.price); // Update object properties realm.write(() { myItem.price = 20; myItem.name = "Special Pencil"; }); // Get objects from the realm // Get all objects of type var items = realm.all(); // Get object by index var item = items[1]; // Get object by primary key var itemByKey = realm.find(0); // Filter and sort object var objects = realm.query("name == 'Special Pencil'"); var name = 'Pen'; objects = realm.query(r'name == $0', [name]); // Close the realm realm.close(); ``` -------------------------------- ### Install native binaries for testing Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Command to install required native binaries for running Flutter widget and unit tests. ```bash dart run realm install ``` -------------------------------- ### Flutter Asset Installation Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/linux/CMakeLists.txt Installs Flutter assets by removing the old directory and then copying the new one. ```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) ``` -------------------------------- ### Realm Install Command Source: https://github.com/realm/realm-dart/blob/main/packages/realm/windows/CMakeLists.txt Executes a Dart command to install Realm for the Windows target OS. ```cmake # message ("FLUTTER_TOOL_ENVIRONMENT is ${FLUTTER_TOOL_ENVIRONMENT}") # message ("FLUTTER_ROOT is ${FLUTTER_ROOT}") execute_process(COMMAND "${FLUTTER_ROOT}\bin\dart.bat" "run" "realm" "install" "--target-os-type" "windows" #"--debug" OUTPUT_VARIABLE output RESULT_VARIABLE result COMMAND_ERROR_IS_FATAL ANY ) message(STATUS "cmd output: ${output}") message(STATUS "cmd result: ${result}") ``` -------------------------------- ### Installation Code Block Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/linux/CMakeLists.txt Installs the application bundle, including the executable, ICU data, Flutter library, bundled libraries, and native assets. ```cmake 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 ``` -------------------------------- ### Install Flutter and Dart Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Creates a directory for Flutter and clones the Flutter repository into a 'master' branch. ```shell cd ~/development mkdir flutter cd flutter git clone git@github.com:flutter/flutter.git master cd master ``` -------------------------------- ### AOT Library Installation Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/linux/CMakeLists.txt Installs the AOT library on non-Debug builds. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Generate RealmObject classes Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/example/README.md Command to generate RealmObject classes using the realm_dart package. A new file `bin/myapp.g.dart` will be created. ```bash dart run realm_dart generate ``` -------------------------------- ### Install Dev Tool Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/dev/README.md Instructions to install the dev tool globally using Dart's pub global activate. ```shell dart pub global activate --source path . ``` -------------------------------- ### Install and activate melos Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Installs and activates the melos package manager globally. ```shell dart pub global activate melos ``` -------------------------------- ### Installation Rules Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/CMakeLists.txt Defines installation rules for the application executable, Flutter ICU data, libraries, bundled plugins, native assets, and assets 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(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) ``` -------------------------------- ### Use RealmObject class with Realm Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Example demonstrating how to create a Configuration, open a Realm, add objects, read properties, update objects, query objects, and close the Realm. ```dart // Create a Configuration object var config = Configuration.local([Item.schema]); // Opean a Realm var realm = Realm(config); var myItem = Item(0, 'Pen', price: 4); // Open a write transaction realm.write(() { realm.add(myItem); var item = realm.add(Item(1, 'Pencil')..price = 20); }); // Objects `myItem` and `item` are now managed and persisted in the realm // Read object properties from realm print(myItem.name); print(myItem.price); // Update object properties realm.write(() { myItem.price = 20; myItem.name = "Special Pencil"; }); // Get objects from the realm // Get all objects of type var items = realm.all(); // Get object by index var item = items[1]; // Get object by primary key var itemByKey = realm.find(0); // Filter and sort object var objects = realm.query("name == 'Special Pencil'"); var name = 'Pen'; objects = realm.query(r'name == $0', [name]); // Close the realm realm.close(); ``` -------------------------------- ### Install and activate melos Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/CONTRIBUTING.md Installs the melos package globally and provides instructions for adding it to the PATH. ```shell dart pub global activate melos ``` ```shell # In e.g. `~/.zshrc` export PATH="$PATH":"$HOME/.pub-cache/bin" ``` -------------------------------- ### VS Code Dart Flutter SDK Paths Configuration Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Example JSON configuration for setting the Flutter SDK path in VS Code. ```json { // ... "dart.flutterSdkPaths": [ "/Users/janedoe/development/flutter" ], } ``` -------------------------------- ### Define a Realm data model class Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Example of defining a data model class for Realm, annotated with @RealmModel() and including a primary key. ```dart @RealmModel() class _Item { @PrimaryKey() late int id; late String name; int price = 42; } ``` -------------------------------- ### Set up the project Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Runs melos commands to bootstrap and set up the project. ```shell melos bootstrap melos run setup ``` -------------------------------- ### Get stream of result changes for a query Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Get stream of result changes for a query. ```dart final cars = realm.all().query(r'make == $0', ['Tesla']); cars.changes.listen((changes) { print('Inserted indexes: ${changes.inserted}'); print('Deleted indexes: ${changes.deleted}'); print('Modified indexes: ${changes.modified}'); }); realm.write(() => realm.add(Car('VW', 'Polo', kilometers: 22000))); ``` -------------------------------- ### Standard Settings Function Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/linux/CMakeLists.txt Applies common compilation features, options, and definitions to a target, optimizing for release builds 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() ``` -------------------------------- ### Build Configuration Settings Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/CMakeLists.txt Sets C++ standard, required status, extensions, visibility, and runtime library. ```cmake set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED on) set(CMAKE_CXX_EXTENSIONS off) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") ``` -------------------------------- ### List available emulators/simulators Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Lists all available Flutter emulators and simulators. ```shell flutter emulator ``` -------------------------------- ### Project Definition and Ccache Inclusion Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/CMakeLists.txt Defines the project name and conditionally includes a CMake script for ccache. ```cmake project(realm-dart) if("$ENV{REALM_USE_CCACHE}" STREQUAL "TRUE") message("REALM_USE_CCACHE is TRUE. Will try a build with ccache") include(src/realm.build.use.ccache.cmake) endif() ``` -------------------------------- ### Output Directory Configuration Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/src/CMakeLists.txt Determines and appends the correct subdirectory to the output directory based on the target system. ```cmake string(APPEND OUTPUT_DIR "${PROJECT_SOURCE_DIR}/binary") if(CMAKE_SYSTEM_NAME STREQUAL "Windows") string(APPEND OUTPUT_DIR "/windows") elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") string(APPEND OUTPUT_DIR "/linux") elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") string(APPEND OUTPUT_DIR "/macos") elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") string(APPEND OUTPUT_DIR "/android/${CMAKE_ANDROID_ARCH_ABI}") elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS") string(APPEND OUTPUT_DIR "/ios") endif() ``` -------------------------------- ### Realm Core Build Configuration Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/src/CMakeLists.txt Configures whether to build Realm Core from source and adds it as a subdirectory if enabled. ```cmake option(REALM_BUILD_CORE_FROM_SOURCE "Build Realm Core from source" ON) if(REALM_BUILD_CORE_FROM_SOURCE) set(REALM_BUILD_LIB_ONLY ON) add_subdirectory(realm-core EXCLUDE_FROM_ALL) endif() ``` -------------------------------- ### Output Directory for Libraries Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/src/CMakeLists.txt Sets the library output directory for different build configurations when not explicitly defined. ```cmake if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) # using RUNTIME_OUTPUT_DIRECTORY_ to output the binaries in the target directory wihtout creating a sub directory # for multi-configuration generators (VS, XCode) # https://cmake.org/cmake/help/v2.8.8/cmake.html#prop_tgt:RUNTIME_OUTPUT_DIRECTORY set_target_properties(realm_dart PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}") set_target_properties(realm_dart PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}") set_target_properties(realm_dart PROPERTIES RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${OUTPUT_DIR}") set_target_properties(realm_dart PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${OUTPUT_DIR}") set_target_properties(realm_dart PROPERTIES LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}") set_target_properties(realm_dart PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}") set_target_properties(realm_dart PROPERTIES LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${OUTPUT_DIR}") set_target_properties(realm_dart PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${OUTPUT_DIR}") endif() ``` -------------------------------- ### Add Subdirectory Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/CMakeLists.txt Includes the 'src' subdirectory for further build processing. ```cmake set(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING=1) add_subdirectory(src) ``` -------------------------------- ### CMake Minimum Required Version and Android Configuration Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/CMakeLists.txt Sets the minimum required CMake version and configures build settings for Android. ```cmake cmake_minimum_required(VERSION 3.21) if(CMAKE_SYSTEM_NAME STREQUAL Android) message("Realm Flutter Android build enabled") set(REALM_ANDROID ON) set(CMAKE_ANDROID_STL_TYPE c++_static) set(ANDROID_ALLOW_UNDEFINED_SYMBOLS ON) endif() ``` -------------------------------- ### Basic CMake Configuration Source: https://github.com/realm/realm-dart/blob/main/packages/realm/linux/CMakeLists.txt Sets the minimum CMake version, project name, and defines the plugin library. ```cmake cmake_minimum_required(VERSION 3.19) set(PROJECT_NAME "realm") project(${PROJECT_NAME} LANGUAGES CXX) # This value is used when generating builds using this plugin, so it must # not be changed. set(PLUGIN_NAME "realm_plugin") add_library(${PLUGIN_NAME} SHARED "realm_plugin.cpp") apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter) target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### CMake Project Configuration Source: https://github.com/realm/realm-dart/blob/main/packages/realm/windows/CMakeLists.txt Sets the minimum CMake version, project name, and language, and defines the plugin name. ```cmake cmake_minimum_required(VERSION 3.10) set(PROJECT_NAME "realm") project(${PROJECT_NAME} LANGUAGES CXX) # This value is used when generating builds using this plugin, so it must # not be changed set(PLUGIN_NAME "realm_plugin") add_library(${PLUGIN_NAME} SHARED "realm_plugin.cpp") apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) ``` -------------------------------- ### Main CMakeLists.txt Configuration Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/runner/CMakeLists.txt This snippet defines the minimum CMake version, project name, and the application target, including source files and standard build settings. ```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" ) # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Realm Bundled Libraries Source: https://github.com/realm/realm-dart/blob/main/packages/realm/windows/CMakeLists.txt Lists the absolute paths to libraries that should be bundled with the plugin. ```cmake set(realm_bundled_libraries "${PROJECT_SOURCE_DIR}/binary/windows/realm_dart.dll" PARENT_SCOPE ) ``` -------------------------------- ### Dependency Libraries and Include Directories Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/runner/CMakeLists.txt Specifies the libraries to link against and the directories to search for include files. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Realm Plugin CMake Configuration Source: https://github.com/realm/realm-dart/blob/main/packages/realm/android/src/main/cpp/CMakeLists.txt This snippet defines the minimum CMake version, project name, and builds the shared library for the Realm plugin. ```cmake cmake_minimum_required(VERSION 3.10) set(PROJECT_NAME "realm") project(${PROJECT_NAME} LANGUAGES CXX) set(PLUGIN_NAME "realm_plugin") #make cmake output visible in build log file set(CMAKE_VERBOSE_MAKEFILE TRUE CACHE BOOL "" FORCE) add_library(${PLUGIN_NAME} SHARED "realm_plugin.cpp") ``` -------------------------------- ### Linker Options for Symbol Inclusion Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/src/CMakeLists.txt Ensures all symbols from RealmFFIStatic are included, as realm-dart resolves them at runtime. ```cmake # Force the linker to include all symbols from RealmFFIStatic. realm-dart resolves them at runtime, so the linker considers them unused. # TODO: Switch to $ when CMake releases it if(MSVC) target_link_options(realm_dart PRIVATE /WHOLEARCHIVE:$) elseif(APPLE) target_link_options(realm_dart PRIVATE -force_load $) else() target_link_options(realm_dart PRIVATE LINKER:--whole-archive $ LINKER:--no-whole-archive) endif() ``` -------------------------------- ### Windows Specific Compile Definitions Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/CMakeLists.txt Adds compile definitions for Windows builds to include minimal Windows.h and prefer Unicode variants. ```cmake if(CMAKE_SYSTEM_NAME MATCHES "^Windows") add_compile_definitions( WIN32_LEAN_AND_MEAN # include minimal Windows.h for faster builds UNICODE # prefer Unicode variants of Windows APIs over ANSI variants _UNICODE # prefer Unicode variants of C runtime APIs over ANSI variants ) endif() ``` -------------------------------- ### iOS Platform Specific Configuration Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/src/CMakeLists.txt Adds platform-specific source files, sets framework properties, and configures framework creation for iOS builds. ```cmake elseif(CMAKE_SYSTEM_NAME STREQUAL iOS) target_sources(realm_dart PRIVATE ios/platform.mm ) set_target_properties(realm_dart PROPERTIES FRAMEWORK TRUE MACOSX_FRAMEWORK_IDENTIFIER io.realm.dart MACOSX_FRAMEWORK_SHORT_VERSION_STRING "1.0.0" MACOSX_FRAMEWORK_BUNDLE_VERSION "1.0.0" ) target_link_options(realm_dart PRIVATE SHELL:-framework UIKIT) if(NOT $ENV{REALM_CI}) add_custom_command(TARGET realm_dart POST_BUILD COMMAND rm -rf ${OUTPUT_DIR}/realm_dart.xcframework COMMAND xcodebuild -create-xcframework -framework $/.. -output ${OUTPUT_DIR}/realm_dart.xcframework ) endif() endif() ``` -------------------------------- ### Application Target Definition Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/linux/CMakeLists.txt Defines the main executable target for the application, listing its source files and applying standard build 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}) ``` -------------------------------- ### Open a Realm and add objects Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Open a Realm and add some objects. ```dart var config = Configuration.local([Car.schema]); var realm = Realm(config); var car = Car("Tesla", "Model Y", kilometers: 5); realm.write(() { realm.add(car); }); ``` -------------------------------- ### App Directory and Pubspec Parsing Source: https://github.com/realm/realm-dart/blob/main/packages/realm/windows/CMakeLists.txt Determines the application directory, reads the pubspec.yaml file, and extracts the app name and bundle ID. ```cmake set(APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../..") # message ("APP_DIR is ${APP_DIR}") set(APP_PUBSPEC_FILE "${APP_DIR}/pubspec.yaml") # message ("APP_PUBSPEC_FILE is ${APP_PUBSPEC_FILE}") file(READ "${APP_PUBSPEC_FILE}" PUBSPEC_CONTENT) string(REGEX MATCH "name:[ \r\n\t]*([a-z0-9_]*)" _ ${PUBSPEC_CONTENT}) # message ("Pubspec name 0 is ${CMAKE_MATCH_0}") # message ("Package name is ${CMAKE_MATCH_1}") set(APP_DIR_NAME ${CMAKE_MATCH_1}) set(BUNDLE_ID ${CMAKE_MATCH_1}) add_definitions(-DAPP_DIR_NAME="${APP_DIR_NAME}") add_definitions(-DBUNDLE_ID="${BUNDLE_ID}") ``` -------------------------------- ### Execute Realm Metrics Command Source: https://github.com/realm/realm-dart/blob/main/packages/realm/linux/CMakeLists.txt Runs the Realm metrics command using the Dart tool, collecting verbose information. ```cmake # message("CMAKE_HOST_SYSTEM_VERSION ${CMAKE_HOST_SYSTEM_VERSION}") execute_process( COMMAND "${FLUTTER_ROOT}/bin/dart" "run" "realm" "metrics" "--verbose" "--flutter-root" "${FLUTTER_ROOT}/bin" "--target-os-type" "linux" "--target-os-version" "${CMAKE_HOST_SYSTEM_VERSION}" # "--pause-isolates-on-start" "--enable-vm-service" WORKING_DIRECTORY ${ABSOLUTE_PATH_APP_DIR} # COMMAND ${CMAKE_COMMAND} -E true OUTPUT_VARIABLE output RESULT_VARIABLE result # COMMAND_ERROR_IS_FATAL LAST ) message(STATUS "cmd output: ${output}") message(STATUS "cmd result: ${result}") ``` -------------------------------- ### Define Application and Bundle IDs Source: https://github.com/realm/realm-dart/blob/main/packages/realm/linux/CMakeLists.txt Adds preprocessor definitions for the application ID and bundle ID. ```cmake add_definitions(-DAPP_DIR_NAME="${APPLICATION_ID}") add_definitions(-DBUNDLE_ID="${BUNDLE_ID}") ``` -------------------------------- ### CMakeLists.txt Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/src/dart-dl/CMakeLists.txt Defines the dart-dl library and its include directories. ```cmake add_library(dart-dl OBJECT dart_api_dl.c dart_api_dl.h dart_api.h dart_native_api.h dart_version.h internal/dart_api_dl_impl.h ) target_include_directories(dart-dl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/internal ) ``` -------------------------------- ### Flutter Tool Backend Command Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/flutter/CMakeLists.txt Defines a custom command to execute the Flutter tool backend, which generates necessary build artifacts. ```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 ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Run Flutter executable Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Executes the Flutter command-line tool. ```shell # In `master` cd bin ./flutter ``` -------------------------------- ### Clone the repo Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Clones the Realm Dart repository and initializes submodules. ```shell git clone https://github.com/realm/realm-dart cd realm-dart git submodule update --init --recursive ``` -------------------------------- ### Preprocessor Definitions for Build Version Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/runner/CMakeLists.txt Adds preprocessor definitions to the build for various components of the Flutter version. ```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}") ``` -------------------------------- ### Application Directory and Pubspec Parsing Source: https://github.com/realm/realm-dart/blob/main/packages/realm/linux/CMakeLists.txt Determines the application directory, reads the pubspec.yaml file, and extracts the application name. ```cmake set(APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../..") file(REAL_PATH ${APP_DIR} ABSOLUTE_PATH_APP_DIR) # message ("ABSOLUTE_PATH_APP_DIR is ${ABSOLUTE_PATH_APP_DIR}") # message ("APP_DIR is ${APP_DIR}") set(APP_PUBSPEC_FILE "${APP_DIR}/pubspec.yaml") # message ("APP_PUBSPEC_FILE is ${APP_PUBSPEC_FILE}") file(REAL_PATH ${APP_PUBSPEC_FILE} ABSOLUTE_PATH_APP_PUBSPEC_FILE) # message ("ABSOLUTE_PATH_APP_PUBSPEC_FILE is ${ABSOLUTE_PATH_APP_PUBSPEC_FILE}") file(READ "${ABSOLUTE_PATH_APP_PUBSPEC_FILE}" PUBSPEC_CONTENT) string(REGEX MATCH "name:[ \r\n\t]*([a-z0-9_]*)" _ ${PUBSPEC_CONTENT}) # message ("Pubspec name 0 is ${CMAKE_MATCH_0}") # message ("Package name is ${CMAKE_MATCH_1}") set(BUNDLE_ID ${CMAKE_MATCH_1}) ``` -------------------------------- ### Ephemeral Directory and Configuration Inclusion Source: https://github.com/realm/realm-dart/blob/main/packages/realm/linux/CMakeLists.txt Sets the ephemeral directory and includes generated configuration, likely for Flutter integration. ```cmake # This works cause realm plugin is always accessed through the .plugin_symlinks directory. set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../ephemeral") include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### C++ Wrapper for Plugins Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/flutter/CMakeLists.txt Configures the static library for C++ wrappers used by plugins, linking against the Flutter library. ```cmake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/" ) list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/" ) list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/" ) # 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) ``` -------------------------------- ### Launch an emulator/simulator Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Launches a specified Flutter emulator or simulator. ```shell flutter emulators --launch apple_ios_simulator ``` -------------------------------- ### Xcode Build Setting for Code Signing Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/CMakeLists.txt Disables code signing for Xcode builds to avoid issues with empty identifiers. ```cmake if(APPLE) # TODO: allow code signing once we setup certificates on CI. # Otherwise, Xcode 15 will use an empty identifier, which will then be rejected when the app is submitted to the app store. # See https://github.com/realm/realm-dart/issues/1679 for more details. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO) endif() ``` -------------------------------- ### Android Platform Specific Configuration Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/src/CMakeLists.txt Adds platform-specific source files and linker options for Android builds. ```cmake if(ANDROID) target_sources(realm_dart PRIVATE android/platform.cpp ) # Core requires these options for the final *.so file. See more realm-core/CMakeLists.txt target_link_options(realm_dart PRIVATE LINKER:-gc-sections) # Add a custom target to strip the binary add_custom_target(strip ${CMAKE_STRIP} $) # 16 KB page size compatibility target_link_options(realm_dart PRIVATE "-Wl,-z,max-page-size=16384") target_link_options(realm_dart PRIVATE "-Wl,-z,common-page-size=16384") ``` -------------------------------- ### Realm Metrics Command Source: https://github.com/realm/realm-dart/blob/main/packages/realm/windows/CMakeLists.txt Executes a Dart command to gather Realm metrics for the Windows target OS, including verbose output and Flutter root information. ```cmake # message("CMAKE_HOST_SYSTEM_VERSION ${CMAKE_HOST_SYSTEM_VERSION}") execute_process( COMMAND "${FLUTTER_ROOT}\bin\dart.bat" "run" "realm" "metrics" "--verbose" "--flutter-root" "${FLUTTER_ROOT}\bin" "--target-os-type" "windows" "--target-os-version" "${CMAKE_HOST_SYSTEM_VERSION}" #"--pause-isolates-on-start" "--enable-vm-service" # COMMAND ${CMAKE_COMMAND} -E true OUTPUT_VARIABLE output RESULT_VARIABLE result # COMMAND_ERROR_IS_FATAL LAST ) message(STATUS "cmd output: ${output}") message(STATUS "cmd result: ${result}") ``` -------------------------------- ### Initialize App Services App client and authenticate a user Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Initializes the App Services `App` client and authenticates a user using anonymous credentials. ```dart String appId = ""; final appConfig = AppConfiguration(appId); final app = App(appConfig); final user = await app.logIn(Credentials.anonymous()); ``` -------------------------------- ### Import Realm Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Import Realm in a dart file `app.dart` ```dart import 'package:realm/realm.dart'; // import realm package part 'app.realm.dart'; // declare a part file. @RealmModel() // define a data model class named `_Car`. class _Car { late String make; late String model; int? kilometers = 500; } ``` -------------------------------- ### Import Realm Source: https://github.com/realm/realm-dart/blob/main/README.md Import Realm in a dart file `app.dart` ```dart import 'package:realm/realm.js'; // import realm package part 'app.realm.dart'; // declare a part file. @RealmModel() // define a data model class named `_Car`. class _Car { late String make; late String model; int? kilometers = 500; } ``` -------------------------------- ### Run all tests Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Runs all project tests using melos. ```shell melos run test ``` -------------------------------- ### Project-level Configuration Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/CMakeLists.txt Sets the minimum CMake version, project name, and executable name. ```cmake cmake_minimum_required(VERSION 3.14) project(tests 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 "tests") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Library Definition and Linking Source: https://github.com/realm/realm-dart/blob/main/packages/realm_dart/src/CMakeLists.txt Defines the realm_dart shared library, specifies source and header files, and links against necessary libraries. ```cmake set(SOURCES realm_dart.cpp realm_dart_logger.cpp realm_dart_decimal128.cpp realm_dart_scheduler.cpp realm_dart_sync.cpp realm-core/src/external/IntelRDFPMathLib20U2/LIBRARY/src/bid128_noncomp.c ) set(HEADERS realm_dart.h realm_dart.hpp realm_dart_logger.h realm_dart_scheduler.h realm_dart_scheduler.h realm_dart_sync.h realm-core/src/realm.h ) add_library(realm_dart SHARED ${SOURCES} ${HEADERS}) target_compile_definitions(RealmFFIStatic PUBLIC -DRealm_EXPORTS) target_link_libraries(realm_dart dart-dl RealmFFIStatic Realm::ObjectStore) ``` -------------------------------- ### Apply Standard Settings Function Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/CMakeLists.txt A function to apply standard compilation features, options, and definitions to a target. ```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() ``` -------------------------------- ### Flutter Library Configuration Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/flutter/CMakeLists.txt Defines and configures the Flutter library, including its DLL, headers, and ICU data file. ```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) 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}/" ) 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 Command Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/linux/flutter/CMakeLists.txt A custom command to execute the Flutter tool backend script, which is necessary for building the Flutter library and its headers. The '_phony_' output is used to ensure the command runs on every build. ```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 ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Profile Build Mode Settings Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/CMakeLists.txt Defines linker and compiler flags for the Profile build mode, inheriting from Release settings. ```cmake # 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}") ``` -------------------------------- ### Ephemeral Directory and Generated Config Source: https://github.com/realm/realm-dart/blob/main/packages/realm/windows/CMakeLists.txt Includes generated configuration from the ephemeral directory, which is assumed to be located relative to the current source directory. ```cmake # This works cause realm plugin is always accessed through the .plugin_symlinks directory. # For example the tests app refers to the realm plugin using this path .../realm-dart/flutter/realm_flutter/tests/windows/flutter/ephemeral/.plugin_symlinks/realm/windows set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../ephemeral") include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Unicode Support Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/CMakeLists.txt Adds definitions to enable Unicode support for all projects. ```cmake # Use Unicode for all projects. add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### C++ Wrapper for Runner Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/flutter/CMakeLists.txt Configures the static library for C++ wrappers used by the runner application, 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) ``` -------------------------------- ### Create Git worktrees for branches Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Creates Git worktrees for 'stable' and 'beta' branches of the Flutter repository. ```shell git worktree add ../stable stable git worktree add ../beta beta ``` -------------------------------- ### Realm Bundled Libraries Source: https://github.com/realm/realm-dart/blob/main/packages/realm/linux/CMakeLists.txt Defines the path to the bundled Realm Dart shared library for Linux. ```cmake set(realm_bundled_libraries "${PROJECT_SOURCE_DIR}/binary/linux/librealm_dart.so" PARENT_SCOPE ) ``` -------------------------------- ### Build artifacts Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Builds the project artifacts using melos. ```shell melos run build ``` -------------------------------- ### List Prepend Function Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/linux/flutter/CMakeLists.txt A custom CMake function to prepend a prefix to each element in a list, as list(TRANSFORM ... PREPEND ...) is not available in CMake version 3.10. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Flutter Integration Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/CMakeLists.txt Includes the Flutter managed directory and the runner subdirectory for application build. ```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") # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Flutter Library Configuration Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/linux/flutter/CMakeLists.txt Defines the Flutter library, its headers, and links against system libraries like GTK, GLIB, and GIO. ```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) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Declare part file for Realm model Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Declares a part file for Realm model generation, placed after imports. ```dart part 'catalog.realm.dart'; ``` -------------------------------- ### Open a synced realm Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Opens a synced realm configuration with the specified user and schema. ```dart final config = Configuration.flexibleSync(user, [Task.schema]); final realm = Realm(config); ``` -------------------------------- ### Flutter Tool Build Dependency Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/runner/CMakeLists.txt Ensures that the Flutter tool's assembly process is completed before the application target is built. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Build Configuration Option Source: https://github.com/realm/realm-dart/blob/main/packages/realm/tests/windows/CMakeLists.txt Defines build configuration options (Debug, Profile, Release) based on whether the generator is multi-config. ```cmake # 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) 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() ``` -------------------------------- ### Import realm_dart in a Dart file Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Import statement for using the realm_dart library in a Dart file. ```dart import 'package:realm_dart/realm.dart'; ``` -------------------------------- ### Add realm_dart package to a Dart application Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Command to add the realm_dart package as a dependency in a Dart project. ```bash dart pub add realm_dart ``` -------------------------------- ### Import Realm in a Dart file Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Import statement for using the Realm library in a Dart file. ```dart import 'package:realm/realm.dart'; ``` -------------------------------- ### Import realm_dart in a Dart file Source: https://github.com/realm/realm-dart/blob/main/README.md Import statement for using realm_dart in a Dart file. ```dart import 'package:realm_dart/realm.'; ``` -------------------------------- ### Add realm package to a Flutter application Source: https://github.com/realm/realm-dart/blob/main/packages/realm_common/README.md Command to add the realm package as a dependency in a Flutter project. ```bash flutter pub add realm ``` -------------------------------- ### Import Realm in a Dart file Source: https://github.com/realm/realm-dart/blob/main/README.md Import statement for using Realm in a Dart file. ```dart import 'package:realm/realm.'; ``` -------------------------------- ### Define the current branch Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Creates a symbolic link to point the 'current' branch to the 'stable' branch. ```shell ln -s stable current ``` -------------------------------- ### Build native code for a specific target Source: https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md Builds the native code for a specific target and mode. ```shell cd packages/realm_dart # Example using `macOSArm64` as target and debug mode. dev build -m debug -t macOSArm64 ```