Skip to content

Commit 6e31855

Browse files
committed
build: work-in-progress clang-tidy config
1 parent 76e6680 commit 6e31855

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

.clang-tidy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Checks: >
2+
bugprone-*,
3+
concurrency-*,
4+
cppcoreguidelines-*,
5+
-cppcoreguidelines-avoid-c-arrays,
6+
-cppcoreguidelines-avoid-const-or-ref-data-members,
7+
-cppcoreguidelines-avoid-magic-numbers,
8+
-cppcoreguidelines-avoid-non-const-global-variables,
9+
-cppcoreguidelines-non-private-member-variables-in-classes,
10+
-cppcoreguidelines-pro-*,
11+
misc-*,
12+
-misc-no-recursion,
13+
-misc-non-private-member-variables-in-classes,
14+
modernize-*,
15+
-modernize-avoid-c-arrays,
16+
-modernize-macro-to-enum,
17+
-modernize-use-trailing-return-type,
18+
performance-*,
19+
portability-*,
20+
readibility-*
21+
CheckOptions:
22+
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
23+
value: true
24+
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions
25+
value: true
26+
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted
27+
value: true

CMakeLists.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
3636

3737
option(ENTT_USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if available." OFF)
3838
option(ENTT_USE_SANITIZER "Enable sanitizers by adding -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined flags if available." OFF)
39+
option(ENTT_USE_CLANG_TIDY "Enable static analysis with clang-tidy" OFF)
3940

4041
if(ENTT_USE_LIBCPP)
4142
if(NOT WIN32)
@@ -55,7 +56,7 @@ if(ENTT_USE_LIBCPP)
5556
endif()
5657

5758
if(NOT ENTT_HAS_LIBCPP)
58-
message(VERBOSE "The option ENTT_USE_LIBCPP is set but libc++ is not available. The flag will not be added to the target.")
59+
message(VERBOSE "The option ENTT_USE_LIBCPP is set but libc++ is not available.")
5960
endif()
6061
endif()
6162

@@ -66,7 +67,15 @@ if(ENTT_USE_SANITIZER)
6667
endif()
6768

6869
if(NOT ENTT_HAS_SANITIZER)
69-
message(VERBOSE "The option ENTT_USE_SANITIZER is set but sanitizer support is not available. The flags will not be added to the target.")
70+
message(VERBOSE "The option ENTT_USE_SANITIZER is set but sanitizer support is not available.")
71+
endif()
72+
endif()
73+
74+
if(ENTT_USE_CLANG_TIDY)
75+
find_program(ENTT_CLANG_TIDY_EXECUTABLE "clang-tidy")
76+
77+
if(NOT ENTT_CLANG_TIDY_EXECUTABLE)
78+
message(VERBOSE "The option ENTT_USE_CLANG_TIDY is set but clang-tidy executable is not available.")
7079
endif()
7180
endif()
7281

@@ -204,6 +213,10 @@ if(ENTT_HAS_SANITIZER)
204213
target_link_libraries(EnTT INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined>)
205214
endif()
206215

216+
if(ENTT_CLANG_TIDY_EXECUTABLE)
217+
set(CMAKE_CXX_CLANG_TIDY "${ENTT_CLANG_TIDY_EXECUTABLE};--config-file=${EnTT_SOURCE_DIR}/.clang-tidy;--header-filter=${EnTT_SOURCE_DIR}/src/entt/.*;--extra-arg=/EHsc")
218+
endif()
219+
207220
if(ENTT_HAS_LIBCPP)
208221
target_compile_options(EnTT BEFORE INTERFACE -stdlib=libc++)
209222
endif()

test/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,16 @@ else()
3232
add_library(GTest::Main ALIAS gtest_main)
3333

3434
target_compile_features(gtest PUBLIC cxx_std_17)
35+
set_target_properties(gtest PROPERTIES CXX_CLANG_TIDY "")
36+
3537
target_compile_features(gtest_main PUBLIC cxx_std_17)
38+
set_target_properties(gtest_main PROPERTIES CXX_CLANG_TIDY "")
39+
3640
target_compile_features(gmock PUBLIC cxx_std_17)
41+
set_target_properties(gmock PROPERTIES CXX_CLANG_TIDY "")
42+
3743
target_compile_features(gmock_main PUBLIC cxx_std_17)
44+
set_target_properties(gmock_main PROPERTIES CXX_CLANG_TIDY "")
3845
endif()
3946

4047
include_directories($<TARGET_PROPERTY:EnTT,INTERFACE_INCLUDE_DIRECTORIES>)
@@ -121,6 +128,7 @@ function(SETUP_LIB_SHARED_TEST TEST_NAME SUB_PATH)
121128
add_library(_${TARGET_NAME} SHARED $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/${SUB_PATH}/lib.cpp)
122129
SETUP_TARGET(_${TARGET_NAME} ENTT_API_EXPORT)
123130
SETUP_BASIC_TEST(lib_${TARGET_NAME} lib/${TEST_NAME}/${SUB_PATH}/main.cpp ENTT_API_IMPORT)
131+
set_target_properties(lib_${TARGET_NAME} PROPERTIES CXX_CLANG_TIDY "")
124132
target_link_libraries(lib_${TARGET_NAME} PRIVATE _${TARGET_NAME})
125133
endfunction()
126134

@@ -129,6 +137,8 @@ function(SETUP_LIB_PLUGIN_TEST TEST_NAME SUB_PATH)
129137
add_library(_${TARGET_NAME} MODULE $<TARGET_OBJECTS:odr> lib/${TEST_NAME}/${SUB_PATH}/plugin.cpp)
130138
SETUP_TARGET(_${TARGET_NAME} ${ARGVN})
131139
SETUP_BASIC_TEST(lib_${TARGET_NAME} lib/${TEST_NAME}/${SUB_PATH}/main.cpp PLUGIN="$<TARGET_FILE:_${TARGET_NAME}>" ${ARGVN})
140+
set_target_properties(_${TARGET_NAME} PROPERTIES CXX_CLANG_TIDY "")
141+
set_target_properties(lib_${TARGET_NAME} PROPERTIES CXX_CLANG_TIDY "")
132142
target_include_directories(_${TARGET_NAME} PRIVATE ${cr_INCLUDE_DIR})
133143
target_include_directories(lib_${TARGET_NAME} PRIVATE ${cr_INCLUDE_DIR})
134144
target_link_libraries(lib_${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS})
@@ -139,6 +149,7 @@ endfunction()
139149

140150
if(ENTT_BUILD_BENCHMARK)
141151
SETUP_BASIC_TEST(benchmark benchmark/benchmark.cpp)
152+
set_target_properties(benchmark PROPERTIES CXX_CLANG_TIDY "")
142153
endif()
143154

144155
# Test example
@@ -202,6 +213,8 @@ if(ENTT_BUILD_SNAPSHOT)
202213
endif()
203214

204215
SETUP_BASIC_TEST(cereal snapshot/snapshot.cpp)
216+
217+
set_target_properties(cereal PROPERTIES CXX_CLANG_TIDY "")
205218
target_include_directories(cereal PRIVATE ${cereal_INCLUDE_DIR})
206219
endif()
207220

0 commit comments

Comments
 (0)