### Serve Dart web app using webdev Source: https://github.com/vm75/sweph.dart/blob/main/example.dart/README.md Navigate to the example project's folder and use `webdev serve` to run the Dart web application. This command starts a local development server, typically accessible at http://localhost:8080. ```Shell webdev serve ``` -------------------------------- ### Run Dart command-line application Source: https://github.com/vm75/sweph.dart/blob/main/example.dart/README.md To execute the Dart command-line application, navigate to the example folder and run `dart run`. Note that precompiled libraries are provided for Windows and Linux; other platforms may require building the native components using CMake in the `native/` folder. ```Shell dart run ``` -------------------------------- ### Activate webdev for Dart web app development Source: https://github.com/vm75/sweph.dart/blob/main/example.dart/README.md This command activates the `webdev` package globally, which is a prerequisite for serving Dart web applications. Ensure you have the Dart SDK installed and configured. ```Shell dart pub global activate webdev ``` -------------------------------- ### Install Application Executable Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Installs the main application executable (`BINARY_NAME`) to the specified installation prefix. This ensures the compiled application is placed in the correct runtime location. ```CMake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Configure Installation Paths Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Defines variables for the installation directory structure. It sets the build bundle directory to the target file's location, makes the 'install' step default for Visual Studio, and initializes the `CMAKE_INSTALL_PREFIX` to the build bundle directory if not already set. It also defines subdirectories for data and libraries within the installation prefix. ```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 Flutter Assets and AOT Library Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Manages the installation of Flutter application assets and the AOT (Ahead-of-Time) compiled library. It first removes any stale asset directories to ensure a fresh copy, then installs the current build's assets. The AOT library is installed only for 'Profile' and 'Release' builds. ```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(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Conditionally installs any bundled plugin libraries if the `PLUGIN_BUNDLED_LIBRARIES` variable is set. These libraries are placed in the installation's library bundle directory, making them available to the application at runtime. ```CMake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Native Assets Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Copies native assets generated by `build.dart` from all packages into the installation's library bundle directory. This ensures platform-specific native code is available to the application. ```CMake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Initialize and Use Sweph for Astronomical Calculations in Dart Source: https://github.com/vm75/sweph.dart/blob/main/README.md This example demonstrates how to initialize the Sweph library, including loading bundled ephemeris files, and then perform basic astronomical calculations like getting the library version and calculating the Moon's longitude. It also shows how to set the sidereal mode with different flags and parameters. Note that ephemeris file handling differs between Web and non-Web platforms. ```Dart import 'package:sweph/sweph.dart'; Future main() async { // Sweph comes bundled with some ephe file. These are available for Flutter but not for vanilla Dart // These or any other bundled ephe files can be initialized during Sweph init // These are coped to /ephe_files folder for non-Web platforms // For Web, this is the only way to provide ephe files, and they are loaded into memory await Sweph.init( modulePath: 'sweph', // where to load module from. epheAssets: [ "packages/sweph/assets/ephe/sefstars.txt", ], assetLoader: SomeLoader(), // platform-specific asset loader. epheFilesPath: 'ephe_files', // where to store ephe files. ); // refer to example. Both Flutter and vanilla Dart examples are available // alternately if a folder already contains ephe files, Sweph can be used in sync mode like this: // await Sweph.swe_set_ephe_path() // This is not available for Web print('sweph.swe_version = ${Sweph.swe_version()}'); print('Moon longitude on 2022-06-29 02:52:00 UTC = ${Sweph.swe_calc_ut(Sweph.swe_julday(2022, 6, 29, (2 + 52 / 60), CalendarType.SE_GREG_CAL), HeavenlyBody.SE_MOON, SwephFlag.SEFLG_SWIEPH).longitude}'); // Most methods use positional parameters, not named. So if some positional parameters take default values, please refer to original documentation // If only some specific flags are allowed for a method, it is restricted via the enumerated flags // For example, to set the sidereal mode to Lahiri with projection onto solar system plane and custom t0 in UT Sweph.swe_set_sid_mode(SiderealMode.SE_SIDM_LAHIRI, SiderealModeFlag.SE_SIDBIT_SSY_PLANE, 123.45 /* t0 */); // or, to set the sidereal mode to Lahiri with no flags and custom ayan_t0 in UT Sweph.swe_set_sid_mode(SiderealMode.SE_SIDM_LAHIRI, SiderealModeFlag.SE_SIDBIT_NONE, 0.0 /* t0 */, 987.65 /* ayan_t0 */); } ``` -------------------------------- ### Install Flutter Core Runtime Files Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Installs essential Flutter runtime files, including the ICU data file and the Flutter library, to their respective data and library bundle directories. These files are crucial for the application's execution. ```CMake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Swiss Ephemeris Fixed Star Data Examples Source: https://github.com/vm75/sweph.dart/blob/main/assets/ephe/sefstars.txt Examples of fixed star data records from `sefstars.txt`. Each record provides astronomical parameters like name, ICRS coordinates (right ascension and declination), proper motion, radial velocity, annual parallax, and visual magnitude. Lines starting with '#' are comments and are ignored by the parser. ```Data Aldebaran ,alTau,ICRS,04,35,55.23907,+16,30,33.4885,63.45,-188.94,54.26,48.94,0.86, 16, 629 Rohini ,alTau,ICRS,04,35,55.23907,+16,30,33.4885,63.45,-188.94,54.26,48.94,0.86, 16, 629 Algol ,bePer,ICRS,03,08,10.13245,+40,57,20.3280,2.99,-1.66,4,36.27,2.12, 40, 673 Antares ,alSco,ICRS,16,29,24.45970,-26,25,55.2094,-12.11,-23.3,-3.5,5.89,0.91,-26,11359 Regulus ,alLeo,ICRS,10,08,22.31099,+11,58,01.9516,-248.73,5.59,5.9,41.13,1.4, 12, 2149 #Sirius ,alCMa,ICRS,06,45,08.91728,-16,42,58.0171,0,0,0,379.21,-1.46,-16, 1591 Sirius ,alCMa,ICRS,06,45,08.91728,-16,42,58.0171,-546.01,-1223.07,-5.5,379.21,-1.46,-16, 1591 ``` -------------------------------- ### Define Installation Bundle Rules Source: https://github.com/vm75/sweph.dart/blob/main/example/linux/CMakeLists.txt Configures the installation process to create a relocatable bundle in the build directory. It ensures a clean bundle by removing previous contents and installs the executable, ICU data, Flutter library, bundled plugins, and native assets into the appropriate bundle subdirectories. ```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 ``` -------------------------------- ### CMake: Configure and Install Flutter Assets Source: https://github.com/vm75/sweph.dart/blob/main/example/linux/CMakeLists.txt This CMake snippet defines the standard directory name for Flutter assets and then configures their installation. It includes a step to recursively remove any existing assets in the destination directory before copying the new ones from the project's build output into the application bundle's data directory. ```CMake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### CMake: Conditionally Install AOT Library Source: https://github.com/vm75/sweph.dart/blob/main/example/linux/CMakeLists.txt This CMake snippet handles the installation of the Ahead-Of-Time (AOT) compiled library. The installation is conditional, ensuring that the AOT library is only installed when the build type is not 'Debug', typically for release or profile builds to optimize performance and reduce size. ```CMake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Define Flutter Tool Backend Custom Commands Source: https://github.com/vm75/sweph.dart/blob/main/example/linux/flutter/CMakeLists.txt Configures custom CMake commands and targets to invoke the Flutter tool backend script. `add_custom_command` specifies the output files (Flutter library and headers) and the command to run, which executes the `tool_backend.sh` script. `add_custom_target` defines `flutter_assemble` as a dependency target, ensuring these outputs are generated. A `_phony_` file is used to force the command to run every time due to limitations in getting a full input/output list from the Flutter tool. ```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} ) ``` -------------------------------- ### Define CMake Project and Binary Name Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Sets the minimum required CMake version, defines the project name 'sweph_example' with CXX language support, and specifies the executable's on-disk name as 'sweph_example'. It also opts into modern CMake policy behaviors. ```CMake cmake_minimum_required(VERSION 3.14) project(sweph_example LANGUAGES CXX) set(BINARY_NAME "sweph_example") cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Include Application Runner Build Rules Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Includes the CMake build rules for the application's runner, typically located in a 'runner' subdirectory. This handles the compilation and linking of the main application executable. ```CMake add_subdirectory("runner") ``` -------------------------------- ### Set Profile Build Mode Flags Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Configures the linker and compiler flags for the 'Profile' build mode to mirror those of the 'Release' build mode. This ensures consistent optimization and linking behavior for performance profiling. ```CMake set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Include Flutter Build Rules Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Sets the path to the Flutter managed directory and includes its CMake build rules. This integrates the Flutter engine and associated tools into the project's build system. ```CMake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Include Generated Flutter Plugin Rules Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Includes CMake rules generated for Flutter plugins. These rules manage the building of plugins and their integration into the main application, ensuring all dependencies are correctly linked. ```CMake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Set Flutter Library and Build Path Variables Source: https://github.com/vm75/sweph.dart/blob/main/example/linux/flutter/CMakeLists.txt Defines and publishes key build-related variables to the parent scope for use in subsequent build steps and the install process. These variables include the path to the Flutter Linux GTK shared library, the ICU data file, the project's build directory, and the Ahead-Of-Time (AOT) compiled application library. ```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) ``` -------------------------------- ### Configure CMake Build Types Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Determines if the CMake generator supports multiple configurations (e.g., Visual Studio). If so, it sets 'Debug', 'Profile', and 'Release' as available configuration types. Otherwise, for single-configuration generators, it defaults the build type to 'Debug' if not already set, and defines the allowed build type strings. ```CMake get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() ``` -------------------------------- ### Enable Unicode Support Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Adds preprocessor definitions `_DUNICODE` and `_D_UNICODE` to ensure all projects linked against this configuration use Unicode character sets. This is a common setting for Windows applications. ```CMake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Define Standard Compilation Settings Function Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/CMakeLists.txt Defines a CMake function `APPLY_STANDARD_SETTINGS` that applies common compilation options to a specified target. These settings include C++17 standard compliance, specific compiler warnings, exception handling, and disabling exceptions for debug builds. This function is designed for broad application but advises caution when adding new options. ```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() ``` -------------------------------- ### Define Application Executable and Dependencies Source: https://github.com/vm75/sweph.dart/blob/main/example/linux/CMakeLists.txt Adds the main executable target, specifies its source files, applies standard build settings using the `APPLY_STANDARD_SETTINGS` function, links necessary libraries like Flutter and GTK, and adds a dependency on `flutter_assemble` to ensure the Flutter tool portions of the build are run. ```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) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") # 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}) # Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Configure Cross-Building Root Filesystem Source: https://github.com/vm75/sweph.dart/blob/main/example/linux/CMakeLists.txt Defines CMake variables for cross-compilation, setting the sysroot and search paths for programs, packages, libraries, and includes when `FLUTTER_TARGET_PLATFORM_SYSROOT` is specified. It also loads bundled libraries from the `lib/` directory relative to the binary. ```CMake # 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() ``` -------------------------------- ### Link Flutter Libraries and Include Directories Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/runner/CMakeLists.txt Links necessary Flutter-related libraries (`flutter`, `flutter_wrapper_app`) and the `dwmapi.lib` to the executable. It also adds the CMake source directory to the include paths, allowing the application to find its own header 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}") ``` -------------------------------- ### Define Flutter Tool Backend Custom Command and Assemble Target Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/flutter/CMakeLists.txt Sets up a custom command that invokes the Flutter tool backend script to generate necessary build artifacts. It uses a phony output file to force execution every time, as the full input/output list from the Flutter tool is not available. A custom target `flutter_assemble` is then created with dependencies on these generated files to ensure they are built. ```CMake set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Configure Executable Output and Plugin Inclusion Source: https://github.com/vm75/sweph.dart/blob/main/example/linux/CMakeLists.txt Sets the runtime output directory for the executable to a subdirectory, preventing users from attempting to run the unbundled copy directly. It also includes generated CMake rules for Flutter plugins, managing their build and integration into the application. ```CMake # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Configure C Library Compilation for Flutter Plugin with CMake Source: https://github.com/vm75/sweph.dart/blob/main/native/CMakeLists.txt This CMakeLists.txt file configures the `sweph` C library for a Flutter plugin. It sets the minimum CMake version, defines the project, adds the C source files to a shared library, specifies include directories, sets output properties, and adds preprocessor definitions for secure CRT and Windows DLL compilation. It also defines `DART_SHARED_LIB` for integration with Dart. ```CMake # The Flutter tooling requires that developers have CMake 3.10 or later # installed. You should not increase this version, as doing so will cause # the plugin to fail to compile for some customers of the plugin. cmake_minimum_required(VERSION 3.10) project(sweph_library VERSION 2.10.03 LANGUAGES C) add_library(sweph SHARED "sweph/src/swecl.c" "sweph/src/swedate.c" "sweph/src/swehel.c" "sweph/src/swehouse.c" "sweph/src/swejpl.c" "sweph/src/swemmoon.c" "sweph/src/swemplan.c" "sweph/src/sweph.c" "sweph/src/swephlib.c" ) target_include_directories(sweph PRIVATE "sweph/src/") set_target_properties(sweph PROPERTIES PUBLIC_HEADER swephexp.h OUTPUT_NAME "sweph" ) add_definitions(-D_CRT_SECURE_NO_WARNINGS) IF (WIN32) add_definitions(-DMAKE_DLL) ENDIF() target_compile_definitions(sweph PUBLIC DART_SHARED_LIB) ``` -------------------------------- ### Apply Standard Build Settings to Executable Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/runner/CMakeLists.txt Applies a predefined set of standard build settings to the application executable. This command can be removed or modified for applications that require different or custom build configurations. ```CMake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Configure Flutter Wrapper Plugin Static Library Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/flutter/CMakeLists.txt Creates a static library `flutter_wrapper_plugin` from core and plugin C++ sources. It applies standard settings, sets position-independent code and hidden visibility, links to the `flutter` interface library, and adds include directories and a dependency on `flutter_assemble`. ```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) ``` -------------------------------- ### Configure Flutter Wrapper App Static Library Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/flutter/CMakeLists.txt Creates a static library `flutter_wrapper_app` from core and app-specific C++ sources. It applies standard settings, links to the `flutter` interface library, adds include directories, and adds a dependency on `flutter_assemble`. ```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) ``` -------------------------------- ### Find and Check System Dependencies (GTK, GLIB, GIO) Source: https://github.com/vm75/sweph.dart/blob/main/example/linux/flutter/CMakeLists.txt Locates and verifies the presence of required system-level dependencies for Flutter's Linux GTK integration. It uses `find_package` for PkgConfig and `pkg_check_modules` to ensure GTK+-3.0, GLIB-2.0, and GIO-2.0 libraries are available and correctly configured. ```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) ``` -------------------------------- ### Define and Prefix Flutter Library Headers Source: https://github.com/vm75/sweph.dart/blob/main/example/linux/flutter/CMakeLists.txt Appends a comprehensive list of Flutter library header files (e.g., `fl_basic_message_channel.h`, `flutter_linux.h`) to the `FLUTTER_LIBRARY_HEADERS` variable. It then uses the custom `list_prepend` function to add the `"${EPHEMERAL_DIR}/flutter_linux/"` prefix to each header path, ensuring correct include paths. ```CMake list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") ``` -------------------------------- ### Configure Basic Project Settings Source: https://github.com/vm75/sweph.dart/blob/main/example/linux/CMakeLists.txt Sets the minimum CMake version, defines the project name, specifies the executable's on-disk name, and assigns a unique GTK application identifier. It also opts into modern CMake behaviors to avoid warnings. ```CMake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "sweph_example") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "org.duckdns.vm75.sweph_example") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Define CMake Project and Minimum Version Source: https://github.com/vm75/sweph.dart/blob/main/example/windows/runner/CMakeLists.txt Sets the minimum required CMake version to 3.14 and defines the project named 'runner', specifying that it uses CXX (C++) language support. ```CMake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) ``` -------------------------------- ### Define Libraries to Bundle with Plugin Source: https://github.com/vm75/sweph.dart/blob/main/windows/CMakeLists.txt Lists the absolute paths to libraries that should be bundled with the plugin. This specific entry includes the `sweph` target file, which is defined in the `../native/CMakeLists.txt`. The `PARENT_SCOPE` keyword ensures the variable is set in the parent directory's scope, making it accessible to other parts of the build system. ```CMake set(sweph_bundled_libraries # Defined in ../native/CMakeLists.txt. # This can be changed to accomodate different builds. $ PARENT_SCOPE ) ```