mirror of
https://github.com/marzer/tomlplusplus.git
synced 2026-01-19 04:52:09 +00:00
Allow tomlplusplus to be built by C++20 modules (#266)
This commit is contained in:
@@ -30,11 +30,26 @@ target_include_directories(
|
|||||||
|
|
||||||
target_compile_features(tomlplusplus_tomlplusplus INTERFACE cxx_std_17)
|
target_compile_features(tomlplusplus_tomlplusplus INTERFACE cxx_std_17)
|
||||||
|
|
||||||
# ---- Install rules, examples, and fuzzing ----
|
# ---- Install rules ----
|
||||||
if (tomlplusplus_INSTALL)
|
if (tomlplusplus_INSTALL)
|
||||||
include(cmake/install-rules.cmake)
|
include(cmake/install-rules.cmake)
|
||||||
endif()
|
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)
|
if(PROJECT_IS_TOP_LEVEL)
|
||||||
option(BUILD_EXAMPLES "Build examples tree." OFF)
|
option(BUILD_EXAMPLES "Build examples tree." OFF)
|
||||||
option(BUILD_FUZZER "Build fuzzer." OFF)
|
option(BUILD_FUZZER "Build fuzzer." OFF)
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -20,6 +20,7 @@
|
|||||||
## Library features
|
## Library features
|
||||||
|
|
||||||
- Header-only (optional!)
|
- Header-only (optional!)
|
||||||
|
- Module support
|
||||||
- Supports the latest [TOML] release ([v1.0.0]), plus optional support for some unreleased TOML features
|
- 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
|
- Passes all tests in the [toml-test](https://github.com/toml-lang/toml-test) suite
|
||||||
- Supports serializing to JSON and YAML
|
- 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
|
### 🍨️ Regular flavour
|
||||||
|
|
||||||
1. Clone the repository
|
1. Clone the repository
|
||||||
2. Add `tomlplusplus/include` to your include paths
|
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 <toml++/toml.hpp>`
|
3. `#include <toml++/toml.hpp>` (or `import tomlplusplus;`)
|
||||||
|
|
||||||
### Conan
|
### Conan
|
||||||
|
|
||||||
@@ -281,13 +282,16 @@ UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's '[
|
|||||||
|
|
||||||
### With thanks to:
|
### With thanks to:
|
||||||
|
|
||||||
|
- **[@a-is](https://github.com/a-is)** - Fixed a bug
|
||||||
- **[@beastle9end](https://github.com/beastle9end)** - Made Windows.h include bypass
|
- **[@beastle9end](https://github.com/beastle9end)** - Made Windows.h include bypass
|
||||||
- **[@bjadamson](https://github.com/bjadamson)** - Reported some bugs and helped design a new feature
|
- **[@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)
|
- **[@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
|
- **[@GiulioRomualdi](https://github.com/GiulioRomualdi)** - Added cmake+meson support
|
||||||
- **[@jonestristand](https://github.com/jonestristand)** - Designed and implemented the `toml::path`s feature
|
- **[@jonestristand](https://github.com/jonestristand)** - Designed and implemented the `toml::path`s feature
|
||||||
- **[@kcsaul](https://github.com/kcsaul)** - Fixed a bug
|
- **[@kcsaul](https://github.com/kcsaul)** - Fixed a bug
|
||||||
- **[@levicki](https://github.com/levicki)** - Helped design some new features
|
- **[@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
|
- **[@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
|
- **[@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`
|
- **[@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
|
- **[@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
|
- **[@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
|
- **[@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
|
- **[@whiterabbit963](https://github.com/whiterabbit963)** - Fixed a bug with value_or conversions
|
||||||
- **[@ximion](https://github.com/ximion)** - Added support for installation with meson
|
- **[@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
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
## Contact
|
## Contact
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
@section mainpage-features Features
|
@section mainpage-features Features
|
||||||
|
|
||||||
- Header-only (optional!)
|
- Header-only (optional!)
|
||||||
|
- Module support
|
||||||
- Supports the latest [TOML](https://toml.io/) release ([v1.0.0](https://toml.io/en/v1.0.0)), plus
|
- 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
|
optional support for some unreleased TOML features
|
||||||
- Passes all tests in the [toml-test](https://github.com/BurntSushi/toml-test) suite
|
- 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
|
@cpp
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <toml++/toml.hpp>
|
#include <toml++/toml.hpp>
|
||||||
|
// or alternatively:
|
||||||
|
import tomlplusplus; // if C++20 or later
|
||||||
|
|
||||||
int main(int argc, char\*\* argv)
|
int main(int argc, char\*\* argv)
|
||||||
{
|
{
|
||||||
@@ -460,8 +463,8 @@ and [emoji sundae] Regular. The API is the same for both.
|
|||||||
|
|
||||||
<h3>[emoji sundae] Regular flavour</h3>
|
<h3>[emoji sundae] Regular flavour</h3>
|
||||||
1. Clone \github{marzer/tomlplusplus, the repository} from GitHub
|
1. Clone \github{marzer/tomlplusplus, the repository} from GitHub
|
||||||
2. Add `tomlplusplus/include` to your include paths
|
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 <toml++/toml.hpp>`
|
3. `#include <toml++/toml.hpp>` (or `import tomlplusplus;`)
|
||||||
|
|
||||||
<!-- --------------------------------------------------------------------------------------------------------------- -->
|
<!-- --------------------------------------------------------------------------------------------------------------- -->
|
||||||
|
|
||||||
|
|||||||
39
src/modules/CMakeLists.txt
Normal file
39
src/modules/CMakeLists.txt
Normal file
@@ -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()
|
||||||
67
src/modules/tomlpp.cppm
Normal file
67
src/modules/tomlpp.cppm
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
* @file tomlpp.cppm
|
||||||
|
* @brief File containing the module declaration for toml++.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module;
|
||||||
|
|
||||||
|
#include <toml++/toml.hpp>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user