Skip to content

Commit

Permalink
Merge pull request #34 from tritonuas/chore/clang-tidy-linter
Browse files Browse the repository at this point in the history
clang tidy linter
  • Loading branch information
Tyler-Lentz authored Oct 19, 2023
2 parents e9f0a08 + d4088ca commit c8ee0c3
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 29 deletions.
15 changes: 15 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
Checks: >
*,
-altera-struct-pack-align,
-fuchsia-*,
-google-*,
-zircon-*,
-abseil-*,
-modernize-use-trailing-return-type,
-llvm-*,
-llvmlibc-*,
CheckOptions: [{ key: misc-non-private-member-variables-in-classes, value: IgnoreClassesWithAllMemberVariablesBeingPublic }]
WarningsAsErrors: '*'
HeaderFilterRegex: ''
FormatStyle: none
34 changes: 34 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Lint

on:
push:
branches:
- main
pull_request:

jobs:
test:
name: clang-tidy
runs-on: ubuntu-latest

steps:
- name: Install CMake
run: sudo apt install cmake

- name: Checkout Repo
uses: actions/checkout@v2
with:
submodules: true
token: ${{ secrets.SSH_TOKEN }}

- name: Create build dir
run: mkdir build

- name: Set up Cmake
run: cd build && cmake ..

- name: Run clang-tidy
run: cd build && make lint



9 changes: 6 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Install Cmake
- name: Install CMake
run: sudo apt install cmake

- name: Checkout Repo
Expand All @@ -21,11 +21,14 @@ jobs:
submodules: true
token: ${{ secrets.SSH_TOKEN }}

- name: Create build dir
run: mkdir build

- name: Set up Cmake
run: cmake .
run: cd build && cmake ..

- name: Run tests
run: make test
run: cd build && make test



59 changes: 34 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,57 @@
cmake_minimum_required(VERSION 3.10)

set(CMAKE_CXX_COMPILER g++)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ./bin)

cmake_minimum_required(VERSION 3.10)

project(obcpp VERSION 1.0)

# =============================
# Libraries
add_library(core_library SHARED
src/core/states.cpp
)
add_library(core::library ALIAS core_library)
target_include_directories(core_library
PUBLIC
${PROJECT_SOURCE_DIR}/include
)

add_subdirectory(deps/json)
# =============================
file(GLOB_RECURSE SOURCES "src/*.cpp")
file(GLOB_RECURSE HEADERS "include/*.hpp")

# =============================
# Executable
set(INCLUDE_DIRECTORY ${PROJECT_SOURCE_DIR}/include)
include_directories(${INCLUDE_DIRECTORY})
add_executable(${PROJECT_NAME} ${SOURCES})
# =============================

add_executable(obcpp
src/main.cpp
)

target_link_libraries(obcpp
# =============================
# Libraries
# NOTE: add each library's include directory to clang-tidy in the Linting section
add_subdirectory(deps/json)
target_link_libraries(${PROJECT_NAME}
PRIVATE
core::library
nlohmann_json::nlohmann_json
nlohmann_json::nlohmann_json
)

# =============================


# =============================
# Unit tests

add_subdirectory(tests)
add_subdirectory(deps/google-test)
# =============================

# =============================
# Json Library
# Linting
# Adding lint target if clang-tidy executable is found
find_program(CLANG_TIDY "clang-tidy")
if(CLANG_TIDY)
# define lint target
add_custom_target(lint
COMMAND ${CLANG_TIDY}
${SOURCES}
${HEADERS}
--
-std=c++${CMAKE_CXX_STANDARD}
-I${INCLUDE_DIRECTORY}
# NOTE: need to add include directory for every library
-I./_deps/json-src/include/
)
else()
message(FATAL_ERROR "clang-tidy executable not found. Check the README for steps to install it on your system")
endif()
# =============================
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ RUN apt-get update \
&& apt-get install -y build-essential \
gdb \
git \
cmake
cmake \
clang-tidy
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pkgs.mkShell {
buildInputs = [
pkgs.gcc
pkgs.cmake
pkgs.libclang
];
}

0 comments on commit c8ee0c3

Please sign in to comment.