Skip to content

Commit

Permalink
Go back to static linking on WIndows
Browse files Browse the repository at this point in the history
Everything except python is once again statically linked
  • Loading branch information
WerWolv committed Jan 6, 2021
1 parent 2248cd9 commit b902cc6
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 21 deletions.
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion external/ImGui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 9 additions & 1 deletion external/glad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
if (WIN32)
target_link_libraries(glad PRIVATE libdl.a)
else()
target_link_libraries(glad PRIVATE dl)
endif()
17 changes: 17 additions & 0 deletions external/llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 0 additions & 13 deletions external/llvm/Demangle/CMakeLists.txt

This file was deleted.

4 changes: 3 additions & 1 deletion plugins/libimhex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b902cc6

Please sign in to comment.