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 recommended security linker flags #758

Merged
merged 1 commit into from
Aug 1, 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
30 changes: 24 additions & 6 deletions cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ function(add_ur_target_compile_options name)
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcolor-diagnostics>
)

if (CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_definitions(${name} PRIVATE -D_FORTIFY_SOURCE=2)
endif()
Expand All @@ -84,27 +83,46 @@ function(add_ur_target_compile_options name)
/MD$<$<CONFIG:Debug>:d>
/GS
)
add_link_options(

if(UR_DEVELOPER_MODE)
target_compile_options(${name} PRIVATE /WX /GS)
endif()
endif()
endfunction()

function(add_ur_target_link_options name)
if(NOT MSVC)
if (NOT APPLE)
target_link_options(${name} PRIVATE "LINKER:-z,relro,-z,now")
endif()
elseif(MSVC)
target_link_options(${name} PRIVATE
/DYNAMICBASE
/HIGHENTROPYVA
/ALLOWISOLATION
/NXCOMPAT
)
endif()
endfunction()

if(UR_DEVELOPER_MODE)
target_compile_options(${name} PRIVATE /WX /GS)
endif()
function(add_ur_target_exec_options name)
if(MSVC)
target_link_options(${name} PRIVATE
/ALLOWISOLATION
)
endif()
endfunction()

function(add_ur_executable name)
add_executable(${name} ${ARGN})
add_ur_target_compile_options(${name})
add_ur_target_exec_options(${name})
add_ur_target_link_options(${name})
endfunction()

function(add_ur_library name)
add_library(${name} ${ARGN})
add_ur_target_compile_options(${name})
add_ur_target_link_options(${name})
endfunction()

include(FetchContent)
Expand Down