Skip to content

Commit 7744772

Browse files
committed
add gersemi to pre-commit hooks for CMake formatting like black
1 parent d0dd282 commit 7744772

File tree

7 files changed

+103
-92
lines changed

7 files changed

+103
-92
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ repos:
3333
- id: codespell
3434
additional_dependencies: [tomli]
3535

36+
- repo: https://github.com/BlankSpruce/gersemi
37+
rev: 0.18.2
38+
hooks:
39+
- id: gersemi
40+
args: ["-i", "--no-warn-about-unknown-commands", "-l", "120"]
41+
3642
- repo: local
3743
hooks:
3844
- id: copyright-headers

cmake/GodotCPPModule.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function( generate_doc_source OUTPUT_PATH SOURCES )
137137
VERBATIM
138138
WORKING_DIRECTORY "${godot-cpp_SOURCE_DIR}"
139139
DEPENDS
140+
DEPENDS #
140141
"${godot-cpp_SOURCE_DIR}/doc_source_generator.py"
141142
"${SOURCES}"
142143
COMMENT "Generating: ${OUTPUT_PATH}"

cmake/common_compiler_flags.cmake

Lines changed: 71 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,14 @@ endfunction( )
4646

4747
function( common_compiler_flags )
4848

49-
target_compile_features(${TARGET_NAME}
50-
PUBLIC
51-
cxx_std_17
52-
)
53-
49+
# gersemi: off
5450
# These compiler options reflect what is in godot/SConstruct.
55-
target_compile_options( ${TARGET_NAME}
51+
target_compile_options(
52+
${TARGET_NAME}
5653
PUBLIC
5754
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
5855
# saves around 20% of binary size and very significant build time.
59-
$<${DISABLE_EXCEPTIONS}:
60-
$<${NOT_MSVC}:-fno-exceptions>
61-
>
56+
$<${DISABLE_EXCEPTIONS}:$<${NOT_MSVC}:-fno-exceptions>>
6257

6358
# Enabling Debug Symbols
6459
$<${DEBUG_SYMBOLS}:
@@ -70,78 +65,75 @@ function( common_compiler_flags )
7065
>
7166
>
7267

73-
$<${IS_DEV_BUILD}:
74-
$<${NOT_MSVC}:-fno-omit-frame-pointer -O0>
68+
$<${IS_DEV_BUILD}:$<${NOT_MSVC}:-fno-omit-frame-pointer -O0>>
69+
70+
$<${HOT_RELOAD}:$<${IS_GNU}:-fno-gnu-unique>>
71+
72+
# MSVC only
73+
$<${IS_MSVC}:
74+
# /MP isn't valid for clang-cl with msvc frontend
75+
$<$<CXX_COMPILER_ID:MSVC>:/MP${PROC_N}>
76+
/W4
77+
78+
# Disable warnings which we don't plan to fix.
79+
/wd4100 # C4100 (unreferenced formal parameter): Doesn't play nice with polymorphism.
80+
/wd4127 # C4127 (conditional expression is constant)
81+
/wd4201 # C4201 (non-standard nameless struct/union): Only relevant for C89.
82+
/wd4244 # C4244 C4245 C4267 (narrowing conversions): Unavoidable at this scale.
83+
/wd4245
84+
/wd4267
85+
/wd4305 # C4305 (truncation): double to float or real_t, too hard to avoid.
86+
/wd4514 # C4514 (unreferenced inline function has been removed)
87+
/wd4714 # C4714 (function marked as __forceinline not inlined)
88+
/wd4820 # C4820 (padding added after construct)
89+
90+
/utf-8
91+
>
92+
93+
# Clang and GNU common options
94+
$<$<OR:${IS_CLANG},${IS_GNU}>:
95+
-Wall
96+
-Wctor-dtor-privacy
97+
-Wextra
98+
-Wno-unused-parameter
99+
-Wnon-virtual-dtor
100+
-Wwrite-strings
75101
>
76102

77-
$<${HOT_RELOAD}:
78-
$<${IS_GNU}:-fno-gnu-unique>
103+
# Clang only
104+
$<${IS_CLANG}:
105+
-Wimplicit-fallthrough
106+
-Wno-ordered-compare-function-pointers
79107
>
80108

81-
# MSVC only
82-
$<${IS_MSVC}:
83-
# /MP isn't valid for clang-cl with msvc frontend
84-
$<$<CXX_COMPILER_ID:MSVC>:/MP${PROC_N}>
85-
/W4
86-
87-
# Disable warnings which we don't plan to fix.
88-
/wd4100 # C4100 (unreferenced formal parameter): Doesn't play nice with polymorphism.
89-
/wd4127 # C4127 (conditional expression is constant)
90-
/wd4201 # C4201 (non-standard nameless struct/union): Only relevant for C89.
91-
/wd4244 # C4244 C4245 C4267 (narrowing conversions): Unavoidable at this scale.
92-
/wd4245
93-
/wd4267
94-
/wd4305 # C4305 (truncation): double to float or real_t, too hard to avoid.
95-
/wd4514 # C4514 (unreferenced inline function has been removed)
96-
/wd4714 # C4714 (function marked as __forceinline not inlined)
97-
/wd4820 # C4820 (padding added after construct)
98-
99-
/utf-8
100-
>
101-
102-
# Clang and GNU common options
103-
$<$<OR:${IS_CLANG},${IS_GNU}>:
104-
-Wall
105-
-Wctor-dtor-privacy
106-
-Wextra
107-
-Wno-unused-parameter
108-
-Wnon-virtual-dtor
109-
-Wwrite-strings
110-
>
111-
112-
# Clang only
113-
$<${IS_CLANG}:
114-
-Wimplicit-fallthrough
115-
-Wno-ordered-compare-function-pointers
116-
>
117-
118-
# GNU only
119-
$<${IS_GNU}:
120-
-Walloc-zero
121-
-Wduplicated-branches
122-
-Wduplicated-cond
123-
-Wno-misleading-indentation
124-
-Wplacement-new=1
125-
-Wshadow-local
126-
-Wstringop-overflow=4
127-
128-
# Bogus warning fixed in 8+.
129-
$<${GNU_LT_V8}:-Wno-strict-overflow>
130-
131-
$<${GNU_GE_V9}:-Wattribute-alias=2>
132-
133-
# Broke on MethodBind templates before GCC 11.
134-
$<${GNU_GT_V11}:-Wlogical-op>
135-
136-
# Regression in GCC 9/10, spams so much in our variadic templates that we need to outright disable it.
137-
$<${GNU_LT_V11}:-Wno-type-limits>
138-
139-
# False positives in our error macros, see GH-58747.
140-
$<${GNU_GE_V12}:-Wno-return-type>
141-
>
109+
# GNU only
110+
$<${IS_GNU}:
111+
-Walloc-zero
112+
-Wduplicated-branches
113+
-Wduplicated-cond
114+
-Wno-misleading-indentation
115+
-Wplacement-new=1
116+
-Wshadow-local
117+
-Wstringop-overflow=4
118+
119+
# Bogus warning fixed in 8+.
120+
$<${GNU_LT_V8}:-Wno-strict-overflow>
121+
122+
$<${GNU_GE_V9}:-Wattribute-alias=2>
123+
124+
# Broke on MethodBind templates before GCC 11.
125+
$<${GNU_GT_V11}:-Wlogical-op>
126+
127+
# Regression in GCC 9/10, spams so much in our variadic templates that we need to outright disable it.
128+
$<${GNU_LT_V11}:-Wno-type-limits>
129+
130+
# False positives in our error macros, see GH-58747.
131+
$<${GNU_GE_V12}:-Wno-return-type>
132+
>
142133
)
143134

144-
target_compile_definitions(${TARGET_NAME}
135+
target_compile_definitions(
136+
${TARGET_NAME}
145137
PUBLIC
146138
GDEXTENSION
147139

@@ -159,19 +151,21 @@ function( common_compiler_flags )
159151
$<${THREADS_ENABLED}:THREADS_ENABLED>
160152
)
161153

162-
target_link_options( ${TARGET_NAME}
154+
target_link_options(
155+
${TARGET_NAME}
163156
PUBLIC
164157
$<${IS_MSVC}:
165158
/WX # treat link warnings as errors.
166159
/MANIFEST:NO # We dont need a manifest
167160
>
168161

169162
$<${DEBUG_SYMBOLS}:$<${IS_MSVC}:/DEBUG:FULL>>
163+
170164
$<$<NOT:${DEBUG_SYMBOLS}>:
171165
$<${IS_GNU}:-s>
172166
$<${IS_CLANG}:-s>
173167
$<${IS_APPLECLANG}:-Wl,-S -Wl,-x -Wl,-dead_strip>
174168
>
175169
)
176-
170+
# gersemi: on
177171
endfunction()

cmake/godotcpp.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,10 @@ function( godotcpp_generate )
324324
${GODOTCPP_GDEXTENSION_DIR}
325325
)
326326

327-
set_target_properties( ${TARGET_NAME}
328-
PROPERTIES
327+
# gersemi: off
328+
set_target_properties(
329+
${TARGET_NAME}
330+
PROPERTIES
329331
CXX_STANDARD 17
330332
CXX_EXTENSIONS OFF
331333
CXX_VISIBILITY_PRESET ${GODOTCPP_SYMBOL_VISIBILITY}
@@ -349,6 +351,7 @@ function( godotcpp_generate )
349351
# Some IDE's respect this property to logically group targets
350352
FOLDER "godot-cpp"
351353
)
354+
# gersemi: on
352355

353356
if( CMAKE_SYSTEM_NAME STREQUAL Android )
354357
android_generate()

cmake/web.cmake

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,26 @@ function( web_options )
1414
# web options
1515
endfunction()
1616

17-
18-
function( web_generate )
19-
target_compile_definitions(${TARGET_NAME}
20-
PUBLIC
17+
function(web_generate)
18+
target_compile_definitions(
19+
${TARGET_NAME}
20+
PUBLIC #
2121
WEB_ENABLED
2222
UNIX_ENABLED
2323
)
2424

25-
target_compile_options( ${TARGET_NAME}
26-
PUBLIC
25+
target_compile_options(
26+
${TARGET_NAME}
27+
PUBLIC #
2728
-sSIDE_MODULE
2829
-sSUPPORT_LONGJMP=wasm
2930
-fno-exceptions
3031
$<${THREADS_ENABLED}:-sUSE_PTHREADS=1>
3132
)
3233

33-
target_link_options( ${TARGET_NAME}
34-
INTERFACE
34+
target_link_options(
35+
${TARGET_NAME}
36+
INTERFACE #
3537
-sWASM_BIGINT
3638
-sSUPPORT_LONGJMP=wasm
3739
-fvisibility=hidden

cmake/windows.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ function( windows_generate )
8484
>
8585
)
8686

87-
target_link_options( ${TARGET_NAME}
88-
PUBLIC
89-
87+
# gersemi: off
88+
target_link_options(
89+
${TARGET_NAME}
90+
PUBLIC
9091
$<${NOT_MSVC}:
9192
-Wl,--no-undefined
9293
$<${STATIC_CPP}:
@@ -98,6 +99,7 @@ function( windows_generate )
9899

99100
$<${IS_CLANG}:-lstdc++>
100101
)
102+
# gersemi: on
101103

102104
common_compiler_flags()
103105
endfunction()

test/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ foreach( TARGET_ALIAS template_debug template_release editor )
4242
get_target_property( GODOTCPP_SUFFIX ${LINK_TARGET} GODOTCPP_SUFFIX )
4343
get_target_property( OSX_ARCH ${LINK_TARGET} OSX_ARCHITECTURES )
4444

45-
set_target_properties( ${TARGET_NAME}
46-
PROPERTIES
45+
# gersemi: off
46+
set_target_properties(
47+
${TARGET_NAME}
48+
PROPERTIES
4749
CXX_STANDARD 17
4850
CXX_EXTENSIONS OFF
4951
CXX_VISIBILITY_PRESET ${GODOTCPP_SYMBOL_VISIBILITY}
@@ -67,6 +69,7 @@ foreach( TARGET_ALIAS template_debug template_release editor )
6769
# Some IDE's respect this property to logically group targets
6870
FOLDER "godot-cpp"
6971
)
72+
# gersemi: on
7073

7174
# CMAKE_SYSTEM_NAME refers to the target system
7275
if( CMAKE_SYSTEM_NAME STREQUAL Darwin )

0 commit comments

Comments
 (0)