From 0012404a5d05404b93046534b6e11043b6b23288 Mon Sep 17 00:00:00 2001 From: Nav Date: Wed, 10 May 2023 19:53:39 +0100 Subject: [PATCH] Added `EXCLUDE_INSIGHT` build flag. --- CMakeLists.txt | 63 +++++++++++++++++++++++++---------------- README.md | 24 ++++++++++++++++ src/Application.cpp | 23 +++++++++++++++ src/Application.hpp | 6 ++++ src/CMakeLists.txt | 5 +++- src/ProjectSettings.cpp | 6 ++++ src/ProjectSettings.hpp | 7 +++++ 7 files changed, 108 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43e212a5..09a59f8e 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,15 +11,7 @@ set(ENABLE_SANITIZERS off) set(CMAKE_AUTOMOC ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") -find_package(yaml-cpp 0.7.0 REQUIRED) -find_package(Qt6Core REQUIRED) -find_package(Qt6Gui REQUIRED) -find_package(Qt6Widgets REQUIRED) -find_package(Qt6Xml REQUIRED) -find_package(Qt6Svg REQUIRED) -find_package(Qt6UiTools REQUIRED) -find_package(Qt6SvgWidgets REQUIRED) -find_package(Qt6Network REQUIRED) +option(EXCLUDE_INSIGHT "Exclude the Insight component from this build" OFF) set(CMAKE_SKIP_BUILD_RPATH false) set(CMAKE_BUILD_RPATH_USE_ORIGIN true) @@ -52,6 +44,39 @@ if (${CMAKE_BUILD_TYPE} MATCHES "Debug") endif() add_executable(Bloom) +set_target_properties(Bloom PROPERTIES OUTPUT_NAME bloom) + +find_package(yaml-cpp 0.7.0 REQUIRED) +find_package(Qt6Core REQUIRED) +find_package(Qt6Xml REQUIRED) + +if (NOT ${EXCLUDE_INSIGHT}) + find_package(Qt6Widgets REQUIRED) + find_package(Qt6Gui REQUIRED) + find_package(Qt6Widgets REQUIRED) + find_package(Qt6Xml REQUIRED) + find_package(Qt6Svg REQUIRED) + find_package(Qt6UiTools REQUIRED) + find_package(Qt6SvgWidgets REQUIRED) + find_package(Qt6Network REQUIRED) + + target_link_libraries(Bloom Qt6::Gui) + target_link_libraries(Bloom Qt6::UiTools) + target_link_libraries(Bloom Qt6::Widgets) + target_link_libraries(Bloom Qt6::Xml) + target_link_libraries(Bloom Qt6::Svg) + target_link_libraries(Bloom Qt6::SvgWidgets) + target_link_libraries(Bloom Qt6::Network) +endif() + +target_link_libraries(Bloom -lstdc++fs) +target_link_libraries(Bloom -lpthread) +target_link_libraries(Bloom -lusb-1.0) +target_link_libraries(Bloom -lhidapi-libusb) +target_link_libraries(Bloom -lprocps) +target_link_libraries(Bloom ${YAML_CPP_LIBRARIES}) +target_link_libraries(Bloom Qt6::Core) +target_link_libraries(Bloom Qt6::Xml) target_sources( Bloom @@ -70,8 +95,6 @@ qt_add_resources( ) add_subdirectory(src) - -set_target_properties(Bloom PROPERTIES OUTPUT_NAME bloom) target_include_directories(Bloom PUBLIC ./) target_include_directories(Bloom PUBLIC ${YAML_CPP_INCLUDE_DIR}) @@ -83,20 +106,10 @@ if (${CMAKE_BUILD_TYPE} MATCHES "Debug") target_include_directories(Bloom PUBLIC /opt/Qt/6.2.4/Src) endif() -target_link_libraries(Bloom -lstdc++fs) -target_link_libraries(Bloom -lpthread) -target_link_libraries(Bloom -lusb-1.0) -target_link_libraries(Bloom -lhidapi-libusb) -target_link_libraries(Bloom -lprocps) -target_link_libraries(Bloom ${YAML_CPP_LIBRARIES}) -target_link_libraries(Bloom Qt6::Core) -target_link_libraries(Bloom Qt6::Gui) -target_link_libraries(Bloom Qt6::UiTools) -target_link_libraries(Bloom Qt6::Widgets) -target_link_libraries(Bloom Qt6::Xml) -target_link_libraries(Bloom Qt6::Svg) -target_link_libraries(Bloom Qt6::SvgWidgets) -target_link_libraries(Bloom Qt6::Network) +target_compile_definitions( + Bloom + PUBLIC $<$:EXCLUDE_INSIGHT> +) target_compile_options( Bloom diff --git a/README.md b/README.md index adc4e5ee..702df7f4 100644 --- a/README.md +++ b/README.md @@ -124,3 +124,27 @@ sudo cmake --install ./ --prefix [SOME_OTHER_INSTALLATION_DIR]; having to supply the full path: `sudo ln -s /opt/bloom/bin/bloom /usr/bin/;` - If you're installing on Ubuntu 20.04 or older, you may need to move the installed udev rules, as they're expected to reside in `/lib/udev/rules.d` on those systems. Move them via: `sudo mv /usr/lib/udev/rules.d/99-bloom.rules /lib/udev/rules.d/;` + +### Excluding Insight at build time + +The Insight component can be excluded at build time, via the `EXCLUDE_INSIGHT` flag. +You'll still need to satisfy the Qt dependency on the build machine, as other parts of Bloom use Qt, but you'll no +longer need to install GUI dependencies on every machine you intend to run Bloom on. Just build it once and distribute +the binary, along with the necessary shared objects. + +To identify the necessary shared objects, copy the binary to one of those machines and run `ldd [PATH_TO_BLOOM_BINARY]`. +That will output a list of all the dependencies that `ld` couldn't satisfy - those will be what you need to distribute +(or manually install on each machine). + +#### Example build excluding Insight + +```shell +# Build Bloom in [SOME_BUILD_DIR] +mkdir [SOME_BUILD_DIR]; +cd [SOME_BUILD_DIR]; + +cmake [PATH_TO_BLOOM_SOURCE] -DEXCLUDE_INSIGHT=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=[PATH_TO_QT_INSTALLATION]/gcc_64/; +cmake --build ./; + +... +``` diff --git a/src/Application.cpp b/src/Application.cpp index b38474f6..c8226276 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -47,8 +47,16 @@ namespace Bloom Logger::warning("This is a debug build - some functions may not work as expected"); #endif +#ifdef EXCLUDE_INSIGHT + Logger::warning( + "The Insight component has been excluded from this build. All Insight related configuration parameters " + "will be ignored." + ); +#endif + this->startup(); +#ifndef EXCLUDE_INSIGHT if (this->insightConfig->insightEnabled) { this->insight = std::make_unique( *(this->applicationEventListener), @@ -72,6 +80,7 @@ namespace Bloom this->shutdown(); return EXIT_SUCCESS; } +#endif // Main event loop while (Thread::getThreadState() == ThreadState::READY) { @@ -165,9 +174,11 @@ namespace Bloom Thread::setThreadState(ThreadState::SHUTDOWN_INITIATED); Logger::info("Shutting down Bloom"); +#ifndef EXCLUDE_INSIGHT if (this->insight != nullptr) { this->insight->shutdown(); } +#endif this->stopDebugServer(); this->stopTargetController(); @@ -283,6 +294,7 @@ namespace Bloom this->environmentConfig = selectedEnvironmentIt->second; +#ifndef EXCLUDE_INSIGHT if (this->environmentConfig->insightConfig.has_value()) { this->insightConfig = this->environmentConfig->insightConfig.value(); @@ -292,6 +304,7 @@ namespace Bloom } else { throw InvalidConfig("Insight configuration missing."); } +#endif if (this->environmentConfig->debugServerConfig.has_value()) { this->debugServerConfig = this->environmentConfig->debugServerConfig.value(); @@ -332,6 +345,10 @@ namespace Bloom std::cout << "Bloom v" << Application::VERSION.toString() << "\n"; +#ifdef EXCLUDE_INSIGHT + std::cout << "Insight has been excluded from this build.\n"; +#endif + #ifdef BLOOM_DEBUG_BUILD std::cout << "DEBUG BUILD - Compilation timestamp: " << __DATE__ << " " << __TIME__ << "\n"; #endif @@ -344,6 +361,11 @@ namespace Bloom int Application::presentVersionMachineText() { Logger::silence(); + auto insightAvailable = true; +#ifdef EXCLUDE_INSIGHT + insightAvailable = false; +#endif + std::cout << QJsonDocument(QJsonObject({ {"version", QString::fromStdString(Application::VERSION.toString())}, {"components", QJsonObject({ @@ -351,6 +373,7 @@ namespace Bloom {"minor", Application::VERSION.minor}, {"patch", Application::VERSION.patch}, })}, + {"insightAvailable", insightAvailable}, })).toJson().toStdString(); return EXIT_SUCCESS; diff --git a/src/Application.hpp b/src/Application.hpp index 43c716fd..e3d87aea 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -12,7 +12,11 @@ #include "src/TargetController/TargetControllerComponent.hpp" #include "src/DebugServer/DebugServerComponent.hpp" + +#ifndef EXCLUDE_INSIGHT #include "src/Insight/Insight.hpp" +#endif + #include "src/SignalHandler/SignalHandler.hpp" #include "src/ProjectConfig.hpp" @@ -80,6 +84,7 @@ namespace Bloom std::unique_ptr debugServer = nullptr; std::thread debugServerThread; +#ifndef EXCLUDE_INSIGHT /** * Insight is, effectively, a small Qt application that serves a GUI to the user. It occupies the main thread, * as well as a single worker thread, and possibly other threads created by Qt. @@ -95,6 +100,7 @@ namespace Bloom * as we want to manage the lifetime of the object here. */ std::unique_ptr insight = nullptr; +#endif /** * Configuration extracted from the user's project configuration file. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a4221df..b07e14b8 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,4 +33,7 @@ add_subdirectory(DebugToolDrivers) add_subdirectory(Targets) add_subdirectory(TargetController) add_subdirectory(DebugServer) -add_subdirectory(Insight) + +if (NOT ${EXCLUDE_INSIGHT}) + add_subdirectory(Insight) +endif() diff --git a/src/ProjectSettings.cpp b/src/ProjectSettings.cpp index 3a2b260f..2db466d2 100644 --- a/src/ProjectSettings.cpp +++ b/src/ProjectSettings.cpp @@ -9,19 +9,24 @@ namespace Bloom { ProjectSettings::ProjectSettings(const QJsonObject& jsonObject) { +#ifndef EXCLUDE_INSIGHT if (jsonObject.contains("insight")) { this->insightSettings = InsightProjectSettings(jsonObject.find("insight")->toObject()); } +#endif } QJsonObject ProjectSettings::toJson() const { auto projectSettingsObj = QJsonObject(); +#ifndef EXCLUDE_INSIGHT projectSettingsObj.insert("insight", this->insightSettings.toJson()); +#endif return projectSettingsObj; } +#ifndef EXCLUDE_INSIGHT InsightProjectSettings::InsightProjectSettings(const QJsonObject& jsonObject) { if (jsonObject.contains("mainWindowSize")) { const auto mainWindowSizeObj = jsonObject.find("mainWindowSize")->toObject(); @@ -351,4 +356,5 @@ namespace Bloom return json; } +#endif } diff --git a/src/ProjectSettings.hpp b/src/ProjectSettings.hpp index 907c3939..8c1c1bab 100644 --- a/src/ProjectSettings.hpp +++ b/src/ProjectSettings.hpp @@ -8,14 +8,18 @@ #include #include "src/Targets/TargetMemory.hpp" + +#ifndef EXCLUDE_INSIGHT #include "src/Insight/UserInterfaces/InsightWindow/Widgets/PanelState.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/PaneState.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp" +#endif #include "src/Helpers/BiMap.hpp" namespace Bloom { +#ifndef EXCLUDE_INSIGHT struct InsightProjectSettings { public: @@ -65,10 +69,13 @@ namespace Bloom [[nodiscard]] QJsonObject paneStateToJson(const Widgets::PaneState& paneState) const; }; +#endif struct ProjectSettings { +#ifndef EXCLUDE_INSIGHT InsightProjectSettings insightSettings; +#endif ProjectSettings() = default; explicit ProjectSettings(const QJsonObject& jsonObject);