Skip to content

Commit a3a4978

Browse files
committed
Move fortification to ci-linux
Fortification via the "_FORTIFY_SOURCE" define only works when optimizations are enabled. The "ci-linux" preset already sets the build type to release, so this seems to be the best place to put a release config dependent compiler option. Fixes: #128
1 parent 19ab707 commit a3a4978

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

cmake-init/templates/common/CMakePresets.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
"description": "These flags are supported by both GCC and Clang",
8787
"hidden": true,
8888
"cacheVariables": {
89-
"CMAKE_C{% if cpp %}XX{% end %}_FLAGS": "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3{% if cpp %} -D_GLIBCXX_ASSERTIONS=1{% end %} -fstack-protector-strong -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough {% if c %}-Werror=strict-prototypes -Wwrite-strings{% if c90 %} -Werror=declaration-after-statement{% end %}{% else %}-Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast{% end %}",{% if c and pm %}
90-
"CMAKE_CXX_FLAGS": "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS=1 -fstack-protector-strong -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast",{% end %}
89+
"CMAKE_C{% if cpp %}XX{% end %}_FLAGS": "{% if cpp %}-D_GLIBCXX_ASSERTIONS=1 {% end %}-fstack-protector-strong -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough {% if c %}-Werror=strict-prototypes -Wwrite-strings{% if c90 %} -Werror=declaration-after-statement{% end %}{% else %}-Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast{% end %}",{% if c and pm %}
90+
"CMAKE_CXX_FLAGS": "-D_GLIBCXX_ASSERTIONS=1 -fstack-protector-strong -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast",{% end %}
9191
"CMAKE_EXE_LINKER_FLAGS": "-Wl,--allow-shlib-undefined,--as-needed,-z,noexecstack,-z,relro,-z,now,-z,nodlopen",
9292
"CMAKE_SHARED_LINKER_FLAGS": "-Wl,--allow-shlib-undefined,--as-needed,-z,noexecstack,-z,relro,-z,now,-z,nodlopen"
9393
}
@@ -113,11 +113,14 @@
113113
},
114114
{
115115
"name": "ci-linux",
116+
"description": "Includes fortification with the CMake default release flags",
116117
"inherits": ["flags-gcc-clang", "ci-std"],
117118
"generator": "Unix Makefiles",
118119
"hidden": true,
119120
"cacheVariables": {
120-
"CMAKE_BUILD_TYPE": "Release"
121+
"CMAKE_BUILD_TYPE": "Release",
122+
"CMAKE_C{% if cpp %}XX{% end %}_FLAGS_RELEASE": "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -O3 -DNDEBUG"{% if c and pm %},
123+
"CMAKE_CXX_FLAGS_RELEASE": "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -O3 -DNDEBUG"{% end %}
121124
}
122125
},
123126
{

0 commit comments

Comments
 (0)