diff --git a/CMakeLists.txt b/CMakeLists.txt index 2617d1fa7..f9530c838 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ option(IMHEX_ENABLE_STD_ASSERTS "Enable debug asserts in the C++ std lib option(IMHEX_ENABLE_UNIT_TESTS "Enable building unit tests" OFF) option(IMHEX_ENABLE_PRECOMPILED_HEADERS "Enable precompiled headers" OFF) option(IMHEX_COMPRESS_DEBUG_INFO "Compress debug information" ON ) +option(IMHEX_ENABLE_CXX_MODULES "Enable C++20 Module compilation. Testing only!" OFF) set(IMHEX_BASE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}") set(CMAKE_MODULE_PATH "${IMHEX_BASE_FOLDER}/cmake/modules") diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index a0ea2a355..afa6c7bd0 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -639,6 +639,7 @@ macro(setupCompilerFlags target) addCommonFlag("/wd4267" ${target}) # 'var': conversion from 'size_t' to 'type', possible loss of data addCommonFlag("/wd4305" ${target}) # truncation from 'double' to 'float' addCommonFlag("/wd4996" ${target}) # 'function': was declared deprecated + addCommonFlag("/wd5244" ${target}) # 'include' in the purview of module 'module' appears erroneous if (IMHEX_STRICT_WARNINGS) addCommonFlag("/WX" ${target}) diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index 071cf1735..e4a6feb7d 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -82,6 +82,15 @@ else() add_library(libimhex SHARED ${LIBIMHEX_SOURCES}) endif() + if (IMHEX_ENABLE_CXX_MODULES) + target_sources(libimhex + PUBLIC + FILE_SET cxx_modules TYPE CXX_MODULES + FILES + include/hex.cppm + ) + endif() + set(LIBIMHEX_LIBRARY_TYPE PUBLIC) target_compile_definitions(libimhex PRIVATE IMHEX_PROJECT_NAME="${PROJECT_NAME}") endif() diff --git a/lib/libimhex/include/hex.cppm b/lib/libimhex/include/hex.cppm new file mode 100644 index 000000000..3958b5343 --- /dev/null +++ b/lib/libimhex/include/hex.cppm @@ -0,0 +1,38 @@ +module; + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +export module hex; + +#define HEX_MODULE_EXPORT +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include \ No newline at end of file diff --git a/lib/libimhex/include/hex.hpp b/lib/libimhex/include/hex.hpp index c1e553612..e3db152d1 100644 --- a/lib/libimhex/include/hex.hpp +++ b/lib/libimhex/include/hex.hpp @@ -1,3 +1,9 @@ #pragma once #include + +#if defined(HEX_MODULE_EXPORT) + #define EXPORT_MODULE export +#else + #define EXPORT_MODULE +#endif \ No newline at end of file diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index ff65b9286..eb33be161 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -20,7 +20,7 @@ struct ImFontAtlas; struct ImFont; struct GLFWwindow; -namespace hex { +EXPORT_MODULE namespace hex { namespace impl { class AutoResetBase; @@ -767,7 +767,7 @@ namespace hex { void loadFont(const std::fs::path &path, const std::vector &glyphRanges = {}, Offset offset = {}, u32 flags = 0, std::optional defaultSize = std::nullopt); void loadFont(const std::string &name, const std::span &data, const std::vector &glyphRanges = {}, Offset offset = {}, u32 flags = 0, std::optional defaultSize = std::nullopt); - constexpr static float DefaultFontSize = 13.0; + constexpr float DefaultFontSize = 13.0; void registerFont(const UnlocalizedString &fontName); ImFont* getFont(const UnlocalizedString &fontName); diff --git a/lib/libimhex/include/hex/api/localization_manager.hpp b/lib/libimhex/include/hex/api/localization_manager.hpp index c3db82386..05cef447d 100644 --- a/lib/libimhex/include/hex/api/localization_manager.hpp +++ b/lib/libimhex/include/hex/api/localization_manager.hpp @@ -10,7 +10,7 @@ #include #include -namespace hex { +EXPORT_MODULE namespace hex { namespace LocalizationManager { diff --git a/lib/libimhex/include/hex/helpers/fs.hpp b/lib/libimhex/include/hex/helpers/fs.hpp index 80babb466..a0cd31a03 100644 --- a/lib/libimhex/include/hex/helpers/fs.hpp +++ b/lib/libimhex/include/hex/helpers/fs.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -7,7 +8,7 @@ #include -namespace hex::fs { +EXPORT_MODULE namespace hex::fs { enum class DialogMode { Open, diff --git a/lib/libimhex/include/hex/helpers/semantic_version.hpp b/lib/libimhex/include/hex/helpers/semantic_version.hpp index 109489427..7e7365c72 100644 --- a/lib/libimhex/include/hex/helpers/semantic_version.hpp +++ b/lib/libimhex/include/hex/helpers/semantic_version.hpp @@ -6,7 +6,7 @@ #include #include -namespace hex { +EXPORT_MODULE namespace hex { class SemanticVersion { public: