### Install Dependencies with Python and Conan Source: https://github.com/swift-project/pilotclient/wiki/Build:-Build-with-CLion Installs project dependencies using a Python virtual environment and Conan package manager. This requires Python 3 and Conan to be installed. ```bash python3 -m venv .venv source .venv/bin/activate # on Linux und macOS .venv\Scripts\activate.bat # on Windows pip install conan conan install . --output-folder=build_conan --build=missing --deployer=full_deploy ``` -------------------------------- ### Install 'simulatoremulated' Library Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/emulated/CMakeLists.txt Defines the installation rules for the 'simulatoremulated' library. It specifies that the library should be installed in the `bin/plugins/simulator` directory relative to the installation prefix, for both library and runtime destinations. ```cmake install(TARGETS simulatoremulated LIBRARY DESTINATION bin/plugins/simulator RUNTIME DESTINATION bin/plugins/simulator ) ``` -------------------------------- ### Clone Swift Project PilotClient Repository Source: https://github.com/swift-project/pilotclient/wiki/Build:-Build-with-CLion This snippet clones the PilotClient Git repository and updates its submodules. Ensure Git is installed before running these commands. ```sh git clone https://github.com/swift-project/pilotclient.git git submodule update --init ``` -------------------------------- ### General Installation Rules (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/xswiftbus/CMakeLists.txt This section defines the general installation rules for the project. It specifies that the 'LegacyData' directory should be installed to the 'xswiftbus' destination, and configuration files like 'xswiftbus.conf' and 'readme.txt' are installed along with the built application. ```cmake install(DIRECTORY LegacyData DESTINATION xswiftbus) install(FILES xswiftbus.conf ${CMAKE_CURRENT_BINARY_DIR}/readme.txt DESTINATION xswiftbus) ``` -------------------------------- ### Install GUI Target and Resources in CMake Source: https://github.com/swift-project/pilotclient/blob/main/src/gui/CMakeLists.txt Defines installation rules for the 'gui' target and associated resources. Libraries are installed to 'lib', executables/DLLs to 'bin', and shared resources to the specified installation prefix. ```cmake install(TARGETS gui LIBRARY DESTINATION lib RUNTIME DESTINATION bin ) install(DIRECTORY share/qss DESTINATION ${CMAKE_INSTALL_PREFIX}/share/) ``` -------------------------------- ### Installing the 'misc' Target Source: https://github.com/swift-project/pilotclient/blob/main/src/misc/CMakeLists.txt Defines installation rules for the 'misc' target, specifying where the library and executable files should be placed when the project is installed. Libraries are installed to 'lib' and executables to 'bin'. ```cmake install(TARGETS misc LIBRARY DESTINATION lib RUNTIME DESTINATION bin ) ``` -------------------------------- ### Install simulatormsfs Library Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/msfs/CMakeLists.txt Installs the 'simulatormsfs' target as a library and runtime file into the 'bin/plugins/simulator' directory relative to the installation prefix. ```cmake install(TARGETS simulatormsfs LIBRARY DESTINATION bin/plugins/simulator RUNTIME DESTINATION bin/plugins/simulator ) ``` -------------------------------- ### CMake: Install simulatormsfs2024 Target Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/msfs2024/CMakeLists.txt This CMake 'install' command specifies where the 'simulatormsfs2024' target should be installed. The library and runtime files will be placed in the 'bin/plugins/simulator' directory relative to the installation prefix. ```cmake install(TARGETS simulatormsfs2024 LIBRARY DESTINATION bin/plugins/simulator RUNTIME DESTINATION bin/plugins/simulator ) ``` -------------------------------- ### Install Swift Pilot Client Library (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/input/CMakeLists.txt Installs the built 'input' library to the 'lib' directory and its runtime components to the 'bin' directory. This makes the library accessible for use in other projects. ```cmake install(TARGETS input LIBRARY DESTINATION lib RUNTIME DESTINATION bin ) ``` -------------------------------- ### Install simulatorp3d Target (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/p3d/CMakeLists.txt Configures the installation of the simulatorp3d library. It specifies the destination directories for the library and runtime files when the project is installed. ```cmake install(TARGETS simulatorp3d LIBRARY DESTINATION bin/plugins/simulator RUNTIME DESTINATION bin/plugins/simulator ) ``` -------------------------------- ### Initialize CApplication and Network Request (C++) Source: https://context7.com/swift-project/pilotclient/llms.txt Demonstrates the initialization of the CApplication framework, including command-line argument parsing, setup loading, and core facade configuration. It also shows how to initiate a network request and handle the response using C++ with Qt. ```cpp #include #include "core/application.h" #include "core/corefacadeconfig.h" using namespace swift::core; using namespace swift::misc; int main(int argc, char *argv[]) { QCoreApplication qa(argc, argv); // Create swift application instance CApplication app("myswiftapp", CApplicationInfo::PilotClientCore); // Add command line options app.addDBusAddressOption(); app.addNetworkOptions(); app.addAudioOptions(); // Parse command line and load global setup if (!app.parseCommandLineArgsAndLoadSetup()) { return EXIT_FAILURE; } // Configure core facade for local contexts CCoreFacadeConfig config; config.setContextMode(CCoreFacadeConfig::Local); config.setAudioMode(CCoreFacadeConfig::Audio); // Initialize contexts and start core facade CStatusMessageList msgs = app.initContextsAndStartCoreFacade(config); if (msgs.hasErrorMessages()) { app.cmdLineErrorMessage(msgs); return EXIT_FAILURE; } // Access network context auto *networkContext = app.getIContextNetwork(); if (networkContext) { // Connect signals QObject::connect(networkContext, &IContextNetwork::connectionStatusChanged, [](const CConnectionStatus &from, const CConnectionStatus &to) { qDebug() << "Connection status:" << from.toQString() << "->" << to.toQString(); }); } // Perform network request CUrl url("https://api.swift-project.org/resource"); app.getFromNetwork(url, [](QNetworkReply *reply) { if (reply->error() == QNetworkReply::NoError) { QByteArray data = reply->readAll(); qDebug() << "Downloaded:" << data.size() << "bytes"; } reply->deleteLater(); }); return app.exec(); } ``` -------------------------------- ### Cross-Platform Installation (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/swiftdata/CMakeLists.txt Configures the installation rules for the 'swiftdata' target. On macOS, it's installed to the 'bin' directory within the bundle; otherwise, it's installed to the default location. ```cmake if(APPLE) install(TARGETS swiftdata BUNDLE DESTINATION bin) else() install(TARGETS swiftdata) endif() ``` -------------------------------- ### CMake: Install 'fscommon' Library Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/fscommon/CMakeLists.txt Specifies installation rules for the 'fscommon' library and its runtime components. Both are installed into the 'bin' directory relative to the installation prefix. ```cmake install(TARGETS fscommon LIBRARY DESTINATION bin RUNTIME DESTINATION bin ) ``` -------------------------------- ### Manage Dependencies and Install Targets (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/swiftlauncher/CMakeLists.txt Defines build dependencies and installation rules for the 'swiftlauncher' target. It ensures that 'resources' are built before 'swiftlauncher' and handles platform-specific installation destinations. ```cmake add_dependencies(swiftlauncher resources) if(WIN32) add_dependencies(swiftlauncher copy_externals_to_build_dir) endif() if(APPLE) install(TARGETS swiftlauncher BUNDLE DESTINATION bin) else() install(TARGETS swiftlauncher) endif() ``` -------------------------------- ### Include Installation Script Source: https://github.com/swift-project/pilotclient/blob/main/CMakeLists.txt Includes a CMake script named 'install.cmake' located in the 'cmake' directory. This script likely contains custom installation rules for the project. ```cmake include(cmake/install.cmake) ``` -------------------------------- ### CMake: Install 'fsxcommon' Library Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/fsxcommon/CMakeLists.txt Defines the installation rules for the 'fsxcommon' library. It specifies that the library file should be installed in the 'bin' directory, and any runtime components should also be placed in the 'bin' directory. ```cmake install(TARGETS fsxcommon LIBRARY DESTINATION bin RUNTIME DESTINATION bin ) ``` -------------------------------- ### CMake: Install Targets Configuration Source: https://github.com/swift-project/pilotclient/blob/main/src/core/CMakeLists.txt Defines the installation rules for the 'core' target in CMake. It specifies that the 'core' target should be installed as a library in the 'lib' directory and as a runtime executable in the 'bin' directory. ```cmake install(TARGETS core LIBRARY DESTINATION lib RUNTIME DESTINATION bin ) ``` -------------------------------- ### Define Dependencies and Installation Rules (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/swiftcore/CMakeLists.txt Sets build dependencies for the 'swiftcore' target, including 'resources' and platform-specific 'copy_externals_to_build_dir' for Windows. It also defines installation rules, installing to 'bin' on macOS and the default location otherwise. ```cmake add_dependencies(swiftcore resources) if(WIN32) add_dependencies(swiftcore copy_externals_to_build_dir) endif() if(APPLE) install(TARGETS swiftcore BUNDLE DESTINATION bin) else() install(TARGETS swiftcore) endif() ``` -------------------------------- ### Install xswiftbus Library and Configure Permissions (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/xswiftbus/CMakeLists.txt This CMake command installs the 'xswiftbus' target library to the 'xswiftbus/64' directory. It also sets file permissions to allow read and write access for the owner, and read access for the group and world, ensuring proper deployment and security. ```cmake install(TARGETS xswiftbus LIBRARY DESTINATION xswiftbus/64 RUNTIME DESTINATION xswiftbus/64 PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ ) ``` -------------------------------- ### Install simulatorflightgear Library (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/flightgear/CMakeLists.txt Configures the installation of the simulatorflightgear library. It specifies the destination directories for both the library file and any associated runtime files. This ensures the library is placed correctly in the build output for deployment. ```cmake install(TARGETS simulatorflightgear LIBRARY DESTINATION bin/plugins/simulator RUNTIME DESTINATION bin/plugins/simulator ) ``` -------------------------------- ### Enable Swift Unit Tests Build Configuration Source: https://github.com/swift-project/pilotclient/wiki/Build:-Configure This example shows how to add a specific cache variable to `CMakeUserPresets.json` to enable the building of unit tests for the Swift Pilot Client. This is done by setting `SWIFT_BUILD_UNIT_TESTS` to 'ON'. ```json "cacheVariables": { "SWIFT_BUILD_UNIT_TESTS": "ON" } ``` -------------------------------- ### Extensible JSON Example for Aircraft Lights Source: https://github.com/swift-project/pilotclient/wiki/Knowledgebase-Programming:-Draft-Protocol-Spec:-Aircraft-Parts-Configuration-Packets Shows an extended version of the aircraft lights JSON object, demonstrating extensibility by adding a 'taxi' property. This highlights how new attributes can be incorporated without affecting older systems that may not recognize them. ```json { "strobe": false, "landing": false, "taxi": true } ``` -------------------------------- ### JSON Example for Aircraft Lights Source: https://github.com/swift-project/pilotclient/wiki/Knowledgebase-Programming:-Draft-Protocol-Spec:-Aircraft-Parts-Configuration-Packets Demonstrates the structure of a JSON object used to control aircraft lights. It includes boolean values for individual lights like strobe, landing, and taxi. This object can be extended with new light types without breaking compatibility. ```json { "strobe": false, "landing": false, "taxi": true, "beacon": false, "nav": true, "logo": false } ``` -------------------------------- ### CMake: Define and Configure simulatorfsx Shared Library Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/fsx/CMakeLists.txt Defines the 'simulatorfsx' shared library, specifying its source files, output directories, include paths, linked libraries (fscommon, fsxcommon, core, misc, Qt::Core), and installation destinations. ```cmake add_library(simulatorfsx SHARED simulatorfsx.cpp simulatorfsx.h simulatorfsx.json simulatorfsxfactory.cpp simulatorfsxfactory.h ) set_target_properties(simulatorfsx PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/bin/plugins/simulator) set_target_properties(simulatorfsx PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/bin/plugins/simulator) target_include_directories(simulatorfsx PUBLIC ${PROJECT_SOURCE_DIR}/src) target_link_libraries(simulatorfsx PUBLIC fscommon fsxcommon core misc Qt::Core ) install(TARGETS simulatorfsx LIBRARY DESTINATION bin/plugins/simulator RUNTIME DESTINATION bin/plugins/simulator ) ``` -------------------------------- ### Define and Configure simulatorfsxconfig Library (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/fsxconfig/CMakeLists.txt Defines the 'simulatorfsxconfig' shared library, setting its source files, output locations, include directories, and linking against other libraries like 'gui', 'misc', 'Qt::Core', and 'fsxcommon'. It also specifies installation paths for the library. ```cmake add_library(simulatorfsxconfig SHARED simulatorfsxconfig.cpp simulatorfsxconfig.h simulatorfsxconfig.json ) set_target_properties(simulatorfsxconfig PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/bin/plugins/simulator) set_target_properties(simulatorfsxconfig PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/bin/plugins/simulator) target_include_directories(simulatorfsxconfig PUBLIC ${PROJECT_SOURCE_DIR}/src) target_link_libraries(simulatorfsxconfig PUBLIC gui misc Qt::Core PRIVATE fsxcommon ) install(TARGETS simulatorfsxconfig LIBRARY DESTINATION bin/plugins/simulator RUNTIME DESTINATION bin/plugins/simulator ) ``` -------------------------------- ### Define and Configure simulatorxplaneconfig Library (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/xplaneconfig/CMakeLists.txt This snippet defines a shared library named 'simulatorxplaneconfig', lists its source files, sets its output directories, specifies public include directories, links necessary libraries, and defines installation rules. It also configures platform-specific runtime paths for macOS and Unix-like systems. ```cmake add_library(simulatorxplaneconfig SHARED simulatorxplaneconfig.cpp simulatorxplaneconfig.h simulatorxplaneconfigwindow.cpp simulatorxplaneconfigwindow.h simulatorxplaneconfigwindow.ui ) set_target_properties(simulatorxplaneconfig PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/bin/plugins/simulator) set_target_properties(simulatorxplaneconfig PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/bin/plugins/simulator) target_include_directories(simulatorxplaneconfig PUBLIC ${PROJECT_SOURCE_DIR}/src) target_link_libraries(simulatorxplaneconfig PUBLIC gui misc Qt::Core ) install(TARGETS simulatorxplaneconfig LIBRARY DESTINATION bin/plugins/simulator RUNTIME DESTINATION bin/plugins/simulator ) if(APPLE) set_target_properties(simulatorxplaneconfig PROPERTIES INSTALL_RPATH @loader_path/../../../lib) elseif(UNIX) set_target_properties(simulatorxplaneconfig PROPERTIES INSTALL_RPATH $ORIGIN/../../../lib) endif() ``` -------------------------------- ### Set Output Directories for 'simulatoremulated' Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/emulated/CMakeLists.txt Configures the output directories for the 'simulatoremulated' library. It ensures that the compiled library files are placed in the `${PROJECT_BINARY_DIR}/out/bin/plugins/simulator` directory, both for general library output and runtime execution. ```cmake set_target_properties(simulatoremulated PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/bin/plugins/simulator) set_target_properties(simulatoremulated PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/bin/plugins/simulator) ``` -------------------------------- ### Create Static Library with CMake Source: https://github.com/swift-project/pilotclient/blob/main/src/config/CMakeLists.txt Defines a static library named 'config' using CMake's add_library command. It lists the source files, header files, and generated configuration files required for the library. The library is linked against Qt::Core and includes specific directories. ```cmake add_library(config STATIC buildconfig.cpp buildconfig.h buildconfig.inc ${CMAKE_CURRENT_BINARY_DIR}/buildconfig_gen.inc ${CMAKE_CURRENT_BINARY_DIR}/buildconfig_gen.cpp ) target_link_libraries(config PUBLIC Qt::Core) target_include_directories(config PUBLIC ${PROJECT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR} ) set_property(TARGET config PROPERTY POSITION_INDEPENDENT_CODE ON) ``` -------------------------------- ### Specify Include Directories for 'simulatoremulated' Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/emulated/CMakeLists.txt Adds the source directory `${PROJECT_SOURCE_DIR}/src` as a public include directory for the 'simulatoremulated' library. This allows other parts of the project to include headers from this directory. ```cmake target_include_directories(simulatoremulated PUBLIC ${PROJECT_SOURCE_DIR}/src) ``` -------------------------------- ### Implement Simulator Plugin Interface (C++) Source: https://context7.com/swift-project/pilotclient/llms.txt This C++ code demonstrates how to implement the ISimulator interface for creating custom simulator plugins. It includes methods for connecting/disconnecting, updating aircraft positions, adding/removing remote aircraft, and retrieving simulator information. The associated JSON file provides metadata for plugin registration. ```cpp // Simulator plugin implementation pattern #include "plugins/simulator/plugincommon.h" #include "misc/simulation/simulatorplugininfo.h" class CSimulatorMyPlugin : public QObject, public ISimulator { Q_OBJECT Q_PLUGIN_METADATA(IID "org.swift_project.swift_core.simulator" FILE "simulatormyplugin.json") Q_INTERFACES(swift::core::ISimulator) public: // Implement required interface methods virtual bool connectToSimulator() override { // Connect to simulator SDK return true; } virtual bool disconnectFromSimulator() override { // Cleanup simulator connection return true; } virtual bool updateOwnSimulatorPosition(const CAircraftSituation &situation) override { // Update own aircraft position in simulator return true; } virtual bool addRemoteAircraft(const CSimulatedAircraft &aircraft) override { // Add multiplayer aircraft to simulator return true; } virtual bool removeRemoteAircraft(const CCallsign &callsign) override { // Remove multiplayer aircraft from simulator return true; } virtual CSimulatorInfo getSimulatorInfo() const override { return CSimulatorInfo("My Simulator", "MyPlugin", "1.0"); } }; // simulatormyplugin.json { "simulator": "MySimulator", "name": "My Simulator Plugin", "version": "1.0.0", "platforms": ["windows", "linux", "macos"] } ``` -------------------------------- ### Configure Build Files with CMake Source: https://github.com/swift-project/pilotclient/blob/main/src/config/CMakeLists.txt Uses CMake's configure_file command to process input files ending in '.in' and generate output configuration files. This is crucial for setting up build-specific configurations. ```cmake configure_file(buildconfig_gen.inc.in buildconfig_gen.inc) configure_file(buildconfig_gen.cpp.in buildconfig_gen.cpp) ``` -------------------------------- ### Install CLogHandler as Qt Message Handler (C++) Source: https://github.com/swift-project/pilotclient/wiki/Architecture:-Logging Installs the CLogHandler as the global Qt message handler. This is typically done in the application's main function to ensure all log messages are captured. It relies on the qInstallMessageHandler function from the Qt framework. ```cpp CLogHandler::instance()->install(); ``` -------------------------------- ### Set Installation RPATH for macOS and Unix Source: https://github.com/swift-project/pilotclient/blob/main/CMakeLists.txt Configures the RPATH (Run-time search path) for dynamic libraries based on the operating system. For Apple platforms, it's set relative to the loader path; for other Unix systems, it's relative to the installed library directory. ```cmake if(APPLE) set(CMAKE_INSTALL_RPATH @loader_path/../../../../lib) elseif(UNIX) set(CMAKE_INSTALL_RPATH $ORIGIN/../lib) endif() ``` -------------------------------- ### C++ Batched Settings Changes with RAII Source: https://github.com/swift-project/pilotclient/wiki/Architecture:-Caches Demonstrates how to perform batched changes to settings using a RAII object to ensure that a single signal is emitted for multiple modifications. This pattern groups changes and commits them atomically when the RAII object goes out of scope. ```cpp { auto batch = CSettingsCache::instance()->batchChanges(this); // RAII object m_fooSetting.set(1234); m_barSetting.set(5678); } // RAII object destroyed here, its destructor causes the changes to m_fooSetting and m_barSetting to be committed. ``` -------------------------------- ### Development: Copy xswiftbus to X-Plane Plugins (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/xswiftbus/CMakeLists.txt This CMake snippet defines a custom target 'copy_xswiftbus' intended for development workflows. It depends on the 'xswiftbus' target and uses CMake commands to install the application and then copy the installed 'xswiftbus' directory into a specified X-Plane plugins directory, facilitating rapid development and testing. ```cmake if (DEFINED SWIFT_DEV_X_PLANE_PLUGINS_DIR) # Copy xswiftbus to X-Plane folder for development add_custom_target(copy_xswiftbus DEPENDS xswiftbus COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_INSTALL_PREFIX}/xswiftbus ${SWIFT_DEV_X_PLANE_PLUGINS_DIR}/xswiftbus COMMENT "Installing xswiftbus into X-Plane plugins dir" ) endif () ``` -------------------------------- ### Link Libraries for 'simulatoremulated' Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/emulated/CMakeLists.txt Specifies the libraries that the 'simulatoremulated' library depends on. It links public dependencies like Qt modules ('Qt::Core', 'Qt::Widgets') and other project libraries ('misc', 'core', 'plugincommon'), as well as private dependencies ('gui'). ```cmake target_link_libraries(simulatoremulated PUBLIC Qt::Core misc core Qt::Widgets plugincommon PRIVATE gui ) ``` -------------------------------- ### Display Simulator Build Options Source: https://github.com/swift-project/pilotclient/blob/main/CMakeLists.txt Prints the build status of various simulator plugins to the console using `message(STATUS)`. This is helpful for verifying which simulator targets are enabled in the current build configuration. ```cmake message(STATUS "Simulators:") message(STATUS "\t FS9: ${SWIFT_BUILD_FS9_PLUGIN}") message(STATUS "\t FSX: ${SWIFT_BUILD_FSX_PLUGIN}") message(STATUS "\t P3D: ${SWIFT_BUILD_P3D_PLUGIN}") message(STATUS "\t MSFS: ${SWIFT_BUILD_MSFS_PLUGIN}") message(STATUS "\t MSFS2024: ${SWIFT_BUILD_MSFS2024_PLUGIN}") message(STATUS "\t XPLANE: ${SWIFT_BUILD_XPLANE_PLUGIN}") message(STATUS "\t XSWIFTBUS: ${SWIFT_BUILD_XPLANE_PLUGIN}") message(STATUS "\t FLIGHTGEAR: ${SWIFT_BUILD_FLIGHTGEAR_PLUGIN}") message(STATUS "\t EMULATED: ${SWIFT_BUILD_EMULATED_PLUGIN}") ``` -------------------------------- ### Subscribe to All Log Messages with CLogPattern (C++) Source: https://github.com/swift-project/pilotclient/wiki/Architecture:-Logging Demonstrates how to subscribe to specific types of log messages using CLogPattern. This example shows subscriptions for all warnings, all errors, and all messages with severity at or above warning. It connects the 'messageLogged' signal of the returned handler to a slot in the current class. ```cpp // a pattern which matches all warnings auto pattern = CLogPattern().withSeverity(CStatusMessage::SeverityWarning); // subscribe to all warnings auto *handler = CLogHandler::instance()->handlerForPattern(CLogPattern().withSeverity(CStatusMessage::SeverityWarning)); connect(handler, &CLogPatternHandler::messageLogged, this, &CFoo::mySlot); // subscribe to all errors auto *handler = CLogHandler::instance()->handlerForPattern(CLogPattern().withSeverity(CStatusMessage::SeverityError)); connect(handler, &CLogPatternHandler::messageLogged, this, &CFoo::mySlot); // subscribe to all warnings and errors auto *handler = CLogHandler::instance()->handlerForPattern(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityWarning)); connect(handler, &CLogPatternHandler::messageLogged, this, &CFoo::mySlot); ``` -------------------------------- ### Set Runtime Path for 'simulatoremulated' on Apple and Unix Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/emulated/CMakeLists.txt Configures the runtime search path (RPATH) for the 'simulatoremulated' library based on the operating system. On Apple systems, it's set to `@loader_path/../../../lib`, and on Unix systems, it's set to `$ORIGIN/../../../lib`. This helps the dynamic linker find dependent libraries. ```cmake if(APPLE) set_target_properties(simulatoremulated PROPERTIES INSTALL_RPATH @loader_path/../../../lib) elseif(UNIX) set_target_properties(simulatoremulated PROPERTIES INSTALL_RPATH $ORIGIN/../../../lib) endif() ``` -------------------------------- ### JSON Example for Aircraft Gear Status Source: https://github.com/swift-project/pilotclient/wiki/Knowledgebase-Programming:-Draft-Protocol-Spec:-Aircraft-Parts-Configuration-Packets Illustrates the JSON object structure for representing aircraft landing gear status. It allows for individual control of gear components like center, left, and right. The values indicate whether the gear is extended or retracted. ```json { "center": true, "left": true, "right": true } ``` -------------------------------- ### Define Executable and Add Sources (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/swiftlauncher/CMakeLists.txt Defines the 'swiftlauncher' executable and specifies its source files. For Windows, it conditionally adds a resource script. This is a fundamental step in building the application. ```cmake add_executable(swiftlauncher WIN32 main.cpp swiftlauncher.cpp swiftlauncher.h swiftlauncher.ui swiftlauncher.qrc ) if(WIN32) target_sources(swiftlauncher PRIVATE data.rc) endif() ``` -------------------------------- ### Get Commit ID and Set Commit Hash Compile Definition (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/xswiftbus/CMakeLists.txt This snippet includes a CMake tool script to retrieve the Git commit ID and then defines a preprocessor macro 'XSWIFTBUS_COMMIT' with this ID. This allows the build to embed the exact commit hash into the compiled plugin for traceability. ```cmake include(${PROJECT_SOURCE_DIR}/cmake/xswiftbus_tools.cmake) get_xswiftbus_commit_id() target_compile_definitions(xswiftbus PUBLIC XSWIFTBUS_COMMIT="${XSWIFTBUS_COMMIT_ID}") ``` -------------------------------- ### Define 'simulatoremulated' Shared Library Source: https://github.com/swift-project/pilotclient/blob/main/src/plugins/simulator/emulated/CMakeLists.txt Defines a shared library named 'simulatoremulated'. It lists all the source and header files (.cpp, .h, .ui, .json) that constitute the library. This is a standard CMake command for creating libraries. ```cmake add_library(simulatoremulated SHARED simulatoremulated.cpp simulatoremulated.h simulatoremulatedfactory.cpp simulatoremulatedfactory.h simulatoremulatedmonitordialog.cpp simulatoremulatedmonitordialog.h simulatoremulatedmonitordialog.ui simulatoremulated.json ) ``` -------------------------------- ### Windows-Specific DBUS Configuration (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/xswiftbus/CMakeLists.txt This snippet configures DBUS session bus address and authentication settings specifically for the Windows platform (WIN32). It uses CMake's `set` command to define variables and `configure_file` to process a template configuration file. The resulting configuration is then installed to a specific destination. ```cmake if(WIN32) set(DBUS_SESSION_BUS_LISTEN_ADDRESS "autolaunch:") set(DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL "") configure_file(${swift_SOURCE_DIR}/src/misc/share/dbus-1/session.conf.in ${CMAKE_CURRENT_BINARY_DIR}/session.conf) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/session.conf DESTINATION xswiftbus/64/share/dbus-1/) endif() ``` -------------------------------- ### Configure Install RPATH for Shared Libraries (CMake) Source: https://github.com/swift-project/pilotclient/blob/main/src/xswiftbus/CMakeLists.txt This command sets the RPATH (Run-time Search Path) for the 'xswiftbus' target, which is crucial for dynamic library loading on different platforms. It sets the path to '@loader_path/' on Apple systems and '$ORIGIN' on UNIX-like systems, ensuring the plugin can find its dependencies at runtime. ```cmake if(APPLE) set_target_properties(xswiftbus PROPERTIES INSTALL_RPATH @loader_path/) elseif(UNIX) set_target_properties(xswiftbus PROPERTIES INSTALL_RPATH $ORIGIN) endif() ```