Skip to content

Commit 8ad386e

Browse files
committed
feat(clang-tidy): Add warnings into errors for cmake command. Add naming conventions.
1 parent df07224 commit 8ad386e

File tree

2 files changed

+140
-131
lines changed

2 files changed

+140
-131
lines changed

.clang-tidy

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ CheckOptions:
1717
cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU'
1818
cert-dcl51-cpp.AggressiveDependentMemberLookup: 'false'
1919
readability-identifier-naming.GetConfigPerFile: 'true'
20-
cert-err61-cpp.MaxSize: '-1'
20+
cert-err61-cpp.MaxSize: '10'
2121
cert-sig30-c.AsyncSafeFunctionSet: POSIX
2222
readability-inconsistent-declaration-parameter-name.Strict: 'false'
2323
cppcoreguidelines-macro-usage.CheckCapsOnly: 'false'
@@ -45,7 +45,7 @@ CheckOptions:
4545
readability-suspicious-call-argument.JaroWinklerDissimilarBelow: '75'
4646
readability-suspicious-call-argument.SuffixSimilarAbove: '30'
4747
readability-suspicious-call-argument.Suffix: 'true'
48-
cert-err09-cpp.MaxSize: '-1'
48+
cert-err09-cpp.MaxSize: '10'
4949
cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion: 'true'
5050
cppcoreguidelines-prefer-member-initializer.UseAssignment: 'false'
5151
cert-oop57-cpp.MemSetNames: ''
@@ -156,5 +156,14 @@ CheckOptions:
156156
cert-dcl16-c.IgnoreMacros: 'true'
157157
llvm-else-after-return.WarnOnUnfixable: 'false'
158158
cert-msc32-c.DisallowedSeedTypes: 'time_t,std::time_t'
159+
readability-identifier-naming.NamespaceCase: 'CamelCase'
160+
readability-identifier-naming.UnionCase: 'CamelCase'
161+
readability-identifier-naming.ClassCase: 'CamelCase'
162+
readability-identifier-naming.ClassMemberCase: 'lower_case'
163+
readability-identifier-naming.ClassMethodCase: 'lower_case'
164+
readability-identifier-naming.StructCase: 'CamelCase'
165+
readability-identifier-naming.MemberCase: 'lower_case'
166+
readability-identifier-naming.MethodCase: 'lower_case'
167+
readability-identifier-naming.FunctionCase: 'lower_case'
159168
...
160169

CMakeLists.txt

Lines changed: 129 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,129 @@
1-
cmake_minimum_required(VERSION 3.16)
2-
3-
# Keep this on one line for release checking
4-
project(dbc VERSION 0.2.0 DESCRIPTION "C++ DBC Parser")
5-
6-
# -- PROJECT OPTIONS -- #
7-
option(DBC_ENABLE_TESTS "Enable Unittests" ON)
8-
option(DBC_TEST_LOCALE_INDEPENDENCE "Used to deterime if the libary is locale agnostic when it comes to converting floats. You need `de_DE.UTF-8` locale installed for this testing." OFF)
9-
option(DBC_GENERATE_DOCS "Use doxygen if installed to generated documentation files" OFF)
10-
option(DBC_GENERATE_SINGLE_HEADER "This will run the generator for the single header file version. Default is OFF since we make a static build. Requires cargo installed." OFF)
11-
# ---------------------- #
12-
13-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
14-
15-
# package
16-
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
17-
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
18-
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
19-
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
20-
set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
21-
include(CPack)
22-
23-
# specify the C++ standard
24-
set(CMAKE_CXX_STANDARD 11)
25-
set(CMAKE_CXX_STANDARD_REQUIRED True)
26-
27-
find_package(FastFloat QUIET)
28-
if (NOT ${FastFloat_FOUND})
29-
include(FetchContent)
30-
FetchContent_Declare(
31-
FastFloat
32-
GIT_REPOSITORY https://github.com/fastfloat/fast_float.git
33-
GIT_TAG 1ea4f27b2aeee2859a1354a3c24cff52a116cad1
34-
)
35-
FetchContent_MakeAvailable(FastFloat)
36-
endif()
37-
38-
# add where to find the source files
39-
list(APPEND SOURCE_FILES
40-
${PROJECT_SOURCE_DIR}/src/utils.cpp
41-
${PROJECT_SOURCE_DIR}/src/message.cpp
42-
${PROJECT_SOURCE_DIR}/src/signal.cpp
43-
${PROJECT_SOURCE_DIR}/src/dbc.cpp
44-
)
45-
46-
list(APPEND HEADER_FILES
47-
${PROJECT_SOURCE_DIR}/include/libdbc/dbc.hpp
48-
${PROJECT_SOURCE_DIR}/include/libdbc/message.hpp
49-
${PROJECT_SOURCE_DIR}/include/libdbc/signal.hpp
50-
${PROJECT_SOURCE_DIR}/include/libdbc/utils/utils.hpp
51-
${PROJECT_SOURCE_DIR}/include/libdbc/exceptions/error.hpp
52-
)
53-
54-
if(DBC_ENABLE_TESTS)
55-
include(CTest)
56-
add_subdirectory(test)
57-
endif()
58-
59-
if(DBC_GENERATE_DOCS)
60-
add_subdirectory(doc)
61-
endif()
62-
63-
list(APPEND GCC_CLANG_COMPILE_FLAGS
64-
-Wall -Wextra -Wpedantic
65-
-Wconversion -Wint-in-bool-context
66-
-Wmissing-declarations -Wmissing-field-initializers
67-
-Werror
68-
)
69-
70-
71-
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
72-
add_compile_options(/W4 /WX)
73-
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
74-
# Clang shadow warnings aren't as sensitive as gcc
75-
add_compile_options(${GCC_CLANG_COMPILE_FLAGS} -Wshadow)
76-
else()
77-
add_compile_options(${GCC_CLANG_COMPILE_FLAGS})
78-
endif()
79-
80-
add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})
81-
target_link_libraries(${PROJECT_NAME} FastFloat::fast_float)
82-
target_include_directories(${PROJECT_NAME} PUBLIC
83-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
84-
$<INSTALL_INTERFACE:include>
85-
)
86-
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
87-
88-
target_sources(${PROJECT_NAME} INTERFACE FILE_SET HEADERS
89-
TYPE HEADERS
90-
BASE_DIRS ${PROJECT_SOURCE_DIR}/include/libdbc
91-
FILES ${HEADER_FILES}
92-
)
93-
94-
if(DBC_GENERATE_SINGLE_HEADER)
95-
add_custom_target(single_header ALL
96-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
97-
COMMAND ${CMAKE_SOURCE_DIR}/scripts/create_single_header.sh
98-
)
99-
endif()
100-
101-
## Installation
102-
# install lib
103-
install(TARGETS ${PROJECT_NAME}
104-
DESTINATION ${CMAKE_INSTALL_LIBDIR})
105-
106-
# install headers
107-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/libdbc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
108-
109-
# Generate pkg-config file
110-
configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
111-
install(
112-
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
113-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
114-
115-
# Clang tidy
116-
add_custom_target(clang-tidy-check
117-
clang-tidy -p ${CMAKE_BINARY_DIR}/compile_commands.json ${SOURCE_FILES} ${HEADER_FILES}
118-
DEPENDS ${SOURCE_FILES} ${HEADER_FILES}
119-
)
120-
121-
add_custom_target(clang-tidy-dump
122-
clang-tidy -checks=-*,clang-analyzer-*,clang-analyzer-cplusplus*,cert-*,cppcoreguidelines-*,portability-*,readability-*,clang-diagnostic-* -dump-config -p ${CMAKE_BINARY_DIR}/compile_commands.json ${SOURCE_FILES} ${HEADER_FILES} > ../.clang-tidy
123-
DEPENDS ${SOURCE_FILES} ${HEADER_FILES}
124-
)
125-
126-
add_custom_target(clang-tidy-fix
127-
clang-tidy -fix-notes -p ${CMAKE_BINARY_DIR}/compile_commands.json ${SOURCE_FILES} ${HEADER_FILES}
128-
DEPENDS ${SOURCE_FILES} ${HEADER_FILES}
129-
)
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
# Keep this on one line for release checking
4+
project(dbc VERSION 0.2.0 DESCRIPTION "C++ DBC Parser")
5+
6+
# -- PROJECT OPTIONS -- #
7+
option(DBC_ENABLE_TESTS "Enable Unittests" ON)
8+
option(DBC_TEST_LOCALE_INDEPENDENCE "Used to deterime if the libary is locale agnostic when it comes to converting floats. You need `de_DE.UTF-8` locale installed for this testing." OFF)
9+
option(DBC_GENERATE_DOCS "Use doxygen if installed to generated documentation files" OFF)
10+
option(DBC_GENERATE_SINGLE_HEADER "This will run the generator for the single header file version. Default is OFF since we make a static build. Requires cargo installed." OFF)
11+
# ---------------------- #
12+
13+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
14+
15+
# package
16+
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
17+
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
18+
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
19+
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
20+
set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
21+
include(CPack)
22+
23+
# specify the C++ standard
24+
set(CMAKE_CXX_STANDARD 11)
25+
set(CMAKE_CXX_STANDARD_REQUIRED True)
26+
27+
find_package(FastFloat QUIET)
28+
if (NOT ${FastFloat_FOUND})
29+
include(FetchContent)
30+
FetchContent_Declare(
31+
FastFloat
32+
GIT_REPOSITORY https://github.com/fastfloat/fast_float.git
33+
GIT_TAG 1ea4f27b2aeee2859a1354a3c24cff52a116cad1
34+
)
35+
FetchContent_MakeAvailable(FastFloat)
36+
endif()
37+
38+
# add where to find the source files
39+
list(APPEND SOURCE_FILES
40+
${PROJECT_SOURCE_DIR}/src/utils.cpp
41+
${PROJECT_SOURCE_DIR}/src/message.cpp
42+
${PROJECT_SOURCE_DIR}/src/signal.cpp
43+
${PROJECT_SOURCE_DIR}/src/dbc.cpp
44+
)
45+
46+
list(APPEND HEADER_FILES
47+
${PROJECT_SOURCE_DIR}/include/libdbc/dbc.hpp
48+
${PROJECT_SOURCE_DIR}/include/libdbc/message.hpp
49+
${PROJECT_SOURCE_DIR}/include/libdbc/signal.hpp
50+
${PROJECT_SOURCE_DIR}/include/libdbc/utils/utils.hpp
51+
${PROJECT_SOURCE_DIR}/include/libdbc/exceptions/error.hpp
52+
)
53+
54+
if(DBC_ENABLE_TESTS)
55+
include(CTest)
56+
add_subdirectory(test)
57+
endif()
58+
59+
if(DBC_GENERATE_DOCS)
60+
add_subdirectory(doc)
61+
endif()
62+
63+
list(APPEND GCC_CLANG_COMPILE_FLAGS
64+
-Wall -Wextra -Wpedantic
65+
-Wconversion -Wint-in-bool-context
66+
-Wmissing-declarations -Wmissing-field-initializers
67+
-Werror
68+
)
69+
70+
71+
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
72+
add_compile_options(/W4 /WX)
73+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
74+
# Clang shadow warnings aren't as sensitive as gcc
75+
add_compile_options(${GCC_CLANG_COMPILE_FLAGS} -Wshadow)
76+
else()
77+
add_compile_options(${GCC_CLANG_COMPILE_FLAGS})
78+
endif()
79+
80+
add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})
81+
target_link_libraries(${PROJECT_NAME} FastFloat::fast_float)
82+
target_include_directories(${PROJECT_NAME} PUBLIC
83+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
84+
$<INSTALL_INTERFACE:include>
85+
)
86+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
87+
88+
target_sources(${PROJECT_NAME} INTERFACE FILE_SET HEADERS
89+
TYPE HEADERS
90+
BASE_DIRS ${PROJECT_SOURCE_DIR}/include/libdbc
91+
FILES ${HEADER_FILES}
92+
)
93+
94+
if(DBC_GENERATE_SINGLE_HEADER)
95+
add_custom_target(single_header ALL
96+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
97+
COMMAND ${CMAKE_SOURCE_DIR}/scripts/create_single_header.sh
98+
)
99+
endif()
100+
101+
## Installation
102+
# install lib
103+
install(TARGETS ${PROJECT_NAME}
104+
DESTINATION ${CMAKE_INSTALL_LIBDIR})
105+
106+
# install headers
107+
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/libdbc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
108+
109+
# Generate pkg-config file
110+
configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
111+
install(
112+
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
113+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
114+
115+
# Clang tidy
116+
add_custom_target(clang-tidy-check
117+
clang-tidy -p ${CMAKE_BINARY_DIR}/compile_commands.json -warnings-as-errors=* ${SOURCE_FILES} ${HEADER_FILES}
118+
DEPENDS ${SOURCE_FILES} ${HEADER_FILES}
119+
)
120+
121+
add_custom_target(clang-tidy-dump
122+
clang-tidy -checks=-*,clang-analyzer-*,clang-analyzer-cplusplus*,cert-*,cppcoreguidelines-*,portability-*,readability-*,clang-diagnostic-* -dump-config -p ${CMAKE_BINARY_DIR}/compile_commands.json ${SOURCE_FILES} ${HEADER_FILES} > ../.clang-tidy
123+
DEPENDS ${SOURCE_FILES} ${HEADER_FILES}
124+
)
125+
126+
add_custom_target(clang-tidy-fix
127+
clang-tidy -fix-notes -p ${CMAKE_BINARY_DIR}/compile_commands.json ${SOURCE_FILES} ${HEADER_FILES}
128+
DEPENDS ${SOURCE_FILES} ${HEADER_FILES}
129+
)

0 commit comments

Comments
 (0)