Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strongly recommended security compiler flags #660

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ if(NOT MSVC)
add_compile_options(-fPIC -Wall -Wpedantic
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcolor-diagnostics>)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(-D_FORTIFY_SOURCE=2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, verify if optimization level of 1 and above has to be set for this macro to work as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FORTIFY_SOURCE requires O>0, we use O3 for the Release version.

endif()
if(UR_DEVELOPER_MODE)
add_compile_options(-Werror -fno-omit-frame-pointer)
add_compile_options(-Werror -fno-omit-frame-pointer -fstack-protector-strong)
endif()
# Determine if libstdc++ is being used.
check_cxx_source_compiles("
Expand All @@ -81,7 +84,7 @@ elseif(MSVC)
add_compile_options(/MP /W3 /MD$<$<CONFIG:Debug>:d>)

if(UR_DEVELOPER_MODE)
add_compile_options(/WX)
add_compile_options(/WX /GS)
endif()
endif()

Expand Down