Skip to content

Commit e9500c4

Browse files
authored
Merge pull request #11 from rsps/add-compiler-utils
Add compiler utils
2 parents bc2ee9c + feea1ad commit e9500c4

File tree

6 files changed

+262
-2
lines changed

6 files changed

+262
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
* `semver_parse()`, `write_version_file` and `version_from_file()` utils, in `version.cmake`.
1818
* `git_find_version_tag()` util, in `git.cmake`.
1919
* `VERSION` file.
20+
* RSP's GCC strict compile options, in `gcc.cmake` (_exposed via `compiler.cmake` module_).
2021
* Caching utilities, `cache.cmake`.
21-
* A "mini" testing framework for cmake modules and scripts, in `testing.cmake`.
22+
* A "mini" testing framework for cmake modules and scripts, in `testing.cmake`.
2223
* `RSP_CMAKE_SCRIPTS_BUILD_TESTS` project option for building tests.
2324
* `tests.yaml` and `deploy-docs.yaml` GitHub Actions workflows.
2425
* `composer.json` to install [Daux.io](https://daux.io) dev-dependency (_documentation generator_).

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ endif ()
7878
# Misc.
7979
# -------------------------------------------------------------------------------------------------------------- #
8080

81-
# include("rsp/helpers")
81+
# include("rsp/debug")
8282

8383
# dump(CMAKE_MODULE_PATH FOO BAR PROJECT_NAME)

cmake/rsp/compiler.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -------------------------------------------------------------------------------------------------------------- #
2+
# Compiler utilities
3+
# -------------------------------------------------------------------------------------------------------------- #
4+
5+
include_guard(GLOBAL)
6+
7+
# Debug
8+
message(VERBOSE "rsp/compiler module included")
9+
10+
include("rsp/compilers/gcc")

cmake/rsp/compilers/gcc.cmake

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# -------------------------------------------------------------------------------------------------------------- #
2+
# GCC compiler utilities
3+
# -------------------------------------------------------------------------------------------------------------- #
4+
5+
include_guard(GLOBAL)
6+
7+
# Debug
8+
message(VERBOSE "rsp/compilers/gcc module included")
9+
10+
# GCC strict compile options
11+
#
12+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Option-Index.html
13+
# @see https://gcc.gnu.org/onlinedocs/
14+
#
15+
if (NOT DEFINED RSP_GCC_STRICT_COMPILE_OPTIONS)
16+
set(RSP_GCC_STRICT_COMPILE_OPTIONS
17+
18+
# Issue all the warnings demanded by strict ISO C and ISO C++.
19+
#
20+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-pedantic-1
21+
#
22+
-pedantic
23+
24+
# Enables all the warnings about constructions...
25+
#
26+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wall
27+
#
28+
-Wall
29+
30+
# Enables some extra warning flags that are not enabled by -Wall.
31+
#
32+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wextra
33+
#
34+
-Wextra
35+
36+
# Warn if an old-style (C-style) cast to a non-void type is used within a C++ program.
37+
#
38+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/C_002b_002b-Dialect-Options.html#index-Wold-style-cast
39+
#
40+
-Wold-style-cast
41+
42+
# Warn whenever a pointer is cast such that the required alignment of the target is increased.
43+
#
44+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wcast-align
45+
#
46+
-Wcast-align
47+
48+
# Warn whenever a pointer is cast so as to remove a type qualifier from the target type.
49+
#
50+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wcast-qual
51+
#
52+
-Wcast-qual
53+
54+
# Warn when a class seems unusable because all the constructors or destructors in that class
55+
# are private, and it has neither friends nor public static member functions.
56+
#
57+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/C_002b_002b-Dialect-Options.html#index-Wctor-dtor-privacy
58+
#
59+
-Wctor-dtor-privacy
60+
61+
# Warn if a requested optimization pass is disabled.
62+
#
63+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wdisabled-optimization
64+
#
65+
-Wdisabled-optimization
66+
67+
# Check calls to printf and scanf, etc., to make sure that the arguments supplied have types
68+
# appropriate to the format string specified.
69+
#
70+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wformat
71+
#
72+
-Wformat=2
73+
74+
# Warn about uninitialized variables that are initialized with themselves.
75+
#
76+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Winit-self
77+
#
78+
-Winit-self
79+
80+
# Warn about suspicious uses of logical operators in expressions.
81+
#
82+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wlogical-op
83+
#
84+
-Wlogical-op
85+
86+
# Warn if a global function is defined without a previous declaration.
87+
#
88+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wmissing-declarations
89+
#
90+
-Wmissing-declarations
91+
92+
# Warn if a user-supplied include directory does not exist.
93+
#
94+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wmissing-include-dirs
95+
#
96+
-Wmissing-include-dirs
97+
98+
# Warn when a noexcept-expression evaluates to false because of a call to a function that
99+
# does not have a non-throwing exception specification.
100+
#
101+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/C_002b_002b-Dialect-Options.html#index-Wnoexcept
102+
#
103+
-Wnoexcept
104+
105+
# Warn when a function declaration hides virtual functions from a base class.
106+
#
107+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/C_002b_002b-Dialect-Options.html#index-Woverloaded-virtual
108+
#
109+
-Woverloaded-virtual
110+
111+
# Warn if anything is declared more than once in the same scope.
112+
#
113+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wredundant-decls
114+
#
115+
-Wredundant-decls
116+
117+
# Warn for implicit conversions that may change the sign of an integer value, like assigning
118+
# a signed integer expression to an unsigned integer variable.
119+
#
120+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wsign-conversion
121+
#
122+
-Wsign-conversion
123+
124+
# Warn when a comparison between signed and unsigned values could produce an incorrect result
125+
# when the signed value is converted to unsigned.
126+
#
127+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wsign-compare
128+
#
129+
#-Wsign-compare # (Enabled by -Wall)
130+
131+
# Warn when overload resolution chooses a promotion from unsigned or enumerated type to a
132+
# signed type, over a conversion to an unsigned type of the same size.
133+
#
134+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/C_002b_002b-Dialect-Options.html#index-Wsign-promo
135+
#
136+
-Wsign-promo
137+
138+
# Warn about the use of an uncasted NULL as sentinel.
139+
#
140+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/C_002b_002b-Dialect-Options.html#index-Wstrict-null-sentinel
141+
#
142+
-Wstrict-null-sentinel
143+
144+
# Warns about cases where the compiler optimizes based on the assumption that signed overflow does not occur.
145+
#
146+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wstrict-overflow
147+
#
148+
-Wstrict-overflow=3 # (-Wall only includes Wstrict-overflow=1)
149+
150+
# Warn whenever a switch statement does not have a default case.
151+
#
152+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wswitch-default
153+
#
154+
-Wswitch-default
155+
156+
# Warn if an undefined identifier is evaluated in an #if directive.
157+
#
158+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wundef
159+
#
160+
-Wundef
161+
162+
# All the -Wunused options combined.
163+
#
164+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wno-unused
165+
#
166+
-Wno-unused
167+
168+
# Warn about violations of the style guidelines from Scott Meyers’ Effective C++ series
169+
# of books.
170+
#
171+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/C_002b_002b-Dialect-Options.html#index-Weffc_002b_002b
172+
#
173+
-Weffc++
174+
175+
# Make all warnings into errors.
176+
#
177+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Werror
178+
#
179+
-Werror
180+
181+
# Print (on standard error output) the commands executed to run the stages of compilation.
182+
#
183+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Overall-Options.html#index-v
184+
#
185+
#-v
186+
187+
# Dump all macro definitions, at the end of preprocessing, in addition to normal output.
188+
#
189+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Preprocessor-Options.html#index-dD
190+
# @see https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Developer-Options.html#index-dD-1
191+
#
192+
#-dD
193+
)
194+
endif ()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: GCC
3+
description: How to use the compiler module.
4+
keywords: gcc, compiler, cmake
5+
author: RSP Systems A/S
6+
---
7+
8+
# GCC
9+
10+
Helpers and utilities that are specific for [GNU Compiler Collection (GCC)](https://gcc.gnu.org/).
11+
12+
[TOC]
13+
14+
## Compile Option Presets
15+
16+
### Strict
17+
18+
Use `RSP_GCC_STRICT_COMPILE_OPTIONS` preset when you wish to enable strict compile options.
19+
20+
```cmake
21+
include("rsp/compiler")
22+
23+
add_compile_options(${RSP_GCC_STRICT_COMPILE_OPTIONS})
24+
```
25+
26+
For additional information, please review the `RSP_GCC_STRICT_COMPILE_OPTIONS` list, in the source code.
27+
28+
### Customize
29+
30+
If you need to customise a preset, create a copy of the desired preset, and use cmake's
31+
[list](https://cmake.org/cmake/help/latest/command/list.html#list) operations to remove or append options.
32+
33+
```cmake
34+
# Copy provided preset into new variable
35+
set(my_compile_options "${RSP_GCC_STRICT_COMPILE_OPTIONS}")
36+
37+
# Modify your preset...
38+
list(REMOVE_ITEM my_compile_options "-Wswitch-default")
39+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Compiler
3+
description: How to use the compiler module.
4+
keywords: compiler, cmake
5+
author: RSP Systems A/S
6+
---
7+
8+
# Compiler
9+
10+
Module that contains compiler specific helpers and utilities.
11+
12+
## How to include
13+
14+
```cmake
15+
include("rsp/compiler")
16+
```

0 commit comments

Comments
 (0)