build: Added some initial test code for C++ Modules

This commit is contained in:
WerWolv
2025-02-17 22:57:21 +01:00
parent b81c3d2f75
commit abf97212fe
9 changed files with 61 additions and 5 deletions

View File

@@ -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")

View File

@@ -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})

View File

@@ -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()

View File

@@ -0,0 +1,38 @@
module;
#include <cmath>
#include <map>
#include <string>
#include <string_view>
#include <vector>
#include <exception>
#include <algorithm>
#include <locale>
#include <array>
#include <filesystem>
#include <functional>
#include <memory>
#include <list>
#include <atomic>
#include <ranges>
#include <fstream>
#include <thread>
#include <fmt/format.h>
#include <nlohmann/json.hpp>
export module hex;
#define HEX_MODULE_EXPORT
#include <hex/api/achievement_manager.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/api/event_manager.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/layout_manager.hpp>
#include <hex/api/localization_manager.hpp>
#include <hex/api/plugin_manager.hpp>
#include <hex/api/shortcut_manager.hpp>
#include <hex/api/task_manager.hpp>
#include <hex/api/theme_manager.hpp>
#include <hex/api/tutorial_manager.hpp>
#include <hex/api/workspace_manager.hpp>

View File

@@ -1,3 +1,9 @@
#pragma once
#include <hex/helpers/types.hpp>
#if defined(HEX_MODULE_EXPORT)
#define EXPORT_MODULE export
#else
#define EXPORT_MODULE
#endif

View File

@@ -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<GlyphRange> &glyphRanges = {}, Offset offset = {}, u32 flags = 0, std::optional<u32> defaultSize = std::nullopt);
void loadFont(const std::string &name, const std::span<const u8> &data, const std::vector<GlyphRange> &glyphRanges = {}, Offset offset = {}, u32 flags = 0, std::optional<u32> defaultSize = std::nullopt);
constexpr static float DefaultFontSize = 13.0;
constexpr float DefaultFontSize = 13.0;
void registerFont(const UnlocalizedString &fontName);
ImFont* getFont(const UnlocalizedString &fontName);

View File

@@ -10,7 +10,7 @@
#include <fmt/core.h>
#include <wolv/types/static_string.hpp>
namespace hex {
EXPORT_MODULE namespace hex {
namespace LocalizationManager {

View File

@@ -1,5 +1,6 @@
#pragma once
#include <hex.hpp>
#include <string>
#include <vector>
#include <filesystem>
@@ -7,7 +8,7 @@
#include <wolv/io/fs.hpp>
namespace hex::fs {
EXPORT_MODULE namespace hex::fs {
enum class DialogMode {
Open,

View File

@@ -6,7 +6,7 @@
#include <string>
#include <vector>
namespace hex {
EXPORT_MODULE namespace hex {
class SemanticVersion {
public: