-
Notifications
You must be signed in to change notification settings - Fork 11
feat: C++20 modules support #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wdconinc
wants to merge
7
commits into
iLCSoft:master
Choose a base branch
from
wdconinc:cxx-modules
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5c614c9
fix: static constexpr -> inline constexpr
wdconinc 4c095b0
feat: module exports for core SIO types and interfaces
wdconinc 030b69a
feat: support SIO_ENABLE_CXX_MODULES CMake option (default OFF)
wdconinc 61d31a2
fix: mv sio_module.ixx to ensure canonical install path
wdconinc 39f23e5
fix: use conventional static inline constexpr ordering
wdconinc f16fa9f
docs: improve cmake SIO_ADD_MODULE_INTERFACE documentation
wdconinc 4a2a337
docs: add comment about SIO::ZLIB target visibility
wdconinc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #--------------------------------------------------------------------------------------------------- | ||
| # CMake support for C++20 modules in SIO | ||
| # | ||
| # This file provides macros and options for generating and using C++20 module interfaces | ||
| # for the SIO library. | ||
| #--------------------------------------------------------------------------------------------------- | ||
|
|
||
| # Option to enable C++20 module generation | ||
| option(SIO_ENABLE_CXX_MODULES "Generate C++20 module interface files (.ixx) for SIO" OFF) | ||
|
|
||
| # Check if modules are actually supported | ||
| if(SIO_ENABLE_CXX_MODULES) | ||
| # Check CMake version | ||
| if(CMAKE_VERSION VERSION_LESS 3.29) | ||
| message(WARNING "C++20 modules require CMake 3.29 or later (found ${CMAKE_VERSION}). Disabling module support.") | ||
| set(SIO_ENABLE_CXX_MODULES OFF CACHE BOOL "C++20 modules disabled due to CMake version" FORCE) | ||
| endif() | ||
|
|
||
| # Check generator | ||
| if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") | ||
| message(WARNING "C++20 modules are not supported with the Unix Makefiles generator. Please use Ninja. Disabling module support.") | ||
| set(SIO_ENABLE_CXX_MODULES OFF CACHE BOOL "C++20 modules disabled due to generator" FORCE) | ||
| endif() | ||
|
|
||
| # Check compiler support | ||
| if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
| if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14.0) | ||
| message(WARNING "C++20 modules require GCC 14 or later (found ${CMAKE_CXX_COMPILER_VERSION}). Disabling module support.") | ||
| set(SIO_ENABLE_CXX_MODULES OFF CACHE BOOL "C++20 modules disabled due to compiler version" FORCE) | ||
| endif() | ||
| elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
| if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0) | ||
| message(WARNING "C++20 modules require Clang 18 or later (found ${CMAKE_CXX_COMPILER_VERSION}). Disabling module support.") | ||
| set(SIO_ENABLE_CXX_MODULES OFF CACHE BOOL "C++20 modules disabled due to compiler version" FORCE) | ||
| endif() | ||
| else() | ||
| message(WARNING "C++20 modules have only been tested with GCC 14+ and Clang 18+. Found ${CMAKE_CXX_COMPILER_ID}. Proceed at your own risk.") | ||
| endif() | ||
| endif() | ||
|
|
||
| if(SIO_ENABLE_CXX_MODULES) | ||
| message(STATUS "C++20 module support is ENABLED for SIO") | ||
| message(STATUS " - CMake version: ${CMAKE_VERSION}") | ||
| message(STATUS " - Generator: ${CMAKE_GENERATOR}") | ||
| message(STATUS " - Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") | ||
| else() | ||
| message(STATUS "C++20 module support is DISABLED for SIO") | ||
| endif() | ||
|
|
||
| #--------------------------------------------------------------------------------------------------- | ||
| # SIO_ADD_MODULE_INTERFACE( target module_file ) | ||
| # | ||
| # Add a C++20 module interface to a SIO target. | ||
| # | ||
| # This function conditionally adds a module interface file to the specified target when | ||
| # SIO_ENABLE_CXX_MODULES is ON. The module interface is added as a PUBLIC CXX_MODULES file set, | ||
| # which makes it available for installation and use by downstream projects. | ||
| # | ||
| # When SIO_ENABLE_CXX_MODULES is OFF, this function returns immediately without any action. | ||
| # | ||
| # Arguments: | ||
| # target - The target to which the module interface should be added | ||
| # module_file - The .ixx file implementing the module interface (absolute or relative path) | ||
| # | ||
| # Example: | ||
| # SIO_ADD_MODULE_INTERFACE(sio ${CMAKE_CURRENT_SOURCE_DIR}/sio_module.ixx) | ||
| # | ||
| # Note: | ||
| # The module_file should be installed separately using INSTALL(TARGETS ... FILE_SET CXX_MODULES) | ||
| # when SIO_ENABLE_CXX_MODULES is ON. | ||
| #--------------------------------------------------------------------------------------------------- | ||
| function(SIO_ADD_MODULE_INTERFACE target module_file) | ||
| if(NOT SIO_ENABLE_CXX_MODULES) | ||
| return() | ||
| endif() | ||
|
|
||
| message(STATUS "Adding C++20 module 'sio' to target '${target}'") | ||
|
|
||
| # Add the module file to the target as a CXX_MODULES file set | ||
| # Use PUBLIC so the module gets installed and can be used by downstream projects | ||
| target_sources(${target} | ||
| PUBLIC | ||
| FILE_SET CXX_MODULES | ||
| BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} | ||
| FILES ${module_file} | ||
| ) | ||
| endfunction() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Module interface for SIO - Simple I/O library | ||
| // | ||
| // This module exports the core SIO types and interfaces. | ||
|
|
||
| module; | ||
|
|
||
| // Global module fragment - includes go here | ||
| #include <cctype> | ||
| #include <cstdint> | ||
| #include <fstream> | ||
| #include <functional> | ||
| #include <iostream> | ||
| #include <map> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <type_traits> | ||
| #include <vector> | ||
|
|
||
| #ifdef __APPLE__ | ||
| #include <_types.h> | ||
| #include <_types/_uint16_t.h> | ||
| #include <_types/_uint32_t.h> | ||
| #include <_types/_uint64_t.h> | ||
| #include <_types/_uint8_t.h> | ||
| #include <sys/_types/_int16_t.h> | ||
| #include <sys/_types/_int64_t.h> | ||
| #else | ||
| #include <stdint.h> | ||
| #endif | ||
|
|
||
| // SIO headers | ||
| #include "sio/definitions.h" | ||
| #include "sio/exception.h" | ||
| #include "sio/version.h" | ||
| #include "sio/buffer.h" | ||
| #include "sio/block.h" | ||
| #include "sio/io_device.h" | ||
| #include "sio/memcpy.h" | ||
| #include "sio/api.h" | ||
| #include "sio/compression/zlib.h" | ||
|
|
||
| export module sio; | ||
|
|
||
| // Export SIO namespace and types | ||
| export namespace sio { | ||
| // Type aliases from definitions.h | ||
| using sio::byte; | ||
| using sio::byte_array; | ||
| using sio::byte_traits; | ||
| using sio::index_type; | ||
| using sio::options_type; | ||
| using sio::version_type; | ||
| using sio::ptr_type; | ||
| using sio::pointed_at_map; | ||
| using sio::pointer_to_map; | ||
| using sio::ifstream; | ||
| using sio::ofstream; | ||
| using sio::fstream; | ||
| using sio::block_ptr; | ||
| using sio::block_list; | ||
|
|
||
| // Constants from definitions.h | ||
| using sio::null_byte; | ||
| using sio::padding_bytes; | ||
| using sio::kbyte; | ||
| using sio::mbyte; | ||
| using sio::compression_bit; | ||
| using sio::bit_align; | ||
| using sio::padding; | ||
| using sio::padding_mask; | ||
| using sio::record_marker; | ||
| using sio::block_marker; | ||
| using sio::max_record_name_len; | ||
| using sio::max_record_info_len; | ||
| using sio::single_len; | ||
| using sio::double_len; | ||
| using sio::quad_len; | ||
| using sio::octo_len; | ||
|
|
||
| // Structs and enums from definitions.h | ||
| using sio::record_info; | ||
| using sio::validate; | ||
| using sio::valid_record_name; | ||
|
|
||
| // Exception types | ||
| using sio::exception; | ||
| using sio::error_code; | ||
|
|
||
| // Version class | ||
| using sio::version; | ||
|
|
||
| // Core classes | ||
| using sio::buffer; | ||
| using sio::buffer_span; | ||
| using sio::block; | ||
| using sio::read_device; | ||
| using sio::write_device; | ||
|
|
||
| // Memory copy utilities | ||
| using sio::memcpy; | ||
| using sio::sizeof_helper; | ||
|
|
||
| // API class and functions | ||
| using sio::api; | ||
|
|
||
| // Compression | ||
| using sio::zlib_compression; | ||
| } | ||
wdconinc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.