diff --git a/.clang-format b/.clang-format index 457581e..cf318c0 100644 --- a/.clang-format +++ b/.clang-format @@ -1,8 +1,8 @@ --- BasedOnStyle: Google +AccessModifierOffset: -4 -AccessModifierOffset: -2 AlignTrailingComments: true IndentPPDirectives: AfterHash IndentWidth: 4 @@ -15,11 +15,13 @@ BreakBeforeTernaryOperators: true ColumnLimit: 100 ConstructorInitializerAllOnOneLineOrOnePerLine: true -IncludeBlocks: Regroup +IncludeBlocks: Regroup + SortIncludes: true SpaceBeforeParens: ControlStatements AllowShortFunctionsOnASingleLine: InlineOnly AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false + ... \ No newline at end of file diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml new file mode 100644 index 0000000..10d10d1 --- /dev/null +++ b/.github/workflows/clang-format-check.yml @@ -0,0 +1,31 @@ +name: Clang Format Check + +on: + push: + branches: + - main + pull_request: + branches: + - '**' + +jobs: + clang-format: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y clang-format + + - name: Configure CMake + run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + + - name: Run Clang Format + run: | + find include source -name '*.cpp' -o -name '*.hpp' | xargs clang-format -i + git diff --exit-code || (echo "Clang format check failed! Run clang-format and commit changes."; exit 1) + diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml new file mode 100644 index 0000000..1d398c1 --- /dev/null +++ b/.github/workflows/clang-tidy.yml @@ -0,0 +1,49 @@ +name: Static Analysis Checks + +on: + push: + branches: + - main + pull_request: + branches: + - '**' + +defaults: + run: + working-directory: . + +jobs: + install-deps: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y clang-tidy + + - name: Configure CMake + run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + + + clang-tidy: + needs: install-deps + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Restore Cached Build + uses: actions/cache@v3 + with: + path: build + key: ${{ runner.os }}-build-${{ github.sha }} + + - name: Run Clang Tidy + run: | + clang-tidy source/*.cpp include/*.hpp + + + diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml new file mode 100644 index 0000000..0705669 --- /dev/null +++ b/.github/workflows/cppcheck.yml @@ -0,0 +1,30 @@ +name: CppCheck Analysis + +on: + push: + branches: + - main + pull_request: + branches: + - '**' + +jobs: + cppcheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y cppcheck + + - name: Configure CMake + run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + + - name: Run CppCheck + run: | + cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 source/ include/ + diff --git a/.gitignore b/.gitignore index 0c18535..4cca412 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,18 @@ +# IDEs and editors .idea/ +.vscode/ + +# Build directories build/ + # Prerequisites *.d # Compiled Object files -*.slo -*.lo *.o *.obj +*.slo +*.lo # Precompiled Headers *.gch @@ -23,10 +28,10 @@ build/ *.smod # Compiled Static libraries -*.lai -*.la *.a *.lib +*.lai +*.la # Executables *.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index 81f6226..05fba6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,31 +1,22 @@ -cmake_minimum_required(VERSION 3.10) -project(TelegramBot) +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) + +project(MyProject LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -find_package(Boost REQUIRED COMPONENTS system) -find_package(TgBot REQUIRED) +include(cmake/CPM.cmake) -target_include_directories(include) -file(GLOB SOURCES source/*.cpp) +# ---- Add source files ---- +# Note: globbing sources is considered bad practice as CMake's generators may not detect new files +# automatically. Keep that in mind when changing files, or explicitly mention them here. +file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") +file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp") -add_executable(my_bot ${SOURCES}) +add_library(${PROJECT_NAME} ${headers} ${sources}) -target_link_libraries(my_bot Boost::system TgBot::TgBot) +set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20 OUTPUT_NAME "MyApp") +target_include_directories(${PROJECT_NAME} PUBLIC include) -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - target_compile_options(my_bot PRIVATE - -g - -fsanitize=address,undefined - -fno-omit-frame-pointer - ) - target_link_options(my_bot PRIVATE - -fsanitize=address,undefined - -fno-omit-frame-pointer - ) -endif() \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..34a1f1b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Melnikov Kirill + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 25c0187..db2f725 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,6 @@ git clone git@github.com:EntryPoint-C-project/EntryPoint.git cd EntryPoint # You need to make a telegram-bot token mkdir build && cd build -cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. # Enable clang-tidy support +cmake -G Ninja .. ninja -``` -### 🔹 2. Running clang-tidy -```sh -run-clang-tidy -p build/ -``` \ No newline at end of file +``` \ No newline at end of file diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 0000000..4c61aea --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.40.7) +set(CPM_HASH_SUM "c0fc82149e00c43a21febe7b2ca57b2ffea2b8e88ab867022c21d6b81937eb50") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) \ No newline at end of file