From b902cc653106fec9e2099dcc2830c80ef7116622 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 6 Jan 2021 19:19:01 +0100 Subject: [PATCH] Go back to static linking on WIndows Everything except python is once again statically linked --- CMakeLists.txt | 14 +++++++++----- external/ImGui/CMakeLists.txt | 6 +++++- external/glad/CMakeLists.txt | 10 +++++++++- external/llvm/CMakeLists.txt | 17 +++++++++++++++++ external/llvm/Demangle/CMakeLists.txt | 13 ------------- plugins/libimhex/CMakeLists.txt | 4 +++- 6 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 external/llvm/CMakeLists.txt delete mode 100644 external/llvm/Demangle/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f52eae6a..08c82dfcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,13 +19,13 @@ set(Python_FIND_FRAMEWORK NEVER) # Find packages find_package(PkgConfig REQUIRED) -pkg_search_module(CRYPTO REQUIRED crypto) +pkg_search_module(CRYPTO REQUIRED libcrypto) pkg_search_module(CAPSTONE REQUIRED capstone) find_package(OpenGL REQUIRED) find_package(nlohmann_json REQUIRED) find_package(Python COMPONENTS Development) -add_subdirectory(external/llvm/Demangle) +add_subdirectory(external/llvm) add_subdirectory(plugins/libimhex) @@ -50,8 +50,8 @@ list(JOIN PYTHON_VERSION_MAJOR_MINOR "." PYTHON_VERSION_MAJOR_MINOR) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -DPYTHON_VERSION_MAJOR_MINOR=\"\\\"${PYTHON_VERSION_MAJOR_MINOR}\"\\\"") # Detect current OS / System -if (MSYS OR MINGW) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOS_WINDOWS") +if (WIN32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOS_WINDOWS -static-libstdc++ -static-libgcc -Wl,--allow-multiple-definition -static") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wl,-subsystem,windows") elseif(APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOS_MACOS") @@ -155,7 +155,11 @@ set_target_properties(imhex PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_directories(imhex PRIVATE ${CRYPTO_LIBRARY_DIRS} ${CAPSTONE_LIBRARY_DIRS} ${MAGIC_LIBRARY_DIRS}) -target_link_libraries(imhex magic crypto ${CMAKE_DL_LIBS} capstone LLVMDemangle imgui libimhex ${Python_LIBRARIES} nlohmann_json::nlohmann_json dl) +if (WIN32) + target_link_libraries(imhex libdl.a libmagic.a libgnurx.a libtre.a libintl.a libiconv.a libshlwapi.a libcrypto.a libwinpthread.a libcapstone.a LLVMDemangle imgui libimhex ${Python_LIBRARIES} nlohmann_json::nlohmann_json) +elseif (UNIX) + target_link_libraries(imhex magic crypto ${CMAKE_DL_LIBS} capstone LLVMDemangle imgui libimhex ${Python_LIBRARIES} nlohmann_json::nlohmann_json dl) +endif() if (CREATE_BUNDLE) include(PostprocessBundle) diff --git a/external/ImGui/CMakeLists.txt b/external/ImGui/CMakeLists.txt index 4fac8ec57..63e71c8cb 100644 --- a/external/ImGui/CMakeLists.txt +++ b/external/ImGui/CMakeLists.txt @@ -28,4 +28,8 @@ target_include_directories(imgui PUBLIC include ${FREETYPE_INCLUDE_DIRS} ${GLFW_ target_link_directories(imgui PUBLIC ${GLM_INCLUDE_DIRS} ${GLFW_LIBRARY_DIRS}) -target_link_libraries(imgui Freetype::Freetype glad glfw3) +if (WIN32) + target_link_libraries(imgui libstdc++.a libgcc.a libharfbuzz.a libfreetype.a libharfbuzz.a libgraphite2.a libpng.a libbrotlidec-static.a libbrotlicommon-static.a libz.a libbz2.a librpcrt4.a glad libglfw3.a) +elseif (UNIX) + target_link_libraries(imgui Freetype::Freetype glad glfw) +endif() diff --git a/external/glad/CMakeLists.txt b/external/glad/CMakeLists.txt index 154a0fc47..49c58033e 100644 --- a/external/glad/CMakeLists.txt +++ b/external/glad/CMakeLists.txt @@ -3,10 +3,18 @@ project(glad) set(CMAKE_CXX_STANDARD 17) +if (WIN32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc -static") +endif() + add_library(glad source/glad.c ) target_include_directories(glad PUBLIC include) -target_link_libraries(glad PRIVATE dl) \ No newline at end of file +if (WIN32) + target_link_libraries(glad PRIVATE libdl.a) +else() + target_link_libraries(glad PRIVATE dl) +endif() \ No newline at end of file diff --git a/external/llvm/CMakeLists.txt b/external/llvm/CMakeLists.txt new file mode 100644 index 000000000..c536d79d0 --- /dev/null +++ b/external/llvm/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.16) +project(LLVMDemangle) + +set(CMAKE_CXX_STANDARD 17) + +if (WIN32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc -static") +endif() + +add_library(LLVMDemangle + Demangle/Demangle.cpp + Demangle/ItaniumDemangle.cpp + Demangle/MicrosoftDemangle.cpp + Demangle/MicrosoftDemangleNodes.cpp +) + +target_include_directories(LLVMDemangle PUBLIC include) diff --git a/external/llvm/Demangle/CMakeLists.txt b/external/llvm/Demangle/CMakeLists.txt deleted file mode 100644 index 6efa4f3d0..000000000 --- a/external/llvm/Demangle/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.16) -project(LLVMDemangle) - -set(CMAKE_CXX_STANDARD 17) - -add_library(LLVMDemangle - Demangle.cpp - ItaniumDemangle.cpp - MicrosoftDemangle.cpp - MicrosoftDemangleNodes.cpp -) - -target_include_directories(LLVMDemangle PUBLIC ../include) diff --git a/plugins/libimhex/CMakeLists.txt b/plugins/libimhex/CMakeLists.txt index 11cfab1d6..ed39d5c54 100644 --- a/plugins/libimhex/CMakeLists.txt +++ b/plugins/libimhex/CMakeLists.txt @@ -5,7 +5,9 @@ set(CMAKE_CXX_STANDARD 20) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/ImGui ${CMAKE_CURRENT_BINARY_DIR}/external/ImGui) -set(CMAKE_STATIC_LIBRARY_PREFIX "") +if (WIN32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc -static") +endif() add_library(libimhex STATIC source/helpers/event.cpp