diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..1e35c08 --- /dev/null +++ b/.clang-format @@ -0,0 +1,31 @@ +--- +Language: Cpp +BasedOnStyle: LLVM +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Attach +ColumnLimit: 160 +SpaceAfterTemplateKeyword: true +Standard: c++23 +TabWidth: 4 +IndentWidth: 4 +UseTab: Always +AllowShortEnumsOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortBlocksOnASingleLine: Always +AllowShortIfStatementsOnASingleLine: Always +AllowShortLoopsOnASingleLine: true +IndentRequires: true +IncludeCategories: + # Headers in <> with .h extension. + - Regex: '<([A-Za-z0-9\/-_])+\.h>' + Priority: 10 + # Headers in <> with .hpp extension. + - Regex: '<([A-Za-z0-9\/-_])+\.hpp>' + Priority: 20 + # Headers in <> without extension. + - Regex: '<([A-Za-z0-9\/-_])+>' + Priority: 30 +PointerAlignment: Left +QualifierAlignment: Left diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..aa01f91 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,22 @@ +--- +Checks: 'clang-analyzer-*, + concurrency-*, + cppcoreguidelines-*, + -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-avoid-const-or-ref-data-members, + -cppcoreguidelines-avoid-do-while, + misc-*, + -misc-non-private-member-variables-in-classes, + -misc-no-recursion, + modernize-*, + -modernize-use-trailing-return-type, + performance-*, + portability-*, + readability-*, + -readability-identifier-length, + -readability-implicit-bool-conversion, + -readability-magic-numbers, + -readability-redundant-member-init, + -readability-uppercase-literal-suffix' +... diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c8d67b8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +[*] +insert_final_newline = true +charset = utf-8 +indent_size = 4 +indent_style = tab +# Optional: git will commit as lf, this will only affect local files +end_of_line = lf + +[*.{py,md,yml,sh,cmake,json}] +indent_style = space +indent_size = 2 + +[*.{py,md,yml,sh,cmake,json}.in] +indent_style = space +indent_size = 2 + +[CMakeLists.txt] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3954059 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,105 @@ +name: ci-pr +on: [pull_request, workflow_dispatch] +jobs: + x64-linux-gcc: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: init + run: uname -m; sudo apt install -yqq ninja-build + - name: configure + run: cmake -S . --preset=ninja-gcc -B build -DCMAKE_C_COMPILER=gcc-14 -DCMAKE_CXX_COMPILER=g++-14 + - name: build debug + run: cmake --build build --config=Debug -- -v + - name: build release + run: cmake --build build --config=Release -- -v + - name: test debug + run: cd build && ctest -V -C Debug + - name: test release + run: cd build && ctest -V -C Release + x64-linux-clang: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: init + run: | + uname -m + sudo apt update -yqq && sudo apt install -yqq clang-19 ninja-build + sudo update-alternatives --remove-all clang++ + sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 10 + - name: configure + run: cmake -S . --preset=ninja-clang -B build + - name: build debug + run: cmake --build build --config=Debug -- -v + - name: build release + run: cmake --build build --config=Release -- -v + - name: test debug + run: cd build && ctest -V -C Debug + - name: test release + run: cd build && ctest -V -C Release + arm64-linux-gcc: + runs-on: ubuntu-24.04-arm + steps: + - uses: actions/checkout@v4 + - name: init + run: uname -m + - name: configure + run: cmake -S . --preset=ninja-gcc -B build -DCMAKE_C_COMPILER=gcc-14 -DCMAKE_CXX_COMPILER=g++-14 + - name: build debug + run: cmake --build build --config=Debug -- -v + - name: build release + run: cmake --build build --config=Release -- -v + - name: test debug + run: cd build && ctest -V -C Debug + - name: test release + run: cd build && ctest -V -C Release + arm64-linux-clang: + runs-on: ubuntu-24.04-arm + steps: + - uses: actions/checkout@v4 + - name: init + run: | + uname -m + sudo apt update -yqq && sudo apt install -yqq clang-19 ninja-build + sudo update-alternatives --remove-all clang++ + sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 10 + - name: configure + run: cmake -S . --preset=ninja-clang -B build + - name: build debug + run: cmake --build build --config=Debug -- -v + - name: build release + run: cmake --build build --config=Release -- -v + - name: test debug + run: cd build && ctest -V -C Debug + - name: test release + run: cd build && ctest -V -C Release + x64-windows-vs22: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - name: configure + run: cmake -S . --preset=vs22 -B build + - name: build debug + run: cmake --build build --config=Debug --parallel + - name: build release + run: cmake --build build --config=Release --parallel + - name: test debug + run: cd build && ctest -V -C Debug + - name: test release + run: cd build && ctest -V -C Release + x64-windows-clang: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - name: init + run: choco install ninja + - name: configure + run: cmake -S . --preset=ninja-clang -B clang + - name: build debug + run: cmake --build clang --config=Debug -- -v + - name: build release + run: cmake --build clang --config=Release -- -v + - name: test debug + run: cd clang && ctest -V -C Debug + - name: test release + run: cd clang && ctest -V -C Release diff --git a/.gitignore b/.gitignore index fe27ea5..c1d1196 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,13 @@ /Test/out/build/x64-debug /cppjson/out/build/x64-debug /out/build/x64-Debug + +# clangd +/.cache +compile_commands.json + +# CMake presets +CMakeUserPresets.json + +# CMake build output +/out diff --git a/CMakeLists.txt b/CMakeLists.txt index c99d92f..110edd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,19 @@ -cmake_minimum_required (VERSION 3.8) +cmake_minimum_required(VERSION 3.24) -add_subdirectory("cppjson") -add_subdirectory("Test") \ No newline at end of file +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_DEBUG_POSTFIX "-d") + +include(version.cmake) + +project(cppjson VERSION ${cppjson_version}) + +option(CPPJSON_BUILD_TESTS "Build cppjson tests" ${PROJECT_IS_TOP_LEVEL}) + +add_subdirectory(cppjson) + +if(CPPJSON_BUILD_TESTS) + enable_testing() + add_subdirectory(Test) +endif() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..d8e0236 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,250 @@ +{ + "version": 5, + "cmakeMinimumRequired": { + "major": 3, + "minor": 24, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default", + "displayName": "Default Config", + "description": "Base configuration using Ninja Multi-config", + "generator": "Ninja Multi-Config", + "binaryDir": "${sourceDir}/out/default", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "base-gcc", + "hidden": true, + "inherits": "default", + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + } + }, + { + "name": "base-clang", + "hidden": true, + "inherits": "default", + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + } + }, + { + "name": "base-msvc", + "hidden": true, + "inherits": "default", + "cacheVariables": { + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl" + } + }, + { + "name": "ninja-gcc", + "displayName": "Ninja GCC", + "description": "Build configuration using Ninja Multi-config / GCC", + "inherits": "base-gcc", + "binaryDir": "${sourceDir}/out/gcc", + "cacheVariables": { + "CMAKE_CXX_FLAGS_INIT": "-Wall -Wextra -Wpedantic -Wconversion -Werror=return-type", + "CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT": "-Werror", + "CMAKE_CXX_FLAGS_RELEASE_INIT": "-Werror" + } + }, + { + "name": "ninja-clang", + "displayName": "Ninja Clang", + "description": "Build configuration using Ninja Multi-config / Clang", + "inherits": "base-clang", + "binaryDir": "${sourceDir}/out/clang", + "cacheVariables": { + "CMAKE_CXX_FLAGS_INIT": "-Wall -Wextra -Wpedantic -Wconversion -Werror=return-type", + "CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT": "-Werror", + "CMAKE_CXX_FLAGS_RELEASE_INIT": "-Werror" + } + }, + { + "name": "ninja-msvc", + "displayName": "Ninja MSVC", + "description": "Build configuration using Ninja Multi-config / MSVC", + "inherits": "base-msvc", + "binaryDir": "${sourceDir}/out/msvc", + "cacheVariables": { + "CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT": "/WX", + "CMAKE_CXX_FLAGS_RELEASE_INIT": "/WX" + } + }, + { + "name": "ninja-ubsan", + "displayName": "Ninja UBSan", + "description": "UBSan build configuration using Ninja Multi-config", + "inherits": "default", + "binaryDir": "${sourceDir}/out/ubsan", + "cacheVariables": { + "CMAKE_CXX_FLAGS_INIT": "-fsanitize=undefined -Wall -Wextra -Wpedantic -Wconversion -Werror=return-type" + } + }, + { + "name": "ninja-asan", + "displayName": "Ninja ASan", + "description": "ASan build configuration using Ninja Multi-config", + "inherits": "default", + "binaryDir": "${sourceDir}/out/asan", + "cacheVariables": { + "CMAKE_CXX_FLAGS_INIT": "-fsanitize=address -Wall -Wextra -Wpedantic -Wconversion -Werror=return-type" + } + }, + { + "name": "ninja-msvc-asan", + "displayName": "Ninja MSVC ASan", + "description": "ASan build configuration using Ninja Multi-config", + "inherits": "base-msvc", + "binaryDir": "${sourceDir}/out/asan", + "cacheVariables": { + "CMAKE_CXX_FLAGS_INIT": "-fsanitize=address" + } + }, + { + "name": "ninja-tsan", + "displayName": "Ninja TSan", + "description": "TSan build configuration using Ninja Multi-config", + "inherits": "default", + "binaryDir": "${sourceDir}/out/tsan", + "cacheVariables": { + "CMAKE_CXX_FLAGS_INIT": "-fsanitize=thread -Wall -Wextra -Wpedantic -Wconversion -Werror=return-type" + } + }, + { + "name": "vs22", + "displayName": "Visual Studio 2022", + "description": "Build configuration using Visual Studio 17 (2022)", + "generator": "Visual Studio 17 2022", + "binaryDir": "${sourceDir}/out/vs", + "cacheVariables": { + "CMAKE_CXX_FLAGS_INIT": "/WX" + }, + "architecture": { + "value": "x64", + "strategy": "external" + } + } + ], + "buildPresets": [ + { + "name": "Debug", + "configurePreset": "default", + "configuration": "Debug" + }, + { + "name": "Release", + "configurePreset": "default", + "configuration": "Release" + }, + { + "name": "RelWithDebInfo", + "configurePreset": "default", + "configuration": "RelWithDebInfo" + }, + { + "name": "GCC Debug", + "configurePreset": "ninja-gcc", + "configuration": "Debug" + }, + { + "name": "GCC RelWithDebInfo", + "configurePreset": "ninja-gcc", + "configuration": "RelWithDebInfo" + }, + { + "name": "Clang Debug", + "configurePreset": "ninja-clang", + "configuration": "Debug" + }, + { + "name": "Clang RelWithDebInfo", + "configurePreset": "ninja-clang", + "configuration": "RelWithDebInfo" + }, + { + "name": "MSVC Debug", + "configurePreset": "ninja-msvc", + "configuration": "Debug" + }, + { + "name": "MSVC Release", + "configurePreset": "ninja-msvc", + "configuration": "Release" + }, + { + "name": "UBSan Debug", + "configurePreset": "ninja-ubsan", + "configuration": "Debug" + } + ], + "testPresets": [ + { + "name": "Debug", + "configurePreset": "default", + "configuration": "Debug", + "inheritConfigureEnvironment": true + }, + { + "name": "Release", + "configurePreset": "default", + "configuration": "Release", + "inheritConfigureEnvironment": true + }, + { + "name": "RelWithDebInfo", + "configurePreset": "default", + "configuration": "RelWithDebInfo", + "inheritConfigureEnvironment": true + }, + { + "name": "GCC Debug", + "configurePreset": "ninja-gcc", + "configuration": "Debug", + "inheritConfigureEnvironment": true + }, + { + "name": "GCC RelWithDebInfo", + "configurePreset": "ninja-gcc", + "configuration": "RelWithDebInfo", + "inheritConfigureEnvironment": true + }, + { + "name": "Clang Debug", + "configurePreset": "ninja-clang", + "configuration": "Debug", + "inheritConfigureEnvironment": true + }, + { + "name": "Clang RelWithDebInfo", + "configurePreset": "ninja-clang", + "configuration": "RelWithDebInfo", + "inheritConfigureEnvironment": true + }, + { + "name": "MSVC Debug", + "configurePreset": "ninja-msvc", + "configuration": "Debug", + "inheritConfigureEnvironment": true + }, + { + "name": "MSVC Release", + "configurePreset": "ninja-msvc", + "configuration": "Release", + "inheritConfigureEnvironment": true + }, + { + "name": "UBSan Debug", + "configurePreset": "ninja-ubsan", + "configuration": "Debug", + "inheritConfigureEnvironment": true + } + ] +} \ No newline at end of file diff --git a/Test/CMakeLists.txt b/Test/CMakeLists.txt index 92dda0e..c04d300 100644 --- a/Test/CMakeLists.txt +++ b/Test/CMakeLists.txt @@ -1,21 +1,15 @@ -# CMakeList.txt : CMake project for Test, include source and define -# project specific logic here. -# -cmake_minimum_required (VERSION 3.8) +add_executable(cppjson-Test) -# Enable Hot Reload for MSVC compilers if supported. -if (POLICY CMP0141) - cmake_policy(SET CMP0141 NEW) - set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$,$>,$<$:EditAndContinue>,$<$:ProgramDatabase>>") -endif() +target_link_libraries(cppjson-Test PRIVATE + cppjson::cppjson +) -project ("Test") +target_sources(cppjson-Test PRIVATE + Test.cpp +) -# Add source to this project's executable. -add_executable (Test "Test.cpp" "Test.h") - -if (CMAKE_VERSION VERSION_GREATER 3.12) - set_property(TARGET Test PROPERTY CXX_STANDARD 23) -endif() - -# TODO: Add tests and install targets if needed. +add_test( + NAME cppjson-Test + COMMAND cppjson-Test + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" +) diff --git a/Test/Test.cpp b/Test/Test.cpp index ed24606..34b0e90 100644 --- a/Test/Test.cpp +++ b/Test/Test.cpp @@ -1,6 +1,3 @@ -#include +#include -int main() -{ - std::println("Hewwo wowld"); -} \ No newline at end of file +int main() { cppjson::hello_world(); } diff --git a/Test/Test.h b/Test/Test.h deleted file mode 100644 index 7c6c88c..0000000 --- a/Test/Test.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once \ No newline at end of file diff --git a/cppjson/CMakeLists.txt b/cppjson/CMakeLists.txt index 0575379..15473eb 100644 --- a/cppjson/CMakeLists.txt +++ b/cppjson/CMakeLists.txt @@ -1,21 +1,17 @@ -# CMakeList.txt : CMake project for cppjson, include source and define -# project specific logic here. -# -cmake_minimum_required (VERSION 3.8) +add_library(cppjson) +add_library(cppjson::cppjson ALIAS cppjson) -# Enable Hot Reload for MSVC compilers if supported. -if (POLICY CMP0141) - cmake_policy(SET CMP0141 NEW) - set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$,$>,$<$:EditAndContinue>,$<$:ProgramDatabase>>") -endif() +target_compile_features(cppjson PUBLIC + cxx_std_23 +) -project ("cppjson") +file(GLOB_RECURSE headers LIST_DIRECTORIES false "include/*.hpp") +target_sources(cppjson PUBLIC FILE_SET HEADERS + BASE_DIRS include + FILES ${headers} +) -# Add source to this project's executable. -add_executable (cppjson "cppjson.cpp" "cppjson.h") - -if (CMAKE_VERSION VERSION_GREATER 3.12) - set_property(TARGET cppjson PROPERTY CXX_STANDARD 23) -endif() - -# TODO: Add tests and install targets if needed. +file(GLOB_RECURSE sources LIST_DIRECTORIES false "src/*.[hc]pp") +target_sources(cppjson PRIVATE + ${sources} +) diff --git a/cppjson/CMakePresets.json b/cppjson/CMakePresets.json deleted file mode 100644 index abf4065..0000000 --- a/cppjson/CMakePresets.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "version": 3, - "configurePresets": [ - { - "name": "windows-base", - "hidden": true, - "generator": "Ninja", - "binaryDir": "${sourceDir}/out/build/${presetName}", - "installDir": "${sourceDir}/out/install/${presetName}", - "cacheVariables": { - "CMAKE_C_COMPILER": "cl.exe", - "CMAKE_CXX_COMPILER": "cl.exe" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - }, - { - "name": "x64-debug", - "displayName": "x64 Debug", - "inherits": "windows-base", - "architecture": { - "value": "x64", - "strategy": "external" - }, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "x64-release", - "displayName": "x64 Release", - "inherits": "x64-debug", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" - } - }, - { - "name": "x86-debug", - "displayName": "x86 Debug", - "inherits": "windows-base", - "architecture": { - "value": "x86", - "strategy": "external" - }, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "x86-release", - "displayName": "x86 Release", - "inherits": "x86-debug", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" - } - } - ] -} diff --git a/cppjson/cppjson.cpp b/cppjson/cppjson.cpp deleted file mode 100644 index 0529d15..0000000 --- a/cppjson/cppjson.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main() -{ - std::println("Hewwo"); - return 0; -} diff --git a/cppjson/cppjson.h b/cppjson/cppjson.h deleted file mode 100644 index 7c6c88c..0000000 --- a/cppjson/cppjson.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once \ No newline at end of file diff --git a/cppjson/include/cppjson/cppjson.hpp b/cppjson/include/cppjson/cppjson.hpp new file mode 100644 index 0000000..2955248 --- /dev/null +++ b/cppjson/include/cppjson/cppjson.hpp @@ -0,0 +1,5 @@ +#pragma once + +namespace cppjson { +void hello_world(); +} // namespace cppjson diff --git a/cppjson/src/cppjson.cpp b/cppjson/src/cppjson.cpp new file mode 100644 index 0000000..e12af32 --- /dev/null +++ b/cppjson/src/cppjson.cpp @@ -0,0 +1,4 @@ +#include +#include + +void cppjson::hello_world() { std::println("Hewwo wowld"); } diff --git a/version.cmake b/version.cmake new file mode 100644 index 0000000..9042652 --- /dev/null +++ b/version.cmake @@ -0,0 +1 @@ +set(cppjson_version "0.1.0")