diff --git a/.devcontainer b/.devcontainer new file mode 160000 index 0000000000..97db0d6b7d --- /dev/null +++ b/.devcontainer @@ -0,0 +1 @@ +Subproject commit 97db0d6b7d00d8f33e52e646a1aef1395fa58931 diff --git a/.gitattributes b/.gitattributes index 6f598bb7f9..fa97c8d066 100644 --- a/.gitattributes +++ b/.gitattributes @@ -19,4 +19,9 @@ Dockerfile text # Denote all files that are truly binary and should not be modified. *.png binary *.jpg binary -*.json binary \ No newline at end of file +bin/**/*.json binary +library.json binary +package.json binary + +# Exceptions for JSON files that should be treated as text +CMakePresets*.json text eol=lf diff --git a/.github/workflows/xpbuild.yml b/.github/workflows/xpbuild.yml new file mode 100644 index 0000000000..b9166a830e --- /dev/null +++ b/.github/workflows/xpbuild.yml @@ -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 diff --git a/.github/workflows/xprelease.yml b/.github/workflows/xprelease.yml new file mode 100644 index 0000000000..273199e97d --- /dev/null +++ b/.github/workflows/xprelease.yml @@ -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 diff --git a/.gitignore b/.gitignore index 5932e82c21..e5ecd59830 100644 --- a/.gitignore +++ b/.gitignore @@ -25,5 +25,10 @@ Doxyfile.zh-cn DartConfiguration.tcl *.nupkg +# externpro +.env +_bld*/ +docker-compose.override.yml + # Files created by OS *.DS_Store diff --git a/.gitmodules b/.gitmodules index 5e41f7c975..8612e8ad70 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index be860c93d7..d651d203bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -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) @@ -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) @@ -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 $) +target_include_directories(${PROJECT_NAME} INTERFACE $) install(DIRECTORY include/rapidjson DESTINATION "${INCLUDE_INSTALL_DIR}" - COMPONENT dev) + COMPONENT ${RAPIDJSON_COMPONENT}) install(DIRECTORY example/ DESTINATION "${DOC_INSTALL_DIR}/examples" @@ -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 ) @@ -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() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000000..f82cfdd2cf --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,8 @@ +{ + "version": 8, + "include": [ + ".devcontainer/cmake/presets/xpLinuxNinja.json", + ".devcontainer/cmake/presets/xpDarwinNinja.json", + ".devcontainer/cmake/presets/xpWindowsVs2022.json" + ] +} diff --git a/CMakePresetsBase.json b/CMakePresetsBase.json new file mode 100644 index 0000000000..4489d79c34 --- /dev/null +++ b/CMakePresetsBase.json @@ -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 + } + ] +} diff --git a/docker-compose.sh b/docker-compose.sh new file mode 120000 index 0000000000..85f182f0be --- /dev/null +++ b/docker-compose.sh @@ -0,0 +1 @@ +.devcontainer/compose.pro.sh \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 120000 index 0000000000..46c1f8918f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1 @@ +.devcontainer/compose.bld.yml \ No newline at end of file diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 9f53c9aadc..0d5908c86d 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -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) diff --git a/example/jsonx/jsonx.cpp b/example/jsonx/jsonx.cpp index 954aa2b907..b2d72317b5 100644 --- a/example/jsonx/jsonx.cpp +++ b/example/jsonx/jsonx.cpp @@ -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) { diff --git a/example/tutorial/tutorial.cpp b/example/tutorial/tutorial.cpp index d6021c6689..6e10d9d33d 100644 --- a/example/tutorial/tutorial.cpp +++ b/example/tutorial/tutorial.cpp @@ -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(len), document.GetAllocator()); // Shorter but slower version: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 11c1b04c7d..7f407e06b6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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()