Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit ba4fa56

Browse files
authored
Add build support for clang-tidy and clang build metrics (#3150)
* Add clang-tidy support. Exclude externals. * Add configure option for -ftime-trace.
1 parent 25d3929 commit ba4fa56

File tree

5 files changed

+67
-10
lines changed

5 files changed

+67
-10
lines changed

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# disable everything by default. see src/.clang-tidy.
2+
Checks: -*

CMakeLists.txt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ set(CMAKE_CXX_STANDARD 11)
2626
set(CMAKE_CXX_STANDARD_REQUIRED 1)
2727
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2828

29+
# ##############################################################################
30+
# Set options
31+
32+
option(TC_BUILD_METRICS "Produce clang build metrics" OFF)
33+
2934
# **************************************************************************/
30-
# * */
31-
# * Global Link, Include and Define Flags */
32-
# * */
35+
# * */
36+
# * Global Link, Include and Define Flags */
37+
# * */
3338
# **************************************************************************/
3439

3540
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake")
@@ -111,9 +116,9 @@ add_definitions(-DEIGEN_MPL2_ONLY)
111116
add_definitions(-Dgoogle=_tc_google)
112117

113118
# **************************************************************************/
114-
# * */
115-
# * Adapt Compiler and Linker Flags to the system */
116-
# * */
119+
# * */
120+
# * Adapt Compiler and Linker Flags to the system */
121+
# * */
117122
# **************************************************************************/
118123

119124
include(CompilerFlags)
@@ -148,6 +153,13 @@ check_and_set_compiler_flag(-fpeel-loops RELEASE)
148153
check_and_set_compiler_flag(-funswitch-loops RELEASE)
149154
check_and_set_compiler_flag(-ftracer RELEASE)
150155

156+
if(TC_BUILD_METRICS)
157+
# TC_BUILD_METRICS enables -ftime-trace in supported compilers, which will
158+
# produce a timings json file for each compiled object.
159+
160+
check_and_set_compiler_flag(-ftime-trace)
161+
endif()
162+
151163
if(APPLE)
152164
# This triggers a bug in clang; the 10.13 symbol ___chkstk_darwin is missing
153165
# in 10.13, and the code generated doesn't run on that, even with the 10.12
@@ -291,9 +303,9 @@ set(CMAKE_MODULE_LINKER_FLAGS
291303
)
292304

293305
# **************************************************************************/
294-
# * */
295-
# * Report Final Flags */
296-
# * */
306+
# * */
307+
# * Report Final Flags */
308+
# * */
297309
# **************************************************************************/
298310
message("CMAKE_BUILD_TYPE= ${CMAKE_BUILD_TYPE}.")
299311

configure

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ function print_help {
2929
echo " --with-ccache (default) Use ccache, if available."
3030
echo " --no-ccache "
3131
echo
32+
echo " --with-clang-tidy Run clang-tidy, if available."
33+
echo " --with-clang-metrics Run clang with timing metrics. Requires Clang 9.0."
34+
echo
3235
echo " --with-capi (default) Build C API."
3336
echo " --with-capi-framework Build C API as macOS framework (macOS + XCode builder only)"
3437
echo " --no-capi Skip building the C API."
@@ -70,7 +73,7 @@ function print_help {
7073
echo
7174
echo " --codesign Enable code signing for OSX projects. If enabled, the "
7275
echo " proper CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_**** parameters "
73-
echo denoting the signing variables should be passed in.
76+
echo " denoting the signing variables should be passed in."
7477
echo
7578
echo " --list-source-files If given, a list of all the source files compiled using "
7679
echo " the given options is printed as part of the configuration, "
@@ -142,6 +145,8 @@ default_yes=0
142145
with_python=1
143146
with_pre_commit=1
144147
with_ccache=1
148+
with_clangtidy=0
149+
with_clangmetrics=0
145150

146151
with_capi=1
147152
with_capi_framework=0
@@ -189,6 +194,9 @@ while [ $# -gt 0 ]
189194
--with-ccache) with_ccache=1;;
190195
--no-ccache) with_ccache=0;;
191196

197+
--with-clang-tidy) with_clangtidy=1;;
198+
--with-clang-metrics) with_clangmetrics=1;;
199+
192200
--with-capi) with_capi=1;;
193201
--with-capi-framework) with_capi=1; with_capi_framework=1;;
194202
--no-capi) with_capi=0;;
@@ -341,6 +349,23 @@ CXXCMD=`./scripts/find_compiler.sh cxx --ccache=$with_ccache --script-dir=${PWD}
341349
echo "Setting C compiler to $CCCMD."
342350
echo "Setting C++ compiler to $CXXCMD."
343351

352+
if [[ $with_clangtidy == 1 ]]; then
353+
clangtidy_path=$(which clang-tidy || true)
354+
355+
if [[ ! -x "$clangtidy_path" ]]; then
356+
echo "Unable to find clang-tidy in path."
357+
exit 1
358+
fi
359+
360+
echo "Setting clang-tidy to $clangtidy_path"
361+
362+
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_CXX_CLANG_TIDY=${clangtidy_path}"
363+
fi
364+
365+
if [[ $with_clangmetrics == 1 ]]; then
366+
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DTC_BUILD_METRICS=ON"
367+
fi
368+
344369
echo "======================= FINDING CMAKE ========================"
345370

346371
# Set up the path to CMake

src/.clang-tidy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# currently everything is turned on but everything will fail. when we start to enable rules, it will be one at a time.
2+
#
3+
# Documentation: https://clang.llvm.org/extra/clang-tidy/
4+
# Checks: https://clang.llvm.org/extra/clang-tidy/checks/list.html
5+
#
6+
# Multiline format for rules:
7+
# Checks: "-*,\
8+
# rule,\
9+
# "
10+
#
11+
#
12+
13+
#Checks: *
14+
15+
HeaderFilterRegex: 'src/*\.(h|hpp)$'
16+
WarningsAsErrors: '*'

src/external/.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# disable everything in externals.
2+
Checks: -*

0 commit comments

Comments
 (0)