1
0
mirror of synced 2025-02-08 15:08:11 +01:00

build: Make ImHex fully compile with MSVC and Clang CL

This does NOT make ImHex work yet. However it can now be compiled
This commit is contained in:
WerWolv 2025-02-01 15:13:13 +01:00
parent 466b372d41
commit 8039ae1b90
18 changed files with 95 additions and 33 deletions

View File

@ -585,7 +585,7 @@ macro(setupCompilerFlags target)
# Disable some warnings
set(IMHEX_C_CXX_FLAGS "-Wno-array-bounds -Wno-deprecated-declarations -Wno-unknown-pragmas")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(IMHEX_CXX_FLAGS "/EHsc")
set(IMHEX_CXX_FLAGS "/DWIN32 /D_WINDOWS /GR /EHsc")
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")

@ -1 +1 @@
Subproject commit 9d38dd5b48e429d4f1d7c71dc2684a6ab42b6f92
Subproject commit ba8fb9c842b218fdf747df64940e4467421fcc17

@ -1 +1 @@
Subproject commit 82ce31275b124082fc2a32e83f7ac3e122ffadda
Subproject commit 506b867e512f1cbf5ab21f92a7250e2c20b52f94

View File

@ -138,6 +138,7 @@ if (NOT IMHEX_EXTERNAL_PLUGIN_BUILD)
target_link_options(libimhex PRIVATE -Wl,--export-all-symbols)
endif()
target_link_libraries(libimhex PRIVATE Netapi32.lib)
target_compile_definitions(libimhex PRIVATE EXPORT_SYMBOLS=1)
elseif (APPLE)
find_library(FOUNDATION NAMES Foundation)
target_link_libraries(libimhex PUBLIC ${FOUNDATION})

View File

@ -24,8 +24,8 @@ namespace hex {
static void removeWorkspace(const std::string &name);
static const auto& getWorkspaces() { return *s_workspaces; }
static const auto& getCurrentWorkspace() { return s_currentWorkspace; }
static const std::map<std::string, Workspace>& getWorkspaces();
static const std::map<std::string, Workspace>::iterator& getCurrentWorkspace();
static void reset();
static void reload();
@ -34,9 +34,6 @@ namespace hex {
private:
WorkspaceManager() = default;
static AutoReset<std::map<std::string, Workspace>> s_workspaces;
static decltype(s_workspaces)::Type::iterator s_currentWorkspace, s_previousWorkspace, s_workspaceToRemove;
};
}

View File

@ -14,10 +14,10 @@
namespace hex {
AutoReset<std::map<std::string, WorkspaceManager::Workspace>> WorkspaceManager::s_workspaces;
decltype(WorkspaceManager::s_workspaces)::Type::iterator WorkspaceManager::s_currentWorkspace = s_workspaces->end();
decltype(WorkspaceManager::s_workspaces)::Type::iterator WorkspaceManager::s_previousWorkspace = s_workspaces->end();
decltype(WorkspaceManager::s_workspaces)::Type::iterator WorkspaceManager::s_workspaceToRemove = s_workspaces->end();
AutoReset<std::map<std::string, WorkspaceManager::Workspace>> s_workspaces;
decltype(s_workspaces)::Type::iterator s_currentWorkspace = s_workspaces->end();
decltype(s_workspaces)::Type::iterator s_previousWorkspace = s_workspaces->end();
decltype(s_workspaces)::Type::iterator s_workspaceToRemove = s_workspaces->end();
void WorkspaceManager::createWorkspace(const std::string& name, const std::string &layout) {
s_currentWorkspace = s_workspaces->insert_or_assign(name, Workspace {
@ -174,7 +174,13 @@ namespace hex {
}
}
const std::map<std::string, WorkspaceManager::Workspace>& WorkspaceManager::getWorkspaces() {
return *s_workspaces;
}
const std::map<std::string, WorkspaceManager::Workspace>::iterator& WorkspaceManager::getCurrentWorkspace() {
return s_currentWorkspace;
}
}

View File

@ -13,4 +13,9 @@ add_subdirectory(imnodes)
add_subdirectory(backend)
add_subdirectory(ColorTextEditor)
set(IMGUI_LIBRARIES imgui_imgui imgui_cimgui imgui_implot imgui_implot3d imgui_imnodes imgui_backend imgui_color_text_editor PARENT_SCOPE)
set(IMGUI_LIBRARIES imgui_imgui imgui_cimgui imgui_implot imgui_implot3d imgui_imnodes imgui_backend imgui_color_text_editor)
set(IMGUI_LIBRARIES ${IMGUI_LIBRARIES} PARENT_SCOPE)
foreach (LIBRARY IN LISTS IMGUI_LIBRARIES)
target_compile_definitions(${LIBRARY} PRIVATE EXPORT_SYMBOLS=1)
endforeach ()

View File

@ -5011,8 +5011,16 @@ typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC) (GLenum target,
#endif
#ifndef GL3W_API
#ifdef _MSC_VER
#if EXPORT_SYMBOLS == 1
#define GL3W_API __declspec(dllexport)
#else
#define GL3W_API __declspec(dllimport)
#endif
#else
#define GL3W_API
#endif
#endif
#ifndef __gl_h_
#define __gl_h_

View File

@ -32,6 +32,22 @@ namespace hex::log::impl {
//#define IMGUI_API __declspec( dllexport )
//#define IMGUI_API __declspec( dllimport )
#if EXPORT_SYMBOLS == 1
#define IMGUI_API __declspec(dllexport)
#define IMGUI_IMPL_API __declspec(dllexport)
#define IMPLOT_API __declspec(dllexport)
#define IMPLOT_IMPL_API __declspec(dllexport)
#define IMPLOT3D_API __declspec(dllexport)
#define IMPLOT3D_IMPL_API __declspec(dllexport)
#else
#define IMGUI_API __declspec(dllimport)
#define IMGUI_IMPL_API __declspec(dllimport)
#define IMPLOT_API __declspec(dllimport)
#define IMPLOT_IMPL_API __declspec(dllimport)
#define IMPLOT3D_API __declspec(dllimport)
#define IMPLOT3D_IMPL_API __declspec(dllimport)
#endif
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.

View File

@ -17,7 +17,7 @@
struct ImNodesContext;
extern ImNodesContext* GImNodes;
IMGUI_API extern ImNodesContext* GImNodes;
// [SECTION] internal enums

View File

@ -31,7 +31,7 @@
#define sscanf sscanf_s
#endif
ImNodesContext* GImNodes = NULL;
IMGUI_API ImNodesContext* GImNodes = NULL;
namespace IMNODES_NAMESPACE
{

View File

@ -10,4 +10,10 @@ add_dependencies(imhex_all main-forwarder)
set_target_properties(main-forwarder PROPERTIES
OUTPUT_NAME "imhex"
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../..
)
)
if (WIN32)
if (MSVC)
target_link_options(main-forwarder PRIVATE /MANIFEST:NO)
endif()
endif()

View File

@ -61,6 +61,10 @@ target_compile_definitions(main PRIVATE IMHEX_PROJECT_NAME="${PROJECT_NAME}")
target_link_libraries(main PRIVATE libromfs-imhex libimhex libwolv ${LIBBACKTRACE_LIBRARIES} LLVMDemangle)
if (WIN32)
target_link_libraries(main PRIVATE usp10 wsock32 ws2_32 Dwmapi.lib Winmm.lib)
if (MSVC)
target_link_options(main PRIVATE /MANIFEST:NO /ENTRY:mainCRTStartup)
endif()
else ()
target_link_libraries(main PRIVATE pthread)

View File

@ -28,7 +28,7 @@ namespace hex::messaging {
});
EventNativeMessageReceived::subscribe([](const std::vector<u8> &rawData) {
ssize_t nullIndex = -1;
i64 nullIndex = -1;
auto messageData = reinterpret_cast<const char*>(rawData.data());
size_t messageSize = rawData.size();

View File

@ -47,12 +47,21 @@ namespace {
ZeroMemory(&stackFrame, sizeof(STACKFRAME64));
image = IMAGE_FILE_MACHINE_AMD64;
stackFrame.AddrPC.Offset = context.Rip;
stackFrame.AddrPC.Mode = AddrModeFlat;
stackFrame.AddrFrame.Offset = context.Rsp;
stackFrame.AddrFrame.Mode = AddrModeFlat;
stackFrame.AddrStack.Offset = context.Rsp;
stackFrame.AddrStack.Mode = AddrModeFlat;
#if defined(_X86_)
stackFrame.AddrPC.Offset = context.Eip;
stackFrame.AddrPC.Mode = AddrModeFlat;
stackFrame.AddrFrame.Offset = context.Esp;
stackFrame.AddrFrame.Mode = AddrModeFlat;
stackFrame.AddrStack.Offset = context.Esp;
stackFrame.AddrStack.Mode = AddrModeFlat;
#else
stackFrame.AddrPC.Offset = context.Rip;
stackFrame.AddrPC.Mode = AddrModeFlat;
stackFrame.AddrFrame.Offset = context.Rsp;
stackFrame.AddrFrame.Mode = AddrModeFlat;
stackFrame.AddrStack.Offset = context.Rsp;
stackFrame.AddrStack.Mode = AddrModeFlat;
#endif
while (true) {
if (StackWalk64(

View File

@ -32,12 +32,22 @@
#include <shellapi.h>
#include <timeapi.h>
#include <VersionHelpers.h>
#include <cstdio>
#if !defined(STDIN_FILENO)
#define STDIN_FILENO 0
#endif
#if !defined(STDOUT_FILENO)
#define STDOUT_FILENO 1
#endif
#if !defined(STDERR_FILENO)
#define STDERR_FILENO 2
#endif
namespace hex {
template<typename T>
using WinUniquePtr = std::unique_ptr<std::remove_pointer_t<T>, BOOL(*)(T)>;
static LONG_PTR s_oldWndProc;
static float s_titleBarHeight;
static Microsoft::WRL::ComPtr<ITaskbarList4> s_taskbarList;
@ -418,10 +428,10 @@ namespace hex {
DropManager() = default;
virtual ~DropManager() = default;
ULONG AddRef() override { return 1; }
ULONG Release() override { return 0; }
ULONG STDMETHODCALLTYPE AddRef() override { return 1; }
ULONG STDMETHODCALLTYPE Release() override { return 0; }
HRESULT QueryInterface(REFIID riid, void **ppvObject) override {
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override {
if (riid == IID_IDropTarget) {
*ppvObject = this;
@ -578,14 +588,14 @@ namespace hex {
EventThemeChanged::subscribe([this]{
auto hwnd = glfwGetWin32Window(m_window);
static auto user32Dll = WinUniquePtr<HMODULE>(LoadLibraryA("user32.dll"), FreeLibrary);
static auto user32Dll = LoadLibraryA("user32.dll");
if (user32Dll != nullptr) {
using SetWindowCompositionAttributeFunc = BOOL(WINAPI*)(HWND, WINCOMPATTRDATA*);
const auto setWindowCompositionAttribute =
reinterpret_cast<SetWindowCompositionAttributeFunc>(
reinterpret_cast<void*>(
GetProcAddress(user32Dll.get(), "SetWindowCompositionAttribute")
GetProcAddress(user32Dll, "SetWindowCompositionAttribute")
)
);

View File

@ -22,7 +22,7 @@ namespace hex::plugin::builtin {
ImNodesContext *ctx = ImNodes::CreateContext();
ctx->Style = ImNodes::GetStyle();
ctx->Io = ImNodes::GetIO();
ctx->AttributeFlagStack = GImNodes->AttributeFlagStack;
ctx->AttributeFlagStack = ImNodes::GetCurrentContext()->AttributeFlagStack;
return ctx;
}(), [](ImNodesContext *ptr) {

View File

@ -202,7 +202,7 @@ namespace hex::plugin::builtin {
AchievementManager::unlockAchievement("hex.builtin.achievement.hex_editor", "hex.builtin.achievement.hex_editor.modify_byte.name");
});
EventPatchCreated::subscribe([](const u8 *, u8, PatchKind) {
EventPatchCreated::subscribe([](const u8 *, u64, PatchKind) {
AchievementManager::unlockAchievement("hex.builtin.achievement.hex_editor", "hex.builtin.achievement.hex_editor.create_patch.name");
});