Skip to content

Commit ff94644

Browse files
wangrong1069deepin-bot[bot]
authored andcommitted
chore: Update compiler flags for security enhancements
As title Log: Update compiler flags for security enhancements Bug: https://pms.uniontech.com/bug-view-342665.html
1 parent 488195f commit ff94644

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ set(CMAKE_AUTOUIC ON)
1717
set(CMAKE_AUTORCC ON)
1818
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
1919

20+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
21+
message("Enable build hardening.")
22+
23+
set(CMAKE_VERBOSE_MAKEFILE ON)
24+
25+
set(HARDENING_FLAGS "-Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -ffile-prefix-map=${CMAKE_SOURCE_DIR}=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security")
26+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HARDENING_FLAGS}")
27+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${HARDENING_FLAGS}")
28+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now")
29+
endif()
30+
2031
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "sw_64")
2132
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mieee")
2233
endif ()

0 commit comments

Comments
 (0)