1
0
mirror of synced 2024-11-30 18:34:29 +01:00

build: Fix various issues with linking, clang and unity builds

This commit is contained in:
WerWolv 2024-01-29 22:57:39 +01:00
parent 2e74a78f46
commit 76e304c34e
22 changed files with 18 additions and 41 deletions

View File

@ -299,6 +299,8 @@ macro(configureCMake)
# Enable C and C++ languages
enable_language(C CXX)
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "Enable position independent code for all targets" FORCE)
# Configure use of recommended build tools
if (IMHEX_USE_DEFAULT_BUILD_SETTINGS)
message(STATUS "Configuring CMake to use recommended build tools...")
@ -483,7 +485,6 @@ endfunction()
macro(setupCompilerFlags target)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Define strict compilation flags
if (IMHEX_STRICT_WARNINGS)
set(IMHEX_COMMON_FLAGS "${IMHEX_COMMON_FLAGS} -Wall -Wextra -Wpedantic -Werror")
@ -497,7 +498,9 @@ macro(setupCompilerFlags target)
# Disable some warnings
set(IMHEX_C_CXX_FLAGS "-Wno-unknown-warning-option -Wno-array-bounds -Wno-deprecated-declarations")
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (IMHEX_ENABLE_UNITY_BUILD AND WIN32)
set(IMHEX_COMMON_FLAGS "${IMHEX_COMMON_FLAGS} -Wa,-mbig-obj")
endif ()
@ -541,23 +544,14 @@ macro(addBundledLibraries)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/imgui)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/microtar EXCLUDE_FROM_ALL)
set_target_properties(microtar PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_subdirectory(${EXTERNAL_LIBS_FOLDER}/libwolv EXCLUDE_FROM_ALL)
set_property(TARGET libwolv-types PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET libwolv-utils PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET libwolv-io PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET libwolv-hash PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET libwolv-containers PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET libwolv-net PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET libwolv-math_eval PROPERTY POSITION_INDEPENDENT_CODE ON)
set(XDGPP_INCLUDE_DIRS "${THIRD_PARTY_LIBS_FOLDER}/xdgpp")
set(FPHSA_NAME_MISMATCHED ON CACHE BOOL "")
if(NOT USE_SYSTEM_FMT)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/fmt EXCLUDE_FROM_ALL)
set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(FMT_LIBRARIES fmt::fmt-header-only)
else()
find_package(fmt REQUIRED)
@ -577,7 +571,6 @@ macro(addBundledLibraries)
# nfd
if (NOT USE_SYSTEM_NFD)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/nativefiledialog EXCLUDE_FROM_ALL)
set_target_properties(nfd PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(NFD_LIBRARIES nfd)
else()
find_package(nfd)
@ -595,7 +588,6 @@ macro(addBundledLibraries)
if (NOT USE_SYSTEM_LLVM)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/llvm-demangle EXCLUDE_FROM_ALL)
set_target_properties(LLVMDemangle PROPERTIES POSITION_INDEPENDENT_CODE ON)
else()
find_package(LLVM REQUIRED Demangle)
endif()
@ -618,7 +610,6 @@ macro(addBundledLibraries)
set_target_properties(
libpl
PROPERTIES
POSITION_INDEPENDENT_CODE ON
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)

View File

@ -45,7 +45,6 @@ macro(add_imhex_plugin)
target_compile_definitions(${IMHEX_PLUGIN_NAME} PRIVATE IMHEX_PLUGIN_NAME=${IMHEX_PLUGIN_NAME})
# Enable required compiler flags
set_target_properties(${IMHEX_PLUGIN_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
enableUnityBuild(${IMHEX_PLUGIN_NAME})
setupCompilerFlags(${IMHEX_PLUGIN_NAME})
@ -67,7 +66,6 @@ macro(add_imhex_plugin)
list(APPEND LIBROMFS_RESOURCE_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/romfs)
set(LIBROMFS_PROJECT_NAME ${IMHEX_PLUGIN_NAME})
add_subdirectory(${IMHEX_BASE_FOLDER}/lib/external/libromfs ${CMAKE_CURRENT_BINARY_DIR}/libromfs)
set_target_properties(${LIBROMFS_LIBRARY} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE ${LIBROMFS_LIBRARY})
foreach(feature ${IMHEX_PLUGIN_FEATURES})

View File

@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.20)
project(ImHexSDK)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "" FORCE)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/build_helpers.cmake")
set(IMHEX_BASE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)

@ -1 +1 @@
Subproject commit 0a72f7bb33d87c4fb2709b6b94bf83518ab0022d
Subproject commit 61f7e412dd1ad304453a1384a1e42ed01139f729

@ -1 +1 @@
Subproject commit 1fa19577c90d0db47fbb5ad8207cdb7b346a3b69
Subproject commit 0c2918e13247f016bf3e43e678b36aa62be4f965

View File

@ -77,7 +77,6 @@ else()
target_compile_definitions(libimhex PRIVATE IMHEX_PROJECT_NAME="${PROJECT_NAME}")
endif()
set_target_properties(libimhex PROPERTIES POSITION_INDEPENDENT_CODE ON)
enableUnityBuild(libimhex)
setupCompilerFlags(libimhex)

View File

@ -15,4 +15,3 @@ target_include_directories(imgui_color_text_editor PUBLIC
target_include_directories(imgui_all_includes INTERFACE include)
target_link_libraries(imgui_color_text_editor PRIVATE imgui_includes)
set_property(TARGET imgui_color_text_editor PROPERTY POSITION_INDEPENDENT_CODE ON)

View File

@ -14,7 +14,6 @@ target_include_directories(imgui_custom PUBLIC
)
target_link_libraries(imgui_custom PRIVATE imgui_includes)
set_property(TARGET imgui_custom PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(imgui_all_includes INTERFACE include)
find_package(OpenGL REQUIRED)

View File

@ -24,7 +24,6 @@ target_include_directories(imgui_includes INTERFACE include)
target_include_directories(imgui_all_includes INTERFACE include include/misc/freetype)
target_compile_options(imgui_imgui PRIVATE -Wno-unknown-warning-option)
set_property(TARGET imgui_imgui PROPERTY POSITION_INDEPENDENT_CODE ON)
find_package(Freetype REQUIRED)

View File

@ -14,4 +14,3 @@ target_include_directories(imgui_imnodes PUBLIC
target_link_libraries(imgui_imnodes PRIVATE imgui_includes)
target_include_directories(imgui_all_includes INTERFACE include)
set_property(TARGET imgui_imnodes PROPERTY POSITION_INDEPENDENT_CODE ON)

View File

@ -16,5 +16,3 @@ target_include_directories(imgui_implot PUBLIC
target_link_libraries(imgui_implot PRIVATE imgui_includes)
target_include_directories(imgui_all_includes INTERFACE include)
set_property(TARGET imgui_implot PROPERTY POSITION_INDEPENDENT_CODE ON)

View File

@ -107,7 +107,6 @@ set(LIBYARA_MODULES
find_package(mbedTLS 2.26.0 REQUIRED)
add_library(libyara STATIC ${LIBYARA_SOURCE} ${LIBYARA_INCLUDES} ${LIBYARA_MODULES})
set_property(TARGET libyara PROPERTY POSITION_INDEPENDENT_CODE ON)
# Add mbedtls crypto wrappers
target_compile_definitions(libyara PRIVATE

View File

@ -10,5 +10,4 @@ add_dependencies(imhex_all main-forwarder)
set_target_properties(main-forwarder PROPERTIES
OUTPUT_NAME "imhex"
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../..
POSITION_INDEPENDENT_CODE ON
)

View File

@ -30,7 +30,6 @@ setupCompilerFlags(main)
set(LIBROMFS_RESOURCE_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/romfs)
set(LIBROMFS_PROJECT_NAME imhex)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../lib/external/libromfs ${CMAKE_CURRENT_BINARY_DIR}/main/gui/libromfs EXCLUDE_FROM_ALL)
set_target_properties(${LIBROMFS_LIBRARY} PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_dependencies(imhex_all main)
if (EMSCRIPTEN)
@ -49,8 +48,7 @@ endif ()
set_target_properties(main PROPERTIES
OUTPUT_NAME ${IMHEX_APPLICATION_NAME}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../..
POSITION_INDEPENDENT_CODE ON)
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../..)
target_compile_definitions(main PRIVATE IMHEX_PROJECT_NAME="${PROJECT_NAME}")

View File

@ -17,5 +17,4 @@ endif()
set_target_properties(updater PROPERTIES
OUTPUT_NAME "imhex-updater"
RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY}
POSITION_INDEPENDENT_CODE ON
)

View File

@ -5,7 +5,6 @@ include(ImHexPlugin)
macro(addOptionalLibrary package library)
find_package(${package})
if (${package}_FOUND)
set_property(TARGET ${package}::${library} PROPERTY POSITION_INDEPENDENT_CODE ON)
string(TOUPPER ${package} PACKAGE)
set(LIBRARIES ${LIBRARIES} ${package}::${library})
message(STATUS "Enabling decompression support using ${package} (${${package}_VERSION})")

View File

@ -8,9 +8,6 @@ else()
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/edlib ${CMAKE_CURRENT_BINARY_DIR}/edlib EXCLUDE_FROM_ALL)
enableUnityBuild(edlib)
set_target_properties(edlib
PROPERTIES POSITION_INDEPENDENT_CODE ON
)
endif()
add_imhex_plugin(

View File

@ -7,9 +7,7 @@ if (NOT USE_SYSTEM_CAPSTONE)
set(CAPSTONE_BUILD_SHARED OFF CACHE BOOL "Disable shared library building")
set(CAPSTONE_BUILD_TESTS OFF CACHE BOOL "Disable tests")
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/capstone ${CMAKE_CURRENT_BINARY_DIR}/capstone EXCLUDE_FROM_ALL)
set_target_properties(capstone PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_options(capstone PRIVATE -Wno-unused-function)
enableUnityBuild(capstone)
set(CAPSTONE_LIBRARY "capstone")
set(CAPSTONE_INCLUDE_DIR ${THIRD_PARTY_LIBS_FOLDER}/capstone/include)
else()

View File

@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.16)
include(ImHexPlugin)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/HashLibPlus ${CMAKE_CURRENT_BINARY_DIR}/HashLibPlus)
set_target_properties(hashplus PROPERTIES POSITION_INDEPENDENT_CODE ON)
enableUnityBuild(hashplus)
add_imhex_plugin(

View File

@ -74,8 +74,7 @@ namespace hex::ui {
/* Hex Editor */
HexEditor::HexEditor(prv::Provider *provider) : m_provider(provider) {
m_currDataVisualizer = ContentRegistry::HexEditor::getVisualizerByName("hex.builtin.visualizer.hexadecimal.8bit");
m_miniMapVisualizer = ContentRegistry::HexEditor::impl::getMiniMapVisualizers().front();
}
HexEditor::~HexEditor() {
@ -194,6 +193,10 @@ namespace hex::ui {
}
void HexEditor::drawMinimap(ImVec2 characterSize) {
if (const auto &visualizers = ContentRegistry::HexEditor::impl::getMiniMapVisualizers(); m_miniMapVisualizer == nullptr && !visualizers.empty())
m_miniMapVisualizer = visualizers.front();
ImS64 numRows = m_provider == nullptr ? 0 : (m_provider->getSize() / m_bytesPerRow) + ((m_provider->getSize() % m_bytesPerRow) == 0 ? 0 : 1);
auto window = ImGui::GetCurrentWindowRead();
@ -400,6 +403,11 @@ namespace hex::ui {
const float SeparatorColumWidth = 6_scaled;
const auto CharacterSize = ImGui::CalcTextSize("0");
if (const auto &visualizer = ContentRegistry::HexEditor::getVisualizerByName("hex.builtin.visualizer.hexadecimal.8bit"); m_currDataVisualizer == nullptr && visualizer != nullptr) {
m_currDataVisualizer = visualizer;
return;
}
const auto bytesPerCell = m_currDataVisualizer->getBytesPerCell();
const u16 columnCount = m_bytesPerRow / bytesPerCell;
auto byteColumnCount = 2 + columnCount + getByteColumnSeparatorCount(columnCount) + 2 + 2;

View File

@ -4,7 +4,6 @@ include(ImHexPlugin)
if (NOT USE_SYSTEM_MINIAUDIO)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/miniaudio ${CMAKE_CURRENT_BINARY_DIR}/miniaudio EXCLUDE_FROM_ALL)
set_target_properties(miniaudio PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(MINIAUDIO_LIBRARIES miniaudio)
else()
find_package(miniaudio REQUIRED)

View File

@ -4,7 +4,6 @@ include(ImHexPlugin)
if (NOT USE_SYSTEM_YARA)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/yara ${CMAKE_CURRENT_BINARY_DIR}/yara EXCLUDE_FROM_ALL)
set_target_properties(libyara PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(YARA_LIBRARIES libyara)
else()
find_package(Yara REQUIRED)