From 99d83228f5cac02afabe667442ee4e6f835ce639 Mon Sep 17 00:00:00 2001 From: Toyosatomimi no Miko Date: Sat, 24 Oct 2026 00:25:24 -0400 Subject: [PATCH 1/2] feat: Add C++ modules support --- CMakeLists.txt | 1 + src/CMakeLists.txt | 5 +++ src/modules/CMakeLists.txt | 27 +++++++++++++ src/modules/jsoncpp.cppm | 78 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 src/modules/CMakeLists.txt create mode 100644 src/modules/jsoncpp.cppm diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d977b71c..3cd1b902c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ option(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON) option(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" ON) option(JSONCPP_WITH_EXAMPLE "Compile JsonCpp example" OFF) option(JSONCPP_WITH_INSTALL "Include JsonCpp header and binaries in the install target" ON) +option(JSONCPP_WITH_MODULE "Compile JsonCpp module" OFF) option(JSONCPP_STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime" OFF) option(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." ON) option(BUILD_STATIC_LIBS "Build jsoncpp_lib as a static library." ON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f82a7463..6afff6c02 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,3 +3,8 @@ if(JSONCPP_WITH_TESTS) add_subdirectory(jsontestrunner) add_subdirectory(test_lib_json) endif() + +#install the example +if(JSONCPP_WITH_MODULE) + add_subdirectory(modules) +endif() diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt new file mode 100644 index 000000000..ffadee57d --- /dev/null +++ b/src/modules/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.28) + +add_library(jsoncpp_module) + +target_sources(jsoncpp_module + PUBLIC + FILE_SET CXX_MODULES FILES + jsoncpp.cppm +) + +target_compile_features(jsoncpp_module PUBLIC cxx_std_20) + +target_include_directories(jsoncpp_module PUBLIC + $ + $ +) + +add_library(jsoncpp::module ALIAS jsoncpp_module) + +# Installation +install(TARGETS jsoncpp_module + EXPORT ${PROJECT_NAME}Targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/jsoncpp/modules +) diff --git a/src/modules/jsoncpp.cppm b/src/modules/jsoncpp.cppm new file mode 100644 index 000000000..96174a4ab --- /dev/null +++ b/src/modules/jsoncpp.cppm @@ -0,0 +1,78 @@ +// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +module; + +#include + +export module jsoncpp; + +export namespace Json { + // writer.h + using Json::StreamWriter; + using Json::StreamWriterBuilder; + using Json::Writer; + using Json::FastWriter; + using Json::StyledWriter; + using Json::StyledStreamWriter; + using Json::valueToString; + using Json::valueToQuotedString; + using Json::operator<<; + + // reader.h + using Json::Reader; + using Json::CharReader; + using Json::CharReaderBuilder; + using Json::parseFromStream; + using Json::operator>>; + + // json_features.h + using Json::Features; + + // value.h + using Json::ArrayIndex; + using Json::StaticString; + using Json::Path; + using Json::PathArgument; + using Json::Value; + using Json::ValueIteratorBase; + using Json::ValueIterator; + using Json::ValueConstIterator; + using Json::ValueMembersView; + using Json::ValueConstMembersView; + + // config.h + using Json::version; + using Json::Int; + using Json::UInt; + using Json::Int64; + using Json::UInt64; + using Json::LargestInt; + using Json::LargestUInt; + using Json::Allocator; + using Json::String; + using Json::IStringStream; + using Json::OStringStream; + using Json::IStream; + using Json::OStream; + + // allocator.h + using Json::SecureAllocator; + using Json::operator==; + using Json::operator!=; + + // value.h + #if JSON_USE_EXCEPTION + using Json::Exception; + using Json::RuntimeError; + using Json::LogicError; + #endif + using Json::ValueType; + using Json::CommentPlacement; + using Json::PrecisionType; + using Json::MemberProxy; + using Json::ConstMemberProxy; + using Json::swap; +} // namespace Json From 574a96101ee086e89dea3c2ab2bab5405c40cdb5 Mon Sep 17 00:00:00 2001 From: Toyosatomimi no Miko Date: Tue, 27 Oct 2026 15:37:14 -0400 Subject: [PATCH 2/2] Address Greptile suggestions for module and CMake --- jsoncpp-namespaced-targets.cmake | 4 ++++ src/modules/CMakeLists.txt | 28 +++++++++++++++++++++------- src/modules/jsoncpp.cppm | 17 +++++++++++++++++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/jsoncpp-namespaced-targets.cmake b/jsoncpp-namespaced-targets.cmake index 70a79ee7f..f91633241 100644 --- a/jsoncpp-namespaced-targets.cmake +++ b/jsoncpp-namespaced-targets.cmake @@ -7,3 +7,7 @@ if (NOT TARGET JsonCpp::JsonCpp) set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_lib") endif () endif () + +if (TARGET jsoncpp_module AND NOT TARGET jsoncpp::module) + add_library(jsoncpp::module ALIAS jsoncpp_module) +endif () diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index ffadee57d..d35e6a96e 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -10,6 +10,12 @@ target_sources(jsoncpp_module target_compile_features(jsoncpp_module PUBLIC cxx_std_20) +if(BUILD_SHARED_LIBS) + target_link_libraries(jsoncpp_module PUBLIC jsoncpp_lib) +elseif(BUILD_STATIC_LIBS) + target_link_libraries(jsoncpp_module PUBLIC jsoncpp_static) +endif() + target_include_directories(jsoncpp_module PUBLIC $ $ @@ -18,10 +24,18 @@ target_include_directories(jsoncpp_module PUBLIC add_library(jsoncpp::module ALIAS jsoncpp_module) # Installation -install(TARGETS jsoncpp_module - EXPORT ${PROJECT_NAME}Targets - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/jsoncpp/modules -) +if(JSONCPP_WITH_CMAKE_PACKAGE) + set(MODULE_INSTALL_EXPORT EXPORT jsoncpp) +else() + set(MODULE_INSTALL_EXPORT) +endif() + +if(JSONCPP_WITH_INSTALL) + install(TARGETS jsoncpp_module + ${MODULE_INSTALL_EXPORT} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/jsoncpp/modules + ) +endif() diff --git a/src/modules/jsoncpp.cppm b/src/modules/jsoncpp.cppm index 96174a4ab..aa069d42d 100644 --- a/src/modules/jsoncpp.cppm +++ b/src/modules/jsoncpp.cppm @@ -47,8 +47,10 @@ export namespace Json { using Json::version; using Json::Int; using Json::UInt; + #ifdef JSON_HAS_INT64 using Json::Int64; using Json::UInt64; + #endif using Json::LargestInt; using Json::LargestUInt; using Json::Allocator; @@ -74,5 +76,20 @@ export namespace Json { using Json::PrecisionType; using Json::MemberProxy; using Json::ConstMemberProxy; + using Json::nullValue; + using Json::intValue; + using Json::uintValue; + using Json::realValue; + using Json::stringValue; + using Json::booleanValue; + using Json::arrayValue; + using Json::objectValue; + using Json::commentBefore; + using Json::commentAfterOnSameLine; + using Json::commentAfter; + using Json::numberOfCommentPlacement; + using Json::significantDigits; + using Json::decimalPlaces; using Json::swap; + using Json::writeString; } // namespace Json