Skip to content
Permalink
Browse files
Add build support for clang-tidy and clang build metrics (#3150)
* Add clang-tidy support. Exclude externals.
* Add configure option for -ftime-trace.
  • Loading branch information
brtal committed Apr 29, 2020
1 parent 25d3929 commit ba4fa56
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 10 deletions.
@@ -0,0 +1,2 @@
# disable everything by default. see src/.clang-tidy.
Checks: -*
@@ -26,10 +26,15 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED 1)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# ##############################################################################
# Set options

option(TC_BUILD_METRICS "Produce clang build metrics" OFF)

# **************************************************************************/
# * */
# * Global Link, Include and Define Flags */
# * */
# * */
# * Global Link, Include and Define Flags */
# * */
# **************************************************************************/

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

# **************************************************************************/
# * */
# * Adapt Compiler and Linker Flags to the system */
# * */
# * */
# * Adapt Compiler and Linker Flags to the system */
# * */
# **************************************************************************/

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

if(TC_BUILD_METRICS)
# TC_BUILD_METRICS enables -ftime-trace in supported compilers, which will
# produce a timings json file for each compiled object.

check_and_set_compiler_flag(-ftime-trace)
endif()

if(APPLE)
# This triggers a bug in clang; the 10.13 symbol ___chkstk_darwin is missing
# 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
)

# **************************************************************************/
# * */
# * Report Final Flags */
# * */
# * */
# * Report Final Flags */
# * */
# **************************************************************************/
message("CMAKE_BUILD_TYPE= ${CMAKE_BUILD_TYPE}.")

@@ -29,6 +29,9 @@ function print_help {
echo " --with-ccache (default) Use ccache, if available."
echo " --no-ccache "
echo
echo " --with-clang-tidy Run clang-tidy, if available."
echo " --with-clang-metrics Run clang with timing metrics. Requires Clang 9.0."
echo
echo " --with-capi (default) Build C API."
echo " --with-capi-framework Build C API as macOS framework (macOS + XCode builder only)"
echo " --no-capi Skip building the C API."
@@ -70,7 +73,7 @@ function print_help {
echo
echo " --codesign Enable code signing for OSX projects. If enabled, the "
echo " proper CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_**** parameters "
echo denoting the signing variables should be passed in.
echo " denoting the signing variables should be passed in."
echo
echo " --list-source-files If given, a list of all the source files compiled using "
echo " the given options is printed as part of the configuration, "
@@ -142,6 +145,8 @@ default_yes=0
with_python=1
with_pre_commit=1
with_ccache=1
with_clangtidy=0
with_clangmetrics=0

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

--with-clang-tidy) with_clangtidy=1;;
--with-clang-metrics) with_clangmetrics=1;;

--with-capi) with_capi=1;;
--with-capi-framework) with_capi=1; with_capi_framework=1;;
--no-capi) with_capi=0;;
@@ -341,6 +349,23 @@ CXXCMD=`./scripts/find_compiler.sh cxx --ccache=$with_ccache --script-dir=${PWD}
echo "Setting C compiler to $CCCMD."
echo "Setting C++ compiler to $CXXCMD."

if [[ $with_clangtidy == 1 ]]; then
clangtidy_path=$(which clang-tidy || true)

if [[ ! -x "$clangtidy_path" ]]; then
echo "Unable to find clang-tidy in path."
exit 1
fi

echo "Setting clang-tidy to $clangtidy_path"

CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_CXX_CLANG_TIDY=${clangtidy_path}"
fi

if [[ $with_clangmetrics == 1 ]]; then
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DTC_BUILD_METRICS=ON"
fi

echo "======================= FINDING CMAKE ========================"

# Set up the path to CMake
@@ -0,0 +1,16 @@
# currently everything is turned on but everything will fail. when we start to enable rules, it will be one at a time.
#
# Documentation: https://clang.llvm.org/extra/clang-tidy/
# Checks: https://clang.llvm.org/extra/clang-tidy/checks/list.html
#
# Multiline format for rules:
# Checks: "-*,\
# rule,\
# "
#
#

#Checks: *

HeaderFilterRegex: 'src/*\.(h|hpp)$'
WarningsAsErrors: '*'
@@ -0,0 +1,2 @@
# disable everything in externals.
Checks: -*

0 comments on commit ba4fa56

Please sign in to comment.