From 407ec1ceb684e8b7a7fad507fb3a2da3e46c6524 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 2 Nov 2023 20:21:38 +0100 Subject: [PATCH] build: Use custom jthread implementation if standard one is not available --- .gitmodules | 9 +++++++-- cmake/build_helpers.cmake | 14 +++++++++++++- dist/web/Dockerfile | 1 - lib/external/jthread/CMakeLists.txt | 6 ++++++ lib/external/jthread/includes/jthread.hpp | 7 +++++++ lib/external/jthread/jthread | 1 + lib/libimhex/CMakeLists.txt | 2 +- lib/libimhex/include/hex/api/content_registry.hpp | 2 -- lib/libimhex/include/hex/api/task.hpp | 2 -- lib/libimhex/source/api/content_registry.cpp | 2 +- plugins/windows/include/views/view_tty_console.hpp | 1 + 11 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 lib/external/jthread/CMakeLists.txt create mode 100644 lib/external/jthread/includes/jthread.hpp create mode 160000 lib/external/jthread/jthread diff --git a/.gitmodules b/.gitmodules index 18e1ad1dc..e63263f4f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -18,13 +18,18 @@ path = lib/external/capstone url = https://github.com/capstone-engine/capstone ignore = dirty +[submodule "lib/external/jthread/jthread"] + path = lib/external/jthread/jthread + url = https://github.com/josuttis/jthread + ignore = dirty + [submodule "lib/external/libromfs"] path = lib/external/libromfs url = https://github.com/WerWolv/libromfs - ignore = dirty [submodule "lib/external/pattern_language"] path = lib/external/pattern_language url = https://github.com/WerWolv/PatternLanguage [submodule "lib/external/libwolv"] path = lib/external/libwolv - url = https://github.com/WerWolv/libwolv \ No newline at end of file + url = https://github.com/WerWolv/libwolv + diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index 84667a4a5..0b6e298ad 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -382,7 +382,7 @@ function(detectBadClone) file (GLOB EXTERNAL_DIRS "lib/external/*") foreach (EXTERNAL_DIR ${EXTERNAL_DIRS}) - file(GLOB RESULT "${EXTERNAL_DIR}/*") + file(GLOB_RECURSE RESULT "${EXTERNAL_DIR}/*") list(LENGTH RESULT ENTRY_COUNT) if(ENTRY_COUNT LESS_EQUAL 1) message(FATAL_ERROR "External dependency ${EXTERNAL_DIR} is empty!\nMake sure to correctly clone ImHex using the --recurse-submodules git option or initialize the submodules manually.") @@ -570,6 +570,18 @@ macro(addBundledLibraries) pkg_check_modules(miniaudio REQUIRED IMPORTED_TARGET miniaudio) endif() + if (NOT USE_SYSTEM_JTHREAD) + add_subdirectory(${EXTERN_LIBS_FOLDER}/jthread EXCLUDE_FROM_ALL) + set(JTHREAD_LIBRARIES jthread) + else() + find_path(JOSUTTIS_JTHREAD_INCLUDE_DIRS "condition_variable_any2.hpp") + include_directories(${JOSUTTIS_JTHREAD_INCLUDE_DIRS}) + + add_library(jthread INTERFACE) + target_include_directories(jthread INTERFACE ${JOSUTTIS_JTHREAD_INCLUDE_DIRS}) + set(JTHREAD_LIBRARIES jthread) + endif() + if (NOT USE_SYSTEM_CAPSTONE) set(CAPSTONE_BUILD_STATIC_RUNTIME OFF CACHE BOOL "Disable shared library building") set(CAPSTONE_BUILD_SHARED OFF CACHE BOOL "Disable shared library building") diff --git a/dist/web/Dockerfile b/dist/web/Dockerfile index 1ee944edb..09ea86929 100644 --- a/dist/web/Dockerfile +++ b/dist/web/Dockerfile @@ -36,7 +36,6 @@ mkdir -p $VCPKG_DEFAULT_BINARY_CACHE /vcpkg/vcpkg install --triplet=wasm32-emscripten libmagic /vcpkg/vcpkg install --triplet=wasm32-emscripten freetype -/vcpkg/vcpkg install --triplet=wasm32-emscripten josuttis-jthread /vcpkg/vcpkg install --triplet=wasm32-emscripten mbedtls EOF diff --git a/lib/external/jthread/CMakeLists.txt b/lib/external/jthread/CMakeLists.txt new file mode 100644 index 000000000..c4e9082d5 --- /dev/null +++ b/lib/external/jthread/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.16) + +project(jthread) + +add_library(jthread INTERFACE) +target_include_directories(jthread INTERFACE includes) \ No newline at end of file diff --git a/lib/external/jthread/includes/jthread.hpp b/lib/external/jthread/includes/jthread.hpp new file mode 100644 index 000000000..12c19d5ed --- /dev/null +++ b/lib/external/jthread/includes/jthread.hpp @@ -0,0 +1,7 @@ +#pragma once + +#if __has_include() + #include +#else + #include "../jthread/source/jthread.hpp" +#endif \ No newline at end of file diff --git a/lib/external/jthread/jthread b/lib/external/jthread/jthread new file mode 160000 index 000000000..0fa8d3942 --- /dev/null +++ b/lib/external/jthread/jthread @@ -0,0 +1 @@ +Subproject commit 0fa8d394254886c555d6faccd0a3de819b7d47f8 diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index 53daf137b..1a4b24793 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -95,7 +95,7 @@ elseif (APPLE) endif () target_link_libraries(libimhex PRIVATE ${FMT_LIBRARIES}) -target_link_libraries(libimhex PUBLIC dl imgui ${NFD_LIBRARIES} magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${MBEDTLS_LIBRARIES} ${LIBBACKTRACE_LIBRARIES} plcli libpl libpl-gen ${MINIAUDIO_LIBRARIES} libwolv-utils libwolv-io libwolv-hash libwolv-net libwolv-containers) +target_link_libraries(libimhex PUBLIC dl imgui ${NFD_LIBRARIES} magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${MBEDTLS_LIBRARIES} ${LIBBACKTRACE_LIBRARIES} plcli libpl libpl-gen ${MINIAUDIO_LIBRARIES} ${JTHREAD_LIBRARIES} libwolv-utils libwolv-io libwolv-hash libwolv-net libwolv-containers) set_property(TARGET libimhex PROPERTY INTERPROCEDURAL_OPTIMIZATION FALSE) diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index b8c811512..084233480 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -17,9 +17,7 @@ #include #include -#if defined(OS_WEB) #include -#endif #include diff --git a/lib/libimhex/include/hex/api/task.hpp b/lib/libimhex/include/hex/api/task.hpp index c3ecd9973..e01b4dccb 100644 --- a/lib/libimhex/include/hex/api/task.hpp +++ b/lib/libimhex/include/hex/api/task.hpp @@ -12,9 +12,7 @@ #include #include -#if defined(OS_WEB) #include -#endif namespace hex { diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 4190016f5..0658c7d0a 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -8,9 +8,9 @@ #include #include +#include #if defined(OS_WEB) -#include #include #endif diff --git a/plugins/windows/include/views/view_tty_console.hpp b/plugins/windows/include/views/view_tty_console.hpp index 5305660d9..bcf83c5a7 100644 --- a/plugins/windows/include/views/view_tty_console.hpp +++ b/plugins/windows/include/views/view_tty_console.hpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace hex::plugin::windows {