From dd62bee264e1cd4f225a6e65e98ca188a0ff4cbc Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 29 Feb 2024 18:48:16 +0000 Subject: [PATCH] build: Added precompiled headers --- cmake/build_helpers.cmake | 11 ++ cmake/modules/ImHexPlugin.cmake | 6 +- lib/external/libwolv | 2 +- lib/libimhex/CMakeLists.txt | 2 + .../hex/helpers/http_requests_emscripten.hpp | 116 +++++++++--------- main/gui/CMakeLists.txt | 2 + .../include/content/helpers/disassembler.hpp | 2 + plugins/ui/CMakeLists.txt | 1 + .../ui/include/popups/popup_file_chooser.hpp | 2 + 9 files changed, 86 insertions(+), 58 deletions(-) diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index 793f8c095..61ee66b2d 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -758,4 +758,15 @@ endfunction() function(addIncludesFromLibrary target library) get_target_property(library_include_dirs ${library} INTERFACE_INCLUDE_DIRECTORIES) target_include_directories(${target} PRIVATE ${library_include_dirs}) +endfunction() + +function(precompileHeaders target includeFolder) + file(GLOB_RECURSE TARGET_INCLUDES "${includeFolder}/**/*.hpp") + set(SYSTEM_INCLUDES ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;") + set(INCLUDES "${SYSTEM_INCLUDES};${TARGET_INCLUDES}") + string(REPLACE ">" "$" INCLUDES "${INCLUDES}") + target_precompile_headers(${target} + PUBLIC + "$<$:${INCLUDES}>" + ) endfunction() \ No newline at end of file diff --git a/cmake/modules/ImHexPlugin.cmake b/cmake/modules/ImHexPlugin.cmake index a170eed61..be565dcd0 100644 --- a/cmake/modules/ImHexPlugin.cmake +++ b/cmake/modules/ImHexPlugin.cmake @@ -36,8 +36,10 @@ macro(add_imhex_plugin) # Add include directories and link libraries target_include_directories(${IMHEX_PLUGIN_NAME} PUBLIC ${IMHEX_PLUGIN_INCLUDES}) - target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE libimhex ${IMHEX_PLUGIN_LIBRARIES} ${FMT_LIBRARIES} imgui_all_includes libwolv) + target_link_libraries(${IMHEX_PLUGIN_NAME} PUBLIC ${IMHEX_PLUGIN_LIBRARIES}) + target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE libimhex ${FMT_LIBRARIES} imgui_all_includes libwolv) addIncludesFromLibrary(${IMHEX_PLUGIN_NAME} libpl) + addIncludesFromLibrary(${IMHEX_PLUGIN_NAME} libpl-gen) # Add IMHEX_PROJECT_NAME and IMHEX_VERSION define target_compile_definitions(${IMHEX_PLUGIN_NAME} PRIVATE IMHEX_PROJECT_NAME="${IMHEX_PLUGIN_NAME}") @@ -94,6 +96,8 @@ macro(add_imhex_plugin) target_link_libraries(${IMHEX_PLUGIN_NAME} PUBLIC ${IMHEX_PLUGIN_NAME}_tests) target_compile_definitions(${IMHEX_PLUGIN_NAME}_tests PRIVATE IMHEX_PROJECT_NAME="${IMHEX_PLUGIN_NAME}-tests") endif() + + precompileHeaders(${IMHEX_PLUGIN_NAME} "${CMAKE_CURRENT_SOURCE_DIR}/include") endmacro() macro(add_romfs_resource input output) diff --git a/lib/external/libwolv b/lib/external/libwolv index 3856ed29f..7806c1939 160000 --- a/lib/external/libwolv +++ b/lib/external/libwolv @@ -1 +1 @@ -Subproject commit 3856ed29ff136b13c01eadecc169e04109647dd7 +Subproject commit 7806c1939d5aa6c9af794e4b2ff9116bb89d54d8 diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index df7f73592..7e5dd848d 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -77,6 +77,8 @@ else() set(LIBIMHEX_LIBRARY_TYPE PUBLIC) target_compile_definitions(libimhex PRIVATE IMHEX_PROJECT_NAME="${PROJECT_NAME}") + + precompileHeaders(libimhex "${CMAKE_CURRENT_SOURCE_DIR}/include") endif() enableUnityBuild(libimhex) diff --git a/lib/libimhex/include/hex/helpers/http_requests_emscripten.hpp b/lib/libimhex/include/hex/helpers/http_requests_emscripten.hpp index dfce3a668..7098dec69 100644 --- a/lib/libimhex/include/hex/helpers/http_requests_emscripten.hpp +++ b/lib/libimhex/include/hex/helpers/http_requests_emscripten.hpp @@ -1,72 +1,76 @@ #pragma once -#include +#if defined(OS_WEB) -#include + #include -namespace hex { - template - std::future> HttpRequest::downloadFile(const std::fs::path &path) { - return std::async(std::launch::async, [this, path] { - std::vector response; + #include - // Execute the request - auto result = this->executeImpl(response); + namespace hex { + template + std::future> HttpRequest::downloadFile(const std::fs::path &path) { + return std::async(std::launch::async, [this, path] { + std::vector response; - // Write the result to the file - wolv::io::File file(path, wolv::io::File::Mode::Create); - file.writeBuffer(reinterpret_cast(result.getData().data()), result.getData().size()); + // Execute the request + auto result = this->executeImpl(response); - return result; - }); - } + // Write the result to the file + wolv::io::File file(path, wolv::io::File::Mode::Create); + file.writeBuffer(reinterpret_cast(result.getData().data()), result.getData().size()); - template - std::future> HttpRequest::uploadFile(const std::fs::path &path, const std::string &mimeName) { - hex::unused(path, mimeName); - throw std::logic_error("Not implemented"); - } - - template - std::future> HttpRequest::uploadFile(std::vector data, const std::string &mimeName, const std::fs::path &fileName) { - hex::unused(data, mimeName, fileName); - throw std::logic_error("Not implemented"); - } - - template - std::future> HttpRequest::execute() { - return std::async(std::launch::async, [this] { - std::vector responseData; - - return this->executeImpl(responseData); - }); - } - - template - HttpRequest::Result HttpRequest::executeImpl(std::vector &data) { - strcpy(m_attr.requestMethod, m_method.c_str()); - m_attr.attributes = EMSCRIPTEN_FETCH_SYNCHRONOUS | EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; - - if (!m_body.empty()) { - m_attr.requestData = m_body.c_str(); - m_attr.requestDataSize = m_body.size(); + return result; + }); } - std::vector headers; - for (auto it = m_headers.begin(); it != m_headers.end(); it++) { - headers.push_back(it->first.c_str()); - headers.push_back(it->second.c_str()); + template + std::future> HttpRequest::uploadFile(const std::fs::path &path, const std::string &mimeName) { + hex::unused(path, mimeName); + throw std::logic_error("Not implemented"); } - headers.push_back(nullptr); - m_attr.requestHeaders = headers.data(); - // Send request - emscripten_fetch_t* fetch = emscripten_fetch(&m_attr, m_url.c_str()); + template + std::future> HttpRequest::uploadFile(std::vector data, const std::string &mimeName, const std::fs::path &fileName) { + hex::unused(data, mimeName, fileName); + throw std::logic_error("Not implemented"); + } - data.resize(fetch->numBytes); - std::copy(fetch->data, fetch->data + fetch->numBytes, data.begin()); + template + std::future> HttpRequest::execute() { + return std::async(std::launch::async, [this] { + std::vector responseData; + + return this->executeImpl(responseData); + }); + } + + template + HttpRequest::Result HttpRequest::executeImpl(std::vector &data) { + strcpy(m_attr.requestMethod, m_method.c_str()); + m_attr.attributes = EMSCRIPTEN_FETCH_SYNCHRONOUS | EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; + + if (!m_body.empty()) { + m_attr.requestData = m_body.c_str(); + m_attr.requestDataSize = m_body.size(); + } + + std::vector headers; + for (auto it = m_headers.begin(); it != m_headers.end(); it++) { + headers.push_back(it->first.c_str()); + headers.push_back(it->second.c_str()); + } + headers.push_back(nullptr); + m_attr.requestHeaders = headers.data(); + + // Send request + emscripten_fetch_t* fetch = emscripten_fetch(&m_attr, m_url.c_str()); + + data.resize(fetch->numBytes); + std::copy(fetch->data, fetch->data + fetch->numBytes, data.begin()); + + return Result(fetch->status, { data.begin(), data.end() }); + } - return Result(fetch->status, { data.begin(), data.end() }); } -} \ No newline at end of file +#endif \ No newline at end of file diff --git a/main/gui/CMakeLists.txt b/main/gui/CMakeLists.txt index ab86c86aa..35c0876e3 100644 --- a/main/gui/CMakeLists.txt +++ b/main/gui/CMakeLists.txt @@ -63,6 +63,8 @@ else () target_link_libraries(main PRIVATE pthread) endif () +precompileHeaders(main ${CMAKE_CURRENT_SOURCE_DIR}/include) + if (APPLE) add_compile_definitions(GL_SILENCE_DEPRECATION) endif () \ No newline at end of file diff --git a/plugins/disassembler/include/content/helpers/disassembler.hpp b/plugins/disassembler/include/content/helpers/disassembler.hpp index 640431c3f..a3d796db2 100644 --- a/plugins/disassembler/include/content/helpers/disassembler.hpp +++ b/plugins/disassembler/include/content/helpers/disassembler.hpp @@ -2,6 +2,8 @@ #include +#include + #include namespace hex::plugin::disasm { diff --git a/plugins/ui/CMakeLists.txt b/plugins/ui/CMakeLists.txt index cad681bc6..a929c5cf5 100644 --- a/plugins/ui/CMakeLists.txt +++ b/plugins/ui/CMakeLists.txt @@ -13,6 +13,7 @@ add_imhex_plugin( INCLUDES include LIBRARIES + libpl libpl-gen fonts LIBRARY_PLUGIN diff --git a/plugins/ui/include/popups/popup_file_chooser.hpp b/plugins/ui/include/popups/popup_file_chooser.hpp index 950bb1511..8c4b7a05d 100644 --- a/plugins/ui/include/popups/popup_file_chooser.hpp +++ b/plugins/ui/include/popups/popup_file_chooser.hpp @@ -9,6 +9,8 @@ #include #include +#include +#include namespace hex::ui {