mirror of
https://github.com/mtrojnar/osslsigncode.git
synced 2025-04-18 21:58:05 -05:00
fix AppleClang linker flags
This commit is contained in:
parent
d7daf98db8
commit
7871e28141
@ -1,39 +1,5 @@
|
|||||||
include(CheckCCompilerFlag)
|
include(CheckCCompilerFlag)
|
||||||
|
|
||||||
function(add_linker_flag_if_supported flagname targets)
|
|
||||||
check_c_compiler_flag("${flagname}" HAVE_FLAG_${flagname})
|
|
||||||
if (HAVE_FLAG_${flagname})
|
|
||||||
foreach(target ${targets})
|
|
||||||
target_link_options(${target} PRIVATE ${flagname})
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(add_compile_flag_if_supported flagname targets)
|
|
||||||
check_c_compiler_flag("${flagname}" HAVE_FLAG_${flagname})
|
|
||||||
if (HAVE_FLAG_${flagname})
|
|
||||||
foreach(target ${targets})
|
|
||||||
target_compile_options(${target} PRIVATE ${flagname})
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(add_linker_flag_to_targets targets)
|
|
||||||
set(CHECKED_FLAGS
|
|
||||||
"-fstack-protector-all"
|
|
||||||
"-fstack-protector"
|
|
||||||
"-fstack-check"
|
|
||||||
"-fPIE"
|
|
||||||
"-pie"
|
|
||||||
"-Wl,-z,relro"
|
|
||||||
"-Wl,-z,now"
|
|
||||||
"-Wl,-z,noexecstack"
|
|
||||||
)
|
|
||||||
foreach(flag ${CHECKED_FLAGS})
|
|
||||||
add_linker_flag_if_supported(${flag} "${targets}")
|
|
||||||
endforeach()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(add_debug_flag_if_supported flagname targets)
|
function(add_debug_flag_if_supported flagname targets)
|
||||||
check_c_compiler_flag("${flagname}" HAVE_FLAG_${flagname})
|
check_c_compiler_flag("${flagname}" HAVE_FLAG_${flagname})
|
||||||
if (HAVE_FLAG_${flagname})
|
if (HAVE_FLAG_${flagname})
|
||||||
@ -44,10 +10,6 @@ function(add_debug_flag_if_supported flagname targets)
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(add_compile_flag_to_targets targets)
|
function(add_compile_flag_to_targets targets)
|
||||||
set(CHECKED_FLAGS
|
|
||||||
# Support address space layout randomization (ASLR)
|
|
||||||
"-fPIE"
|
|
||||||
)
|
|
||||||
set(CHECKED_DEBUG_FLAGS
|
set(CHECKED_DEBUG_FLAGS
|
||||||
"-ggdb"
|
"-ggdb"
|
||||||
"-g"
|
"-g"
|
||||||
@ -82,9 +44,6 @@ function(add_compile_flag_to_targets targets)
|
|||||||
"-Wunused-parameter"
|
"-Wunused-parameter"
|
||||||
"-Wunused-function"
|
"-Wunused-function"
|
||||||
)
|
)
|
||||||
foreach(flag ${CHECKED_FLAGS})
|
|
||||||
add_compile_flag_if_supported(${flag} ${targets})
|
|
||||||
endforeach()
|
|
||||||
foreach(flag ${CHECKED_DEBUG_FLAGS})
|
foreach(flag ${CHECKED_DEBUG_FLAGS})
|
||||||
add_debug_flag_if_supported(${flag} ${targets})
|
add_debug_flag_if_supported(${flag} ${targets})
|
||||||
endforeach()
|
endforeach()
|
||||||
@ -125,7 +84,24 @@ function(add_compile_flags target)
|
|||||||
# Unrecognized compiler options are errors
|
# Unrecognized compiler options are errors
|
||||||
target_compile_options(${target} PRIVATE $<$<CONFIG:DEBUG>:/options:strict>)
|
target_compile_options(${target} PRIVATE $<$<CONFIG:DEBUG>:/options:strict>)
|
||||||
else()
|
else()
|
||||||
add_linker_flag_to_targets(${target})
|
check_c_compiler_flag("-fstack-protector-all" HAVE_STACK_PROTECTOR_ALL)
|
||||||
|
if(HAVE_STACK_PROTECTOR_ALL)
|
||||||
|
target_link_options(${target} PRIVATE -fstack-protector-all)
|
||||||
|
else()
|
||||||
|
check_c_compiler_flag("-fstack-protector" HAVE_STACK_PROTECTOR)
|
||||||
|
if(HAVE_STACK_PROTECTOR)
|
||||||
|
target_link_options(${target} PRIVATE -fstack-protector)
|
||||||
|
else()
|
||||||
|
message(WARNING "No stack protection supported")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
# Support address space layout randomization (ASLR)
|
||||||
|
target_compile_options(${target} PRIVATE $<$<NOT:$<C_COMPILER_ID:AppleClang>>:-fPIE>)
|
||||||
|
target_link_options(${target} PRIVATE $<$<NOT:$<C_COMPILER_ID:AppleClang>>:-fPIE -pie>)
|
||||||
|
target_link_options(${target} PRIVATE $<$<NOT:$<C_COMPILER_ID:AppleClang>>:-Wl,-z,relro>)
|
||||||
|
target_link_options(${target} PRIVATE $<$<NOT:$<C_COMPILER_ID:AppleClang>>:-Wl,-z,now>)
|
||||||
|
target_link_options(${target} PRIVATE $<$<NOT:$<C_COMPILER_ID:AppleClang>>:-Wl,-z,noexecstack>)
|
||||||
|
target_link_options(${target} PRIVATE -fstack-check)
|
||||||
add_compile_flag_to_targets(${target})
|
add_compile_flag_to_targets(${target})
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user