1
0
mirror of synced 2025-01-29 19:17:28 +01:00

build: Add support for unity builds

This commit is contained in:
WerWolv 2023-11-30 10:22:15 +01:00
parent 09904b77eb
commit e370fdb0fc
25 changed files with 77 additions and 79 deletions

View File

@ -15,6 +15,7 @@ option(IMHEX_USE_DEFAULT_BUILD_SETTINGS "Use default build settings" OFF)
option(IMHEX_STRICT_WARNINGS "Enable most available warnings and treat them as errors" ON)
option(IMHEX_STATIC_LINK_PLUGINS "Statically link all plugins into the main executable" OFF)
option(IMHEX_GENERATE_PACKAGE "Specify if a native package should be built. Only usable on Windows and MacOS" OFF)
option(IMHEX_ENABLE_UNITY_BUILD "Enables building ImHex as a unity build." OFF)
# Basic compiler and cmake configurations
set(CMAKE_CXX_STANDARD 23)

View File

@ -450,6 +450,9 @@ macro(setupCompilerFlags target)
# Disable some warnings
set(IMHEX_C_CXX_FLAGS "-Wno-array-bounds -Wno-deprecated-declarations")
if (IMHEX_ENABLE_UNITY_BUILD AND WIN32)
set(IMHEX_COMMON_FLAGS "${IMHEX_COMMON_FLAGS} -Wa,-mbig-obj")
endif ()
endif()
# Disable some warnings for gcc
@ -634,6 +637,12 @@ macro(addBundledLibraries)
endif ()
endmacro()
function(enableUnityBuild TARGET)
if (IMHEX_ENABLE_UNITY_BUILD)
set_target_properties(${TARGET} PROPERTIES UNITY_BUILD ON UNITY_BUILD_MODE BATCH)
endif ()
endfunction()
function(generatePDBs)
if (NOT WIN32 OR CMAKE_BUILD_TYPE STREQUAL "Debug")
return()

View File

@ -33,6 +33,7 @@ macro(add_imhex_plugin)
# Enable required compiler flags
set_target_properties(${IMHEX_PLUGIN_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
enableUnityBuild(${IMHEX_PLUGIN_NAME})
setupCompilerFlags(${IMHEX_PLUGIN_NAME})
# Configure build properties

@ -1 +1 @@
Subproject commit 86faee9f3e0ebdf7542c51fb5233134c376e4d3d
Subproject commit 43ea92a66ccad58fa12b717113ded20dfa5c018f

View File

@ -69,6 +69,7 @@ else()
endif()
set_target_properties(libimhex PROPERTIES POSITION_INDEPENDENT_CODE ON)
enableUnityBuild(libimhex)
setupCompilerFlags(libimhex)
include(GenerateExportHeader)

View File

@ -1,15 +1,10 @@
#pragma once
#include <hex/helpers/fs.hpp>
#include <functional>
#include <span>
#include <string>
#if defined(OS_WINDOWS)
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#include <wolv/io/fs.hpp>
struct ImGuiContext;
@ -65,11 +60,7 @@ namespace hex {
[[nodiscard]] std::span<SubCommand> getSubCommands() const;
private:
#if defined(OS_WINDOWS)
HMODULE m_handle = nullptr;
#else
void *m_handle = nullptr;
#endif
uintptr_t m_handle = 0;
std::fs::path m_path;
mutable bool m_initialized = false;

View File

@ -65,6 +65,8 @@ namespace hex::dp {
friend class Node;
void setParentNode(Node *node) { this->m_parentNode = node; }
static int s_idCounter;
};
}

View File

@ -17,6 +17,8 @@ namespace hex::dp {
private:
int m_id;
int m_from, m_to;
static int s_idCounter;
};
}

View File

@ -87,6 +87,8 @@ namespace hex::dp {
prv::Overlay *m_overlay = nullptr;
ImVec2 m_position;
static int s_idCounter;
Attribute& getAttribute(u32 index) {
if (index >= this->getAttributes().size())
throw std::runtime_error("Attribute index out of bounds!");

View File

@ -10,14 +10,14 @@
#include <wolv/io/file.hpp>
#include <wolv/utils/guards.hpp>
using curl_off_t = long long;
#if defined(OS_WEB)
#include <emscripten/fetch.h>
using curl_off_t = long;
#else
#include <curl/curl.h>
#endif
typedef void CURL;
namespace hex {
class HttpRequest {

View File

@ -2,29 +2,33 @@
#include <hex/api/imhex_api.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/fmt.hpp>
#include <wolv/utils/string.hpp>
#include <filesystem>
#include <system_error>
#if defined(OS_WINDOWS)
#include <windows.h>
#else
#include <dlfcn.h>
#endif
namespace hex {
Plugin::Plugin(const std::fs::path &path) : m_path(path) {
#if defined(OS_WINDOWS)
this->m_handle = LoadLibraryW(path.c_str());
this->m_handle = uintptr_t(LoadLibraryW(path.c_str()));
if (this->m_handle == INVALID_HANDLE_VALUE || this->m_handle == nullptr) {
if (this->m_handle == uintptr_t(INVALID_HANDLE_VALUE) || this->m_handle == 0) {
log::error("LoadLibraryW failed: {}!", std::system_category().message(::GetLastError()));
return;
}
#else
this->m_handle = dlopen(wolv::util::toUTF8String(path).c_str(), RTLD_LAZY);
this->m_handle = uintptr_t(dlopen(wolv::util::toUTF8String(path).c_str(), RTLD_LAZY));
if (this->m_handle == nullptr) {
if (this->m_handle == 0) {
log::error("dlopen failed: {}!", dlerror());
return;
}
@ -41,14 +45,14 @@ namespace hex {
}
Plugin::Plugin(hex::PluginFunctions functions) {
this->m_handle = nullptr;
this->m_handle = 0;
this->m_functions = std::move(functions);
}
Plugin::Plugin(Plugin &&other) noexcept {
this->m_handle = other.m_handle;
other.m_handle = nullptr;
other.m_handle = 0;
this->m_path = std::move(other.m_path);
@ -58,9 +62,10 @@ namespace hex {
Plugin::~Plugin() {
#if defined(OS_WINDOWS)
if (this->m_handle != nullptr)
FreeLibrary(this->m_handle);
if (this->m_handle != 0)
FreeLibrary(HMODULE(this->m_handle));
#else
dlclose(reinterpret_cast<void*>(this->m_handle));
#endif
}
@ -100,7 +105,7 @@ namespace hex {
if (this->m_functions.getPluginNameFunction != nullptr)
return this->m_functions.getPluginNameFunction();
else
return hex::format("Unknown Plugin @ 0x{0:016X}", reinterpret_cast<intptr_t>(this->m_handle));
return hex::format("Unknown Plugin @ 0x{0:016X}", this->m_handle);
}
std::string Plugin::getPluginAuthor() const {
@ -155,9 +160,9 @@ namespace hex {
void *Plugin::getPluginFunction(const std::string &symbol) const {
#if defined(OS_WINDOWS)
return reinterpret_cast<void *>(GetProcAddress(this->m_handle, symbol.c_str()));
return reinterpret_cast<void *>(GetProcAddress(HMODULE(this->m_handle), symbol.c_str()));
#else
return dlsym(this->m_handle, symbol.c_str());
return dlsym(reinterpret_cast<void*>(this->m_handle), symbol.c_str());
#endif
}

View File

@ -3,11 +3,7 @@
namespace hex::dp {
namespace {
int s_idCounter = 1;
}
int Attribute::s_idCounter = 1;
Attribute::Attribute(IOType ioType, Type type, std::string unlocalizedName) : m_id(s_idCounter++), m_ioType(ioType), m_type(type), m_unlocalizedName(std::move(unlocalizedName)) {

View File

@ -3,11 +3,7 @@
namespace hex::dp {
namespace {
int s_idCounter = 1;
}
int Link::s_idCounter = 1;
Link::Link(int from, int to) : m_id(s_idCounter++), m_from(from), m_to(to) { }

View File

@ -7,11 +7,7 @@
namespace hex::dp {
namespace {
int s_idCounter = 1;
}
int Node::s_idCounter = 1;
Node::Node(std::string unlocalizedTitle, std::vector<Attribute> attributes) : m_id(s_idCounter++), m_unlocalizedTitle(std::move(unlocalizedTitle)), m_attributes(std::move(attributes)) {
for (auto &attr : this->m_attributes)

View File

@ -10,7 +10,6 @@
#include "init/tasks.hpp"
#include <hex/api/task_manager.hpp>
#include <hex/api/project_file_manager.hpp>
#include <hex/api/plugin_manager.hpp>
#include <hex/helpers/fs.hpp>
@ -20,7 +19,9 @@
#include <wolv/utils/guards.hpp>
#include <fcntl.h>
#if defined(OS_WEB)
#if defined(OS_WINDOWS)
#include <windows.h>
#elif defined(OS_WEB)
#include <emscripten.h>
#include <emscripten/html5.h>
#endif

View File

@ -94,7 +94,6 @@ add_imhex_plugin(
source/content/views/view_command_palette.cpp
source/content/views/view_settings.cpp
source/content/views/view_data_processor.cpp
source/content/views/view_yara.cpp
source/content/views/view_constants.cpp
source/content/views/view_store.cpp
source/content/views/view_diff.cpp
@ -103,6 +102,7 @@ add_imhex_plugin(
source/content/views/view_theme_manager.cpp
source/content/views/view_logs.cpp
source/content/views/view_achievements.cpp
source/content/views/view_yara.cpp
source/content/helpers/math_evaluator.cpp
source/content/helpers/notification.cpp

View File

@ -7,11 +7,6 @@
#include <string>
#include <vector>
#if defined(OS_WINDOWS)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
namespace hex::plugin::builtin {
class DiskProvider : public hex::prv::Provider {
@ -67,7 +62,7 @@ namespace hex::plugin::builtin {
std::string m_friendlyName;
#if defined(OS_WINDOWS)
HANDLE m_diskHandle = INVALID_HANDLE_VALUE;
void *m_diskHandle = reinterpret_cast<void*>(-1);
#else
std::string m_pathBuffer;
int m_diskHandle = -1;

View File

@ -3,9 +3,10 @@
#include <hex.hpp>
#include <hex/ui/view.hpp>
#include <hex/api/task_manager.hpp>
#include <hex/helpers/http_requests.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/api/task_manager.hpp>
#include <future>
#include <string>

View File

@ -2,6 +2,7 @@
#include <hex/api/localization_manager.hpp>
#include <hex/api/event_manager.hpp>
#include <wolv/utils/guards.hpp>
#include <wolv/net/socket_server.hpp>
#include <hex/helpers/logger.hpp>

View File

@ -17,24 +17,24 @@
#include <imgui.h>
#if defined(OS_WINDOWS)
#include <winioctl.h>
#include <setupapi.h>
#include <cfgmgr32.h>
#include <windows.h>
#include <winioctl.h>
#include <setupapi.h>
#include <cfgmgr32.h>
#elif defined(OS_LINUX)
#include <fcntl.h>
#include <unistd.h>
#include <linux/fs.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/fs.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#elif defined(OS_MACOS)
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/disk.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/disk.h>
#endif
#if defined(OS_LINUX)

View File

@ -3,13 +3,10 @@
#include <hex/providers/provider.hpp>
#include <hex/api/localization_manager.hpp>
#include <windows.h>
#include <hex/ui/imgui_imhex_extensions.h>
#include <hex/ui/widgets.hpp>
#include <hex/helpers/utils.hpp>
#include <string_view>
#include <set>
namespace hex::plugin::windows {
@ -94,7 +91,7 @@ namespace hex::plugin::windows {
return hex::containsIgnoreCase(memoryRegion.name, search);
});
HANDLE m_processHandle = nullptr;
void* m_processHandle = reinterpret_cast<void*>(-1);
bool m_enumerationFailed = false;
};

View File

@ -2,8 +2,6 @@
#include <hex/ui/view.hpp>
#include <windows.h>
#include <mutex>
#include <thread>
#include <jthread.hpp>
@ -27,7 +25,7 @@ namespace hex::plugin::windows {
void transmitData(std::vector<char> &data);
HANDLE m_portHandle = INVALID_HANDLE_VALUE;
void* m_portHandle = reinterpret_cast<void*>(-1);
std::jthread m_receiveThread;
int m_selectedPort = 0;

View File

@ -10,7 +10,6 @@
#include <hex/helpers/fmt.hpp>
#include <hex/ui/view.hpp>
#include <wolv/io/file.hpp>
#include <wolv/utils/guards.hpp>
namespace hex::plugin::windows {

View File

@ -9,6 +9,8 @@
#include "views/view_tty_console.hpp"
#include <windows.h>
using namespace hex;
namespace hex::plugin::windows {

View File

@ -7,6 +7,8 @@
#include <wolv/utils/guards.hpp>
#include <windows.h>
namespace hex::plugin::windows {
ViewTTYConsole::ViewTTYConsole() : View::Window("hex.windows.view.tty_console.name") {