Skip to content

Commit 202de58

Browse files
authored
fix(hardening): fix hardening on windows based on msvc (#23)
Signed-off-by: l.feng <[email protected]>
1 parent b8c32da commit 202de58

File tree

4 files changed

+108
-130
lines changed

4 files changed

+108
-130
lines changed

CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,12 @@ project(
1515
VERSION ${SKBUILD_PROJECT_VERSION}
1616
LANGUAGES C CXX)
1717

18-
set(CMAKE_CXX_STANDARD
19-
20
20-
CACHE STRING "C++ standard")
21-
set(CMAKE_CXX_STANDARD_REQUIRED
22-
ON
23-
CACHE BOOL "C++ standard required")
24-
set(CMAKE_CXX_EXTENSIONS
25-
OFF
26-
CACHE BOOL "C++ extensions")
27-
2818
# Project default module
2919
find_package(cmake-modules REQUIRED)
3020
include(cmake-modules/ProjectDefault)
3121

3222
# Project custom modules
3323
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
34-
include(ConfigureWarningsAndHardening)
3524
include(ConfigureVersion)
3625

3726
add_subdirectory(src)

cmake/ConfigureWarningsAndHardening.cmake

Lines changed: 0 additions & 117 deletions
This file was deleted.

cmake/ProjectOptions.cmake

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#[[
2+
ProjectOptions.cmake - Defines project-specific options for CMake.
3+
]]
4+
5+
set(CMAKE_CXX_STANDARD
6+
20
7+
CACHE STRING "C++ standard")
8+
set(CMAKE_CXX_STANDARD_REQUIRED
9+
ON
10+
CACHE BOOL "C++ standard required")
11+
set(CMAKE_CXX_EXTENSIONS
12+
OFF
13+
CACHE BOOL "C++ extensions")
14+
15+
# ##############################################################################
16+
# Sanitizer - cmake-modules/build/Sanitizer.cmake
17+
# ##############################################################################
18+
19+
set(USE_SANITIZER
20+
OFF
21+
CACHE BOOL "Enable sanitizer")
22+
23+
# ##############################################################################
24+
# Valgrind - cmake-modules/test/Valgrind.cmake
25+
# ##############################################################################
26+
27+
set(USE_VALGRIND
28+
OFF
29+
CACHE BOOL "Enable Valgrind")
30+
set(USE_VALGRIND_OPTIONS
31+
--leak-check=full # Each individual leak will be shown in detail.
32+
--show-leak-kinds=all # Show all of "definite, indirect, possible,
33+
# reachable" leak kinds in the "full" report.
34+
--gen-suppressions=all # gen suppress info automatically.
35+
--track-origins=yes # Favor useful output over speed. This tracks the
36+
# origins of uninitialized values, which could be very
37+
# useful for memory errors. Consider turning off if
38+
# Valgrind is unacceptably slow.
39+
CACHE STRING "valgrind options.")
40+
41+
# ##############################################################################
42+
# Clang-Tidy - cmake-modules/build/ClangTidy.cmake
43+
# ##############################################################################
44+
45+
set(USE_CLANGTIDY
46+
OFF
47+
CACHE BOOL "Enable Clang-Tidy")
48+
49+
# ##############################################################################
50+
# Cppcheck - cmake-modules/build/Cppcheck.cmake
51+
# ##############################################################################
52+
53+
set(USE_CPPCHECK
54+
OFF
55+
CACHE BOOL "Enable Cppcheck")
56+
set(USE_CPPCHECK_SUPPRESSION_FILE
57+
${CMAKE_SOURCE_DIR}/.cppcheck-suppressions.txt
58+
CACHE STRING
59+
"Customize the path to the Cppcheck suppressions file of the project")
60+
61+
# ##############################################################################
62+
# Hardening - cmake-modules/build/Hardening.cmake
63+
# ##############################################################################
64+
65+
# Comment `-Wl,-z,nodlopen` for dlopen call
66+
if(NOT MSVC)
67+
set(USE_HARDENING_FLAGS
68+
-D_GLIBCXX_ASSERTIONS # Enable assertions
69+
-U_FORTIFY_SOURCE # Disable stack protector
70+
-D_FORTIFY_SOURCE=3 # Enable stack protector
71+
-fstack-protector-strong # Enable stack protector
72+
-fcf-protection # Control Flow Guard
73+
-fstack-clash-protection # Control Flow Guard
74+
-Wimplicit-fallthrough # Enabled in compiler flags by default
75+
-fstrict-flex-arrays=3 # Enable strict array bounds
76+
-Wformat # Enabled in compiler flags by default
77+
-Wformat=2 # Enabled in compiler flags by default
78+
# -Wl,-z,nodlopen # Restrict dlopen(3) calls to shared objects
79+
-Wl,-z,noexecstack # Enable data execution prevention by marking stack
80+
# memory as non-executable
81+
-Wl,-z,relro # Mark relocation table entries resolved at load-time as
82+
# read-only
83+
-Wl,-z,now # Mark relocation table entries resolved at load-time as
84+
# read-only. It impacts startup performance
85+
"-fsanitize=undefined -fsanitize-minimal-runtime" # Enable minimal runtime
86+
# undefined behavior sanitizer
87+
-fno-delete-null-pointer-checks
88+
-fno-strict-overflow
89+
-fno-strict-aliasing
90+
-ftrivial-auto-var-init=zero
91+
-Wtrampolines # Enable trampolines(gcc only)
92+
-mbranch-protection=standard # Enable indirect branches(aarch64 only)
93+
CACHE STRING "Additional hardening compilation flags for GCC/Clang")
94+
95+
set(USE_HARDENING_LINKS
96+
-fstack-protector-strong # Enable stack protector
97+
"-fsanitize=undefined -fsanitize-minimal-runtime"
98+
# -Wl,-z,nodlopen # Restrict dlopen(3) calls to shared objects
99+
-Wl,-z,noexecstack # Enable data execution prevention by marking stack
100+
# memory as non-executable
101+
-Wl,-z,relro # Mark relocation table entries resolved at load-time as
102+
# read-only
103+
-Wl,-z,now # Mark relocation table entries resolved at load-time as
104+
# read-only. It impacts startup performance
105+
CACHE STRING "Additional hardening linking flags for GCC/Clang")
106+
endif()

vcpkg.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
{
3333
"name": "cmake-modules",
34-
"version": "1.6.12"
34+
"version": "1.6.13"
3535
},
3636
{
3737
"name": "robotology-cmake-ycm",
@@ -53,7 +53,7 @@
5353
"registries": [
5454
{
5555
"kind": "git",
56-
"baseline": "d97dd1ef7fecabcfd756dbf520dfd625bb562046",
56+
"baseline": "acce0190fabf75096d6be7db6138cb714bc7aace",
5757
"repository": "https://github.com/msclock/cmake-registry",
5858
"packages": [
5959
"cmake-modules",

0 commit comments

Comments
 (0)