Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions jsoncpp-namespaced-targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
41 changes: 41 additions & 0 deletions src/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.28)

add_library(jsoncpp_module)
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

target_sources(jsoncpp_module
PUBLIC
FILE_SET CXX_MODULES FILES
jsoncpp.cppm
)

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
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

add_library(jsoncpp::module ALIAS jsoncpp_module)

# Installation
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
Comment on lines +34 to +39

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Installed module imports fail

This installs the module source, but the existing install(EXPORT jsoncpp ...) call does not write the information CMake needs to connect import jsoncpp to that source. A separate project can find and link jsoncpp::module but cannot compile code that imports it. Add CXX_MODULES_DIRECTORY to the package export when modules are enabled.

Knowledge Base Used: Consumer package integration

)
endif()
95 changes: 95 additions & 0 deletions src/modules/jsoncpp.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// 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 <json/json.h>

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;
#ifdef JSON_HAS_INT64
using Json::Int64;
using Json::UInt64;
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
#endif
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;
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
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