Skip to content
Merged
21 changes: 21 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
Checks: >
bugprone-*,
cert-dcl37-c,
cert-dcl51-cpp,
performance-*,
-bugprone-easily-swappable-parameters,
-bugprone-narrowing-conversions,
-bugprone-signed-char-misuse,
-bugprone-unhandled-self-assignment,
-bugprone-macro-parentheses,
-performance-avoid-endl,
modernize-use-nullptr,
readability-redundant-control-flow

CheckOptions:
- key: performance-unnecessary-value-param.AllowedTypes
value: 'std::shared_ptr;std::unique_ptr'

HeaderFilterRegex: '.*'
FormatStyle: file
51 changes: 51 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ target_include_directories(
fork_union INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>
)

# Strict compilation flags
target_compile_options(
fork_union INTERFACE
$<$<CXX_COMPILER_ID:GNU,Clang>:-Wall -Wextra -Wpedantic -Wconversion -Wcast-qual -Wcast-align -Wunused -Wno-unused-parameter -Wno-unknown-pragmas -Wno-sign-conversion -Wno-unused-function>
$<$<CXX_COMPILER_ID:MSVC>:/W4 /permissive->
)

# Pre-compiled libraries built from `c/lib.cpp`
add_library(fork_union_dynamic SHARED c/lib.cpp)
add_library(fork_union_static STATIC c/lib.cpp)
Expand All @@ -42,6 +49,50 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR})

# Static analysis tools
find_program(CPPCHECK_EXECUTABLE cppcheck)
if(CPPCHECK_EXECUTABLE)
add_custom_target(
cppcheck
COMMAND ${CPPCHECK_EXECUTABLE}
--enable=all
--std=c++17
--verbose
--quiet
--error-exitcode=1
--suppress=missingIncludeSystem
--suppress=unusedFunction
--suppress=unmatchedSuppression
--suppress=ConfigurationNotChecked
--suppress=knownConditionTrueFalse
--suppress=shadowFunction
--suppress=shadowVariable
--suppress=useStlAlgorithm
--suppress=noExplicitConstructor
-I${CMAKE_CURRENT_SOURCE_DIR}/include
-DFU_ENABLE_NUMA=1
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/c
COMMENT "Running cppcheck static analysis"
)
endif()

find_program(CLANG_TIDY_EXECUTABLE clang-tidy)
if(CLANG_TIDY_EXECUTABLE)
add_custom_target(
clang-tidy
COMMAND ${CLANG_TIDY_EXECUTABLE}
--config-file=${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy
--quiet
${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/c/*.cpp
--
-I${CMAKE_CURRENT_SOURCE_DIR}/include
-std=c++17
COMMENT "Running clang-tidy static analysis"
)
endif()

# Tests & benchmarking scripts
include(CTest)
if (BUILD_TESTING)
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,17 @@ build_release/fork_union_nbody # run the benchmarks
For C++ debug builds, consider using the VS Code debugger presets or the following commands:

```bash
cmake --build build_debug --config Debug # build with Debug symbols
build_debug/fork_union_test_cpp20 # run a single test executable
cmake -B build_debug -D CMAKE_BUILD_TYPE=Debug
cmake --build build_debug --config Debug # build with Debug symbols
build_debug/fork_union_test_cpp20 # run a single test executable
```

To run static analysis:

```bash
sudo apt install cppcheck clang-tidy
cmake --build build_debug --target cppcheck # detects bugs & undefined behavior
cmake --build build_debug --target clang-tidy # suggest code improvements
```

To include NUMA, Huge Pages, and other optimizations on Linux, make sure to install dependencies:
Expand Down
4 changes: 2 additions & 2 deletions include/fork_union.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@
* @see https://en.cppreference.com/w/c/language/arithmetic_types
*/
#pragma once
#include <stddef.h> // `size_t`, `bool`

#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h> // `size_t`, `bool`

int fu_version_major(void); // ? Returns the major version of the Fork Union library
int fu_version_minor(void); // ? Returns the minor version of the Fork Union library
int fu_version_patch(void); // ? Returns the patch version of the Fork Union library
Expand Down
Loading