diff --git a/.devcontainer b/.devcontainer new file mode 160000 index 000000000..97db0d6b7 --- /dev/null +++ b/.devcontainer @@ -0,0 +1 @@ +Subproject commit 97db0d6b7d00d8f33e52e646a1aef1395fa58931 diff --git a/.gitattributes b/.gitattributes index 6f598bb7f..fa97c8d06 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 000000000..b9166a830 --- /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 000000000..273199e97 --- /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 e7e8fba9b..27e4d7cfc 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,8 @@ Doxyfile Doxyfile.zh-cn DartConfiguration.tcl *.nupkg + +# externpro +.env +_bld*/ +docker-compose.override.yml diff --git a/.gitmodules b/.gitmodules index 5e41f7c97..8612e8ad7 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 ec7632782..e5e548456 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,16 +7,13 @@ if(POLICY CMP0054) cmake_policy(SET CMP0054 NEW) endif() +set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES .devcontainer/cmake/xproinc.cmake) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules) PROJECT(RapidJSON CXX) include(GNUInstallDirs) include(xpflags) -if(DEFINED XP_NAMESPACE) - set(nameSpace NAMESPACE ${XP_NAMESPACE}::) - set(XP_OPT_INSTALL EXCLUDE_FROM_ALL) -endif() set(LIB_MAJOR_VERSION "1") set(LIB_MINOR_VERSION "1") @@ -113,9 +110,24 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) string(TOLOWER ${PROJECT_NAME} lib_name) add_library(${lib_name} INTERFACE) target_include_directories(${lib_name} INTERFACE $) + +function(callPackageDevel) + set(lib ${lib_name}) + string(PREPEND lib "${XP_NAMESPACE}::") + set(CMAKE_PROJECT_NAME ${lib_name}) + xpPackageDevel(TARGETS_FILE ${targetsFile} LIBRARIES ${lib}) +endfunction() + set(targetsFile ${lib_name}-targets) -install(TARGETS ${lib_name} EXPORT ${targetsFile}) -install(EXPORT ${targetsFile} DESTINATION ${CMAKE_INSTALL_DIR} ${nameSpace}) +if(DEFINED XP_NAMESPACE) + set(nameSpace NAMESPACE ${XP_NAMESPACE}::) + callPackageDevel() + set(RAPIDJSON_COMPONENT devel) +else() + set(RAPIDJSON_COMPONENT dev) +endif() +install(TARGETS ${lib_name} EXPORT ${targetsFile} COMPONENT devel) +install(EXPORT ${targetsFile} DESTINATION ${CMAKE_INSTALL_DIR} ${nameSpace} COMPONENT devel) if(RAPIDJSON_BUILD_DOC) add_subdirectory(doc) @@ -144,22 +156,19 @@ IF (UNIX OR CYGWIN) ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc @ONLY) INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc - ${XP_OPT_INSTALL} DESTINATION "${LIB_INSTALL_DIR}/pkgconfig" COMPONENT pkgconfig) ENDIF() install(FILES readme.md - ${XP_OPT_INSTALL} DESTINATION "${DOC_INSTALL_DIR}" COMPONENT doc) install(DIRECTORY include/rapidjson DESTINATION "${INCLUDE_INSTALL_DIR}" - COMPONENT dev) + COMPONENT ${RAPIDJSON_COMPONENT}) install(DIRECTORY example/ - ${XP_OPT_INSTALL} DESTINATION "${DOC_INSTALL_DIR}/examples" COMPONENT examples # Following patterns are for excluding the intermediate/object files @@ -183,6 +192,5 @@ CONFIGURE_FILE(${PROJECT_NAME}ConfigVersion.cmake.in INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake - ${XP_OPT_INSTALL} DESTINATION "${CMAKE_INSTALL_DIR}" COMPONENT dev) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..f82cfdd2c --- /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 000000000..4489d79c3 --- /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 000000000..85f182f0b --- /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 000000000..46c1f8918 --- /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 36e0fd9d1..d44c72670 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8...3.24) +cmake_minimum_required(VERSION 2.8...3.31) if(POLICY CMP0054) cmake_policy(SET CMP0054 NEW) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 11c1b04c7..7f407e06b 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() diff --git a/test/perftest/schematest.cpp b/test/perftest/schematest.cpp index 468f5fe6f..7d27344b5 100644 --- a/test/perftest/schematest.cpp +++ b/test/perftest/schematest.cpp @@ -11,6 +11,11 @@ using namespace rapidjson; +RAPIDJSON_DIAG_PUSH +#if defined(__GNUC__) && __GNUC__ >= 7 +RAPIDJSON_DIAG_OFF(format-overflow) +#endif + template static char* ReadFile(const char* filename, Allocator& allocator) { const char *paths[] = { @@ -42,6 +47,8 @@ static char* ReadFile(const char* filename, Allocator& allocator) { return json; } +RAPIDJSON_DIAG_POP + class Schema : public PerfTest { public: Schema() {}