Skip to content

Commit 9d7187e

Browse files
committed
chore: Lints build system files
1 parent 2e7ddb4 commit 9d7187e

7 files changed

+137
-143
lines changed

gbs/00_utilities.cmake

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#==================================================================================================
66
# Print all variables generated during configuration
77
function(print_cmake_variables)
8-
get_cmake_property(_variable_names VARIABLES)
9-
list (SORT _variable_names)
10-
foreach (_var ${_variable_names})
11-
message(STATUS "${_var}=${${_var}}")
12-
endforeach()
8+
get_cmake_property(variable_names VARIABLES)
9+
list (SORT variable_names)
10+
foreach (var ${variable_names})
11+
message(STATUS "${var}=${${var}}")
12+
endforeach()
1313
endfunction()

gbs/03_compiler_config.cmake

+19-23
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ add_compile_options(-Wall -Wextra -Wpedantic -Werror)
1212
set(THIRD_PARTY_COMPILER_WARNINGS -Wall -Wextra -Wpedantic)
1313

1414
# clang warnings
15-
set(CLANG_WARNINGS -Weverything
16-
-Wno-c++20-compat
17-
-Wno-pre-c++20-compat-pedantic
18-
-Wno-pre-c++17-compat
19-
-Wno-c++98-compat
20-
-Wno-c++98-compat-pedantic
21-
-Wno-unsafe-buffer-usage
22-
-Wno-padded
23-
-Wno-switch-default
15+
set(CLANG_WARNINGS -Weverything
16+
-Wno-c++20-compat
17+
-Wno-pre-c++20-compat-pedantic
18+
-Wno-pre-c++17-compat
19+
-Wno-c++98-compat
20+
-Wno-c++98-compat-pedantic
21+
-Wno-unsafe-buffer-usage
22+
-Wno-padded
23+
-Wno-switch-default
2424
-Wno-ctad-maybe-unsupported
2525
-Wno-global-constructors
2626
-Wno-weak-vtables
@@ -39,15 +39,15 @@ set(GCC_WARNINGS
3939
-Wnull-dereference # warn if a null dereference is detected
4040
-Wdouble-promotion # warn if float is implicit promoted to double
4141
-Wformat=2 # warn on security issues around functions that format output (ie printf)
42-
-Wimplicit-fallthrough # warn on statements that fallthrough without an explicit annotation
42+
-Wimplicit-fallthrough # warn on statements that fallthrough without an explicit annotation
4343
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
4444
-Wduplicated-cond # warn if if / else chain has duplicated conditions
4545
-Wduplicated-branches # warn if if / else branches have duplicated code
4646
-Wlogical-op # warn about logical operations being used where bitwise were probably wanted
4747
-Wuseless-cast # warn if you perform a cast to the same type
48-
-Wconversion
49-
-Wcast-qual
50-
-Wpointer-arith
48+
-Wconversion
49+
-Wcast-qual
50+
-Wpointer-arith
5151
)
5252

5353
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
@@ -88,10 +88,7 @@ endif()
8888
option(ENABLE_MSAN "Enable memory sanitizer" FALSE)
8989
if(${ENABLE_MSAN})
9090
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
91-
message(
92-
WARNING
93-
"Memory sanitizer requires all the code (including libc++) to be MSAN-instrumented otherwise it reports false positives"
94-
)
91+
message(WARNING "Memory sanitizer requires all code (including libc++) to be MSAN-instrumented to avoid false positives")
9592
endif()
9693
if("address" IN_LIST SANITIZERS
9794
OR "thread" IN_LIST SANITIZERS
@@ -131,8 +128,8 @@ endif()
131128
option(ENABLE_CACHE "Enable cache if available" ON)
132129
if(ENABLE_CACHE)
133130
set(CACHE_PROGRAM_OPTIONS "ccache" "sccache")
134-
foreach(CACHE_OPTION IN LISTS CACHE_PROGRAM_OPTIONS)
135-
find_program(CACHE_BIN ${CACHE_OPTION})
131+
foreach(cache_option IN LISTS CACHE_PROGRAM_OPTIONS)
132+
find_program(CACHE_BIN ${cache_option})
136133
if(CACHE_BIN)
137134
set(CMAKE_CXX_COMPILER_LAUNCHER ${CACHE_BIN})
138135
set(CMAKE_C_COMPILER_LAUNCHER ${CACHE_BIN})
@@ -156,14 +153,13 @@ option(ENABLE_LINTER "Enable static analysis" ON)
156153
if(ENABLE_LINTER)
157154
find_program(LINTER_BIN NAMES clang-tidy QUIET)
158155
if(LINTER_BIN)
159-
set(LINTER_ARGS
160-
-extra-arg=-Wno-ignored-optimization-argument
156+
set(LINTER_ARGS
157+
-extra-arg=-Wno-ignored-optimization-argument
161158
-extra-arg=-Wno-unknown-warning-option)
162159
# NOTE: To speed up linting, clang-tidy is invoked via clang-tidy-cache.
163160
# (https://github.com/matus-chochlik/ctcache) Cache location is set by environment variable
164161
# CTCACHE_DIR
165-
set(LINTER_INVOKE_COMMAND
166-
${GBS_TEMPLATES_DIR}/clang-tidy-cache.py ${LINTER_BIN} -p ${CMAKE_BINARY_DIR} ${LINTER_ARGS})
162+
set(LINTER_INVOKE_COMMAND ${GBS_TEMPLATES_DIR}/clang-tidy-cache.py ${LINTER_BIN} -p ${CMAKE_BINARY_DIR} ${LINTER_ARGS})
167163
set(CMAKE_C_CLANG_TIDY ${LINTER_INVOKE_COMMAND})
168164
set(CMAKE_CXX_CLANG_TIDY ${LINTER_INVOKE_COMMAND})
169165
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")

gbs/04_code_formatter.cmake

+26-29
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,53 @@ if(ENABLE_FORMATTER)
1515
endif()
1616
endif()
1717

18-
# Target to format source files
19-
add_custom_target(format)
18+
add_custom_target(format COMMENT "Format source files")
2019

2120
# Function to apply clang formatting on a target
22-
# https://www.linkedin.com/pulse/simple-elegant-wrong-how-integrate-clang-format-friends-brendan-drew
23-
24-
function(add_clang_format _target_name)
21+
function(add_clang_format target_name)
2522
if(CLANG_FORMAT_BIN AND ENABLE_FORMATTER)
26-
if(NOT TARGET ${_target_name})
27-
message(FATAL_ERROR "add_clangformat called on a non-target \"${_target_name}\"")
23+
if(NOT TARGET ${target_name})
24+
message(FATAL_ERROR "add_clangformat called on a non-target \"${target_name}\"")
2825
endif()
2926

3027
# figure out which sources this should be applied to
31-
get_target_property(_clang_sources ${_target_name} SOURCES)
32-
get_target_property(_builddir ${_target_name} BINARY_DIR)
28+
get_target_property(_clang_sources ${target_name} SOURCES)
29+
get_target_property(_builddir ${target_name} BINARY_DIR)
3330

3431
# There are file types we don't want to process (or may be the inverse list is shorter)
35-
set(_supported_file_types ".c" ".cpp" ".h" ".hpp" ".inl")
32+
set(supported_file_types ".c" ".cpp" ".h" ".hpp" ".inl")
3633

37-
set(_sources "")
38-
foreach(_source ${_clang_sources})
39-
if(NOT TARGET ${_source})
40-
get_filename_component(_ext_type ${_source} EXT)
34+
set(sources "")
35+
foreach(source ${_clang_sources})
36+
if(NOT TARGET ${source})
37+
get_filename_component(_ext_type ${source} EXT)
4138
if(NOT ${_ext_type} STREQUAL "")
42-
if(${_ext_type} IN_LIST _supported_file_types)
43-
get_filename_component(_source_file ${_source} NAME)
44-
get_source_file_property(_file_loc "${_source}" LOCATION)
39+
if(${_ext_type} IN_LIST supported_file_types)
40+
get_filename_component(_source_file ${source} NAME)
41+
get_source_file_property(_file_loc "${source}" LOCATION)
4542

4643
math(EXPR counter "${counter}+1")
47-
set(_format_file
48-
.${CMAKE_FILES_DIRECTORY}/${_target_name}_${counter}_${_source_file}.format)
44+
set(format_file
45+
.${CMAKE_FILES_DIRECTORY}/${target_name}_${counter}_${_source_file}.format)
4946
add_custom_command(
50-
OUTPUT ${_format_file}
51-
DEPENDS ${_source}
52-
COMMENT "Format ${_source}"
47+
OUTPUT ${format_file}
48+
DEPENDS ${source}
49+
COMMENT "Format ${source}"
5350
COMMAND ${CLANG_FORMAT_BIN} -style=file -i ${_file_loc}
54-
COMMAND ${CMAKE_COMMAND} -E touch ${_format_file})
55-
list(APPEND _sources ${_format_file})
51+
COMMAND ${CMAKE_COMMAND} -E touch ${format_file})
52+
list(APPEND sources ${format_file})
5653
endif() # in included types list
5754
endif() # extension detected
5855
endif()
5956
endforeach()
6057

61-
if(_sources)
58+
if(sources)
6259
add_custom_target(
63-
${_target_name}_clangformat
64-
SOURCES ${_sources}
60+
${target_name}_clangformat
61+
SOURCES ${sources}
6562
COMMENT "Format target ${_target}")
66-
add_dependencies(${_target_name} ${_target_name}_clangformat)
67-
add_dependencies(format ${_target_name}_clangformat)
63+
add_dependencies(${target_name} ${target_name}_clangformat)
64+
add_dependencies(format ${target_name}_clangformat)
6865
endif()
6966
endif() # CLANG_FORMAT_BIN found
7067
endfunction()

0 commit comments

Comments
 (0)