diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d1a137..a9c5a91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,11 +30,26 @@ target_include_directories( target_compile_features(tomlplusplus_tomlplusplus INTERFACE cxx_std_17) -# ---- Install rules, examples, and fuzzing ---- +# ---- Install rules ---- if (tomlplusplus_INSTALL) include(cmake/install-rules.cmake) endif() +# ---- C++ Modules Support (optional) ---- +option(TOMLPLUSPLUS_BUILD_MODULES "Build C++ modules support" OFF) + +if(TOMLPLUSPLUS_BUILD_MODULES) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) + message(STATUS "Building C++ modules (CMake ${CMAKE_VERSION} supports modules)") + add_subdirectory(src/modules) + else() + message(WARNING "Skipping C++ modules (requires CMake 3.28+, found ${CMAKE_VERSION})") + endif() +else() + message(STATUS "C++ modules support is disabled. Enable with -DTOMLPLUSPLUS_BUILD_MODULES=ON") +endif() + +# ---- Examples and fuzzing ---- if(PROJECT_IS_TOP_LEVEL) option(BUILD_EXAMPLES "Build examples tree." OFF) option(BUILD_FUZZER "Build fuzzer." OFF) diff --git a/README.md b/README.md index aa91af2..7992d7b 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ ## Library features - Header-only (optional!) +- Module support - Supports the latest [TOML] release ([v1.0.0]), plus optional support for some unreleased TOML features - Passes all tests in the [toml-test](https://github.com/toml-lang/toml-test) suite - Supports serializing to JSON and YAML @@ -110,8 +111,8 @@ You'll find some more code examples in the `examples` directory, and plenty more ### 🍨️ Regular flavour 1. Clone the repository -2. Add `tomlplusplus/include` to your include paths -3. `#include ` +2. Add `tomlplusplus/include` to your include paths, or for optional module support add `tomlplusplus/modules` as well and enable `TOMLPLUSPLUS_BUILD_MODULES` +3. `#include ` (or `import tomlplusplus;`) ### Conan @@ -281,13 +282,16 @@ UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's '[ ### With thanks to: +- **[@a-is](https://github.com/a-is)** - Fixed a bug - **[@beastle9end](https://github.com/beastle9end)** - Made Windows.h include bypass - **[@bjadamson](https://github.com/bjadamson)** - Reported some bugs and helped design a new feature - **[@bobfang1992](https://github.com/bobfang1992)** - Reported a bug and created a [wrapper in python](https://github.com/bobfang1992/pytomlpp) +- **[@capuanob](https://github.com/capuanob)** - Integrated this project into OSSFuzz - **[@GiulioRomualdi](https://github.com/GiulioRomualdi)** - Added cmake+meson support - **[@jonestristand](https://github.com/jonestristand)** - Designed and implemented the `toml::path`s feature - **[@kcsaul](https://github.com/kcsaul)** - Fixed a bug - **[@levicki](https://github.com/levicki)** - Helped design some new features +- **[@mikomikotaishi](https://github.com/mikomikotaishi)** - Added support for C++20 modules - **[@moorereason](https://github.com/moorereason)** - Reported a whole bunch of bugs - **[@mosra](https://github.com/mosra)** - Created the awesome [m.css] used to generate the API docs - **[@N-Dekker](https://github.com/N-Dekker)** - Added a workaround for the legacy lambda processor of MSVC 2019/2022, added `get_line` @@ -304,11 +308,9 @@ UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's '[ - **[@std-any-emplace](https://github.com/std-any-emplace)** - Reported some bugs - **[@Tachi107](https://github.com/Tachi107)** - Made some tweaks to meson.build, added compile_library build option - **[@traversaro](https://github.com/traversaro)** - Added vcpkg support and reported a bunch of bugs +- **[@tyler92](https://github.com/tyler92)** - Fixed stack overflow that occurred during fuzzing tests - **[@whiterabbit963](https://github.com/whiterabbit963)** - Fixed a bug with value_or conversions - **[@ximion](https://github.com/ximion)** - Added support for installation with meson -- **[@a-is](https://github.com/a-is)** - Fixed a bug -- **[@capuanob](https://github.com/capuanob)** - Integrated this project into OSSFuzz -- **[@tyler92](https://github.com/tyler92)** - Fixed stack overflow that occurred during fuzzing tests
## Contact diff --git a/docs/pages/main_page.md b/docs/pages/main_page.md index 65961ac..0f57374 100644 --- a/docs/pages/main_page.md +++ b/docs/pages/main_page.md @@ -7,6 +7,7 @@ @section mainpage-features Features - Header-only (optional!) +- Module support - Supports the latest [TOML](https://toml.io/) release ([v1.0.0](https://toml.io/en/v1.0.0)), plus optional support for some unreleased TOML features - Passes all tests in the [toml-test](https://github.com/BurntSushi/toml-test) suite @@ -37,6 +38,8 @@ Call toml::parse_file() and work with the toml::table you get back, or handle an @cpp #include #include +// or alternatively: +import tomlplusplus; // if C++20 or later int main(int argc, char\*\* argv) { @@ -460,8 +463,8 @@ and [emoji sundae] Regular. The API is the same for both.

[emoji sundae] Regular flavour

1. Clone \github{marzer/tomlplusplus, the repository} from GitHub -2. Add `tomlplusplus/include` to your include paths -3. `#include ` +2. Add `tomlplusplus/include` to your include paths, or for optional module support add `tomlplusplus/modules` as well and enable `TOMLPLUSPLUS_BUILD_MODULES` +3. `#include ` (or `import tomlplusplus;`) diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt new file mode 100644 index 0000000..356e7cc --- /dev/null +++ b/src/modules/CMakeLists.txt @@ -0,0 +1,39 @@ +file(GLOB_RECURSE TOMLPLUSPLUS_MODULES *.cppm) + +add_library(tomlplusplus_modules) + +cmake_minimum_required(VERSION 3.28) + +if(NOT COMMAND configure_cpp_module_target) + function(configure_cpp_module_target target) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) + target_sources(${target} PUBLIC FILE_SET CXX_MODULES FILES ${TOMLPLUSPLUS_MODULES}) + else() + message(WARNING "C++ modules require CMake 3.28+. Using standard compilation.") + target_sources(${target} PRIVATE ${TOMLPLUSPLUS_MODULES}) + endif() + endfunction() +endif() + +configure_cpp_module_target(tomlplusplus_modules) + +target_link_libraries(tomlplusplus_modules + PUBLIC + tomlplusplus::tomlplusplus +) + +target_include_directories(tomlplusplus_modules + PRIVATE + ${tomlplusplus_SOURCE_DIR}/include +) + +target_compile_features(tomlplusplus_modules PUBLIC cxx_std_20) + +if(TOMLPLUSPLUS_ENABLE_INSTALL) + install(TARGETS tomlplusplus_modules + EXPORT tomlplusplus-targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tomlplusplus/modules + ) +endif() diff --git a/src/modules/tomlpp.cppm b/src/modules/tomlpp.cppm new file mode 100644 index 0000000..6346562 --- /dev/null +++ b/src/modules/tomlpp.cppm @@ -0,0 +1,67 @@ +/** + * @file tomlpp.cppm + * @brief File containing the module declaration for toml++. + */ + +module; + +#include + +export module tomlplusplus; + +/** + * @namespace toml + * @brief The toml++ namespace toml:: + */ +export namespace toml { + /** + * @namespace literals + * @brief The toml++ namespace toml::literals:: + */ + inline namespace literals { + using toml::literals::operator""_toml; + using toml::literals::operator""_tpath; + } + + using toml::array; + using toml::date; + using toml::date_time; + using toml::inserter; + using toml::json_formatter; + using toml::key; + using toml::node; + using toml::node_view; + using toml::parse_error; + using toml::parse_result; + using toml::path; + using toml::path_component; + using toml::source_position; + using toml::source_region; + using toml::table; + using toml::time; + using toml::time_offset; + using toml::toml_formatter; + using toml::value; + using toml::yaml_formatter; + using toml::format_flags; + using toml::node_type; + using toml::path_component_type; + using toml::value_flags; + using toml::array_iterator; + using toml::const_array_iterator; + using toml::const_table_iterator; + using toml::default_formatter; + using toml::inserted_type_of; + using toml::optional; + using toml::source_index; + using toml::source_path_ptr; + using toml::table_iterator; + + using toml::at_path; + using toml::get_line; + using toml::operator""_toml; + using toml::operator""_tpath; + using toml::operator<<; + using toml::parse; + using toml::parse_file; +}