Skip to content
Merged
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 .devcontainer
Submodule .devcontainer added at 97db0d
7 changes: 6 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ Dockerfile text
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.json binary
bin/**/*.json binary
library.json binary
package.json binary

# Exceptions for JSON files that should be treated as text
CMakePresets*.json text eol=lf
30 changes: 30 additions & 0 deletions .github/workflows/xpbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build
on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]
workflow_dispatch:
jobs:
linux:
uses: externpro/externpro/.github/workflows/build-linux.yml@25.05.2
with:
cmake-workflow-preset: LinuxRelease
runon: ubuntu-latest
secrets: inherit
linux-arm64:
uses: externpro/externpro/.github/workflows/build-linux.yml@25.05.2
with:
cmake-workflow-preset: LinuxRelease
runon: ubuntu-24.04-arm
secrets: inherit
macos:
uses: externpro/externpro/.github/workflows/build-macos.yml@25.05.2
with:
cmake-workflow-preset: DarwinRelease
secrets: inherit
windows:
uses: externpro/externpro/.github/workflows/build-windows.yml@25.05.2
with:
cmake-workflow-preset: WindowsRelease
secrets: inherit
20 changes: 20 additions & 0 deletions .github/workflows/xprelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Release
on:
workflow_dispatch:
inputs:
workflow_run_url:
description: 'URL of the workflow run containing artifacts to upload (e.g., https://github.com/owner/repo/actions/runs/123456789)'
required: true
type: string
jobs:
# Upload build artifacts as release assets
release-from-build:
uses: externpro/externpro/.github/workflows/release-from-build.yml@25.05.2
with:
workflow_run_url: ${{ github.event.inputs.workflow_run_url }}
artifact_pattern: "*.tar.xz"
permissions:
contents: write
id-token: write
attestations: write
secrets: inherit
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ Doxyfile.zh-cn
DartConfiguration.tcl
*.nupkg

# externpro
.env
_bld*/
docker-compose.override.yml

# Files created by OS
*.DS_Store
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "thirdparty/gtest"]
path = thirdparty/gtest
url = https://github.com/google/googletest.git
[submodule ".devcontainer"]
path = .devcontainer
url = https://github.com/externpro/externpro
55 changes: 36 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5...3.31)

set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES .devcontainer/cmake/xproinc.cmake)
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules)

set(LIB_MAJOR_VERSION "1")
Expand All @@ -9,6 +10,9 @@ set(LIB_VERSION_STRING "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_PATCH_VE

PROJECT(RapidJSON VERSION "${LIB_VERSION_STRING}" LANGUAGES CXX)

include(GNUInstallDirs)
include(xpflags)

# compile in release with debug info mode by default
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
Expand Down Expand Up @@ -144,25 +148,38 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL")
endif()

#add extra search paths for libraries and includes
SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in")
SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "Directory where lib will install")
SET(DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}" CACHE PATH "Path to the documentation")

IF(UNIX OR CYGWIN)
SET(_CMAKE_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}")
ELSEIF(WIN32)
SET(_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/cmake")
ENDIF()
SET(CMAKE_INSTALL_DIR "${_CMAKE_INSTALL_DIR}" CACHE PATH "The directory cmake files are installed in")
SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE PATH "The directory the headers are installed in")
SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE STRING "Directory where lib will install")
SET(DOC_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/doc/${PROJECT_NAME}" CACHE PATH "Path to the documentation")
if(NOT DEFINED XP_INSTALL_CMAKEDIR)
set(XP_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATADIR}/cmake")
endif()
SET(CMAKE_INSTALL_DIR "${XP_INSTALL_CMAKEDIR}" CACHE PATH "The directory cmake files are installed in")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

function(callPackageDevel)
set(lib ${PROJECT_NAME})
string(PREPEND lib ${XP_NAMESPACE}::)
string(TOLOWER ${PROJECT_NAME} CMAKE_PROJECT_NAME)
xpPackageDevel(TARGETS_FILE ${targetsFile} LIBRARIES ${lib})
endfunction()

set(targetsFile ${PROJECT_NAME}-targets)
if(DEFINED XP_NAMESPACE)
set(nameSpace NAMESPACE ${XP_NAMESPACE}::)
callPackageDevel()
set(RAPIDJSON_COMPONENT devel)
else()
set(RAPIDJSON_COMPONENT dev)
endif()

if(RAPIDJSON_BUILD_DOC)
add_subdirectory(doc)
endif()

add_custom_target(travis_doc)
add_custom_command(TARGET travis_doc
add_custom_command(TARGET travis_doc POST_BUILD
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/travis-doxygen.sh)

if(RAPIDJSON_BUILD_EXAMPLES)
Expand Down Expand Up @@ -193,13 +210,13 @@ install(FILES readme.md
COMPONENT doc)

# Add an interface target to export it
add_library(RapidJSON INTERFACE)
add_library(${PROJECT_NAME} INTERFACE)

target_include_directories(RapidJSON INTERFACE $<INSTALL_INTERFACE:include>)
target_include_directories(${PROJECT_NAME} INTERFACE $<INSTALL_INTERFACE:include>)

install(DIRECTORY include/rapidjson
DESTINATION "${INCLUDE_INSTALL_DIR}"
COMPONENT dev)
COMPONENT ${RAPIDJSON_COMPONENT})

install(DIRECTORY example/
DESTINATION "${DOC_INSTALL_DIR}/examples"
Expand Down Expand Up @@ -230,10 +247,10 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}ConfigVersion.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake @ONLY)

# ... for the install tree
SET( CMAKECONFIG_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME} )
SET( CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DIR}" )
FILE( RELATIVE_PATH REL_INCLUDE_DIR
"${CMAKECONFIG_INSTALL_DIR}"
"${CMAKE_INSTALL_PREFIX}/include" )
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}" )

SET( ${PROJECT_NAME}_INCLUDE_DIR "\${${PROJECT_NAME}_CMAKE_DIR}/${REL_INCLUDE_DIR}" )
SET( CONFIG_SOURCE_DIR )
Expand All @@ -252,6 +269,6 @@ IF(CMAKE_INSTALL_DIR)
DESTINATION "${CMAKE_INSTALL_DIR}"
COMPONENT dev)

INSTALL(TARGETS RapidJSON EXPORT RapidJSON-targets)
INSTALL(EXPORT RapidJSON-targets DESTINATION ${CMAKE_INSTALL_DIR})
INSTALL(TARGETS ${PROJECT_NAME} EXPORT ${targetsFile} COMPONENT ${RAPIDJSON_COMPONENT})
INSTALL(EXPORT ${targetsFile} DESTINATION ${CMAKE_INSTALL_DIR} ${nameSpace} COMPONENT ${RAPIDJSON_COMPONENT})
ENDIF()
8 changes: 8 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 8,
"include": [
".devcontainer/cmake/presets/xpLinuxNinja.json",
".devcontainer/cmake/presets/xpDarwinNinja.json",
".devcontainer/cmake/presets/xpWindowsVs2022.json"
]
}
19 changes: 19 additions & 0 deletions CMakePresetsBase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": 8,
"configurePresets": [
{
"name": "config-base",
"hidden": true,
"binaryDir": "${sourceDir}/_bld-${presetName}",
"cacheVariables": {
"XP_NAMESPACE": "xpro"
}
}
],
"buildPresets": [
{
"name": "build-base",
"hidden": true
}
]
}
1 change: 1 addition & 0 deletions docker-compose.sh
1 change: 1 addition & 0 deletions docker-compose.yml
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.5...3.31)

if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
Expand Down
10 changes: 5 additions & 5 deletions example/jsonx/jsonx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@ class JsonxWriter {

bool Int(int i) {
char buffer[12];
return WriteNumberElement(buffer, sprintf(buffer, "%d", i));
return WriteNumberElement(buffer, snprintf(buffer, sizeof(buffer), "%d", i));
}

bool Uint(unsigned i) {
char buffer[11];
return WriteNumberElement(buffer, sprintf(buffer, "%u", i));
return WriteNumberElement(buffer, snprintf(buffer, sizeof(buffer), "%u", i));
}

bool Int64(int64_t i) {
char buffer[21];
return WriteNumberElement(buffer, sprintf(buffer, "%" PRId64, i));
return WriteNumberElement(buffer, snprintf(buffer, sizeof(buffer), "%" PRId64, i));
}

bool Uint64(uint64_t i) {
char buffer[21];
return WriteNumberElement(buffer, sprintf(buffer, "%" PRIu64, i));
return WriteNumberElement(buffer, snprintf(buffer, sizeof(buffer), "%" PRIu64, i));
}

bool Double(double d) {
char buffer[30];
return WriteNumberElement(buffer, sprintf(buffer, "%.17g", d));
return WriteNumberElement(buffer, snprintf(buffer, sizeof(buffer), "%.17g", d));
}

bool RawNumber(const char* str, SizeType length, bool) {
Expand Down
2 changes: 1 addition & 1 deletion example/tutorial/tutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int main(int, char*[]) {
Value author;
{
char buffer2[10];
int len = sprintf(buffer2, "%s %s", "Milo", "Yip"); // synthetic example of dynamically created string.
int len = snprintf(buffer2, sizeof(buffer2), "%s %s", "Milo", "Yip"); // synthetic example of dynamically created string.

author.SetString(buffer2, static_cast<SizeType>(len), document.GetAllocator());
// Shorter but slower version:
Expand Down
15 changes: 14 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
find_package(GTestSrc)
if(COMMAND xpFindPkg)
xpFindPkg(PKGS googletest)
enable_testing()
get_target_property(GTEST_INCLUDE_DIR xpro::gtest INTERFACE_INCLUDE_DIRECTORIES)
include_directories(SYSTEM ${GTEST_INCLUDE_DIR})
set(TEST_LIBRARIES xpro::gtest xpro::gtest_main)
if(FALSE) # doesn't build with googletest-v1.16.0.1
add_custom_target(tests ALL)
add_subdirectory(perftest)
add_subdirectory(unittest)
endif()
else()
find_package(GTestSrc)
endif()

IF(GTESTSRC_FOUND)
enable_testing()
Expand Down