Commit b83dd528 authored by Marcus Asteborg's avatar Marcus Asteborg Committed by Ralph Giles

cmake - MINGW check for ssp lib and link if security features is enabled

parent d4b8707b
Pipeline #2098 passed with stage
in 4 minutes and 57 seconds
...@@ -109,10 +109,19 @@ cmake_dependent_option(OPUS_STACK_PROTECTOR ...@@ -109,10 +109,19 @@ cmake_dependent_option(OPUS_STACK_PROTECTOR
OFF) OFF)
add_feature_info(OPUS_STACK_PROTECTOR OPUS_STACK_PROTECTOR ${OPUS_STACK_PROTECTOR_HELP_STR}) add_feature_info(OPUS_STACK_PROTECTOR OPUS_STACK_PROTECTOR ${OPUS_STACK_PROTECTOR_HELP_STR})
if(NOT MSVC AND NOT MINGW) if(NOT MSVC)
set(OPUS_FORTIFY_SOURCE_HELP_STR "add protection against buffer overflows.") set(OPUS_FORTIFY_SOURCE_HELP_STR "add protection against buffer overflows.")
option(OPUS_FORTIFY_SOURCE ${OPUS_FORTIFY_SOURCE_HELP_STR} ON) cmake_dependent_option(OPUS_FORTIFY_SOURCE
add_feature_info(OPUS_FORTIFY_SOURCE OPUS_FORTIFY_SOURCE ${OPUS_FORTIFY_SOURCE_HELP_STR}) ${OPUS_FORTIFY_SOURCE_HELP_STR}
ON
"FORTIFY_SOURCE_SUPPORTED"
OFF)
add_feature_info(OPUS_FORTIFY_SOURCE OPUS_FORTIFY_SOURCE ${OPUS_FORTIFY_SOURCE_HELP_STR})
endif()
if(MINGW AND (OPUS_FORTIFY_SOURCE OR OPUS_STACK_PROTECTOR))
# ssp lib is needed for security features for MINGW
list(APPEND OPUS_REQUIRED_LIBRARIES ssp)
endif() endif()
if(OPUS_CPU_X86 OR OPUS_CPU_X64) if(OPUS_CPU_X86 OR OPUS_CPU_X64)
...@@ -247,8 +256,9 @@ target_include_directories( ...@@ -247,8 +256,9 @@ target_include_directories(
target_link_libraries(opus PRIVATE ${OPUS_REQUIRED_LIBRARIES}) target_link_libraries(opus PRIVATE ${OPUS_REQUIRED_LIBRARIES})
target_compile_definitions(opus PRIVATE OPUS_BUILD ENABLE_HARDENING) target_compile_definitions(opus PRIVATE OPUS_BUILD ENABLE_HARDENING)
if(OPUS_FORTIFY_SOURCE) if(OPUS_FORTIFY_SOURCE AND NOT MSVC)
target_compile_definitions(opus PRIVATE _FORTIFY_SOURCE=2) target_compile_definitions(opus PRIVATE
$<$<NOT:$<CONFIG:debug>>:_FORTIFY_SOURCE=2>)
endif() endif()
if(OPUS_FLOAT_APPROX) if(OPUS_FLOAT_APPROX)
......
...@@ -77,6 +77,18 @@ else() ...@@ -77,6 +77,18 @@ else()
check_flag(FAST_MATH -ffast-math) check_flag(FAST_MATH -ffast-math)
check_flag(STACK_PROTECTOR -fstack-protector-strong) check_flag(STACK_PROTECTOR -fstack-protector-strong)
check_flag(HIDDEN_VISIBILITY -fvisibility=hidden) check_flag(HIDDEN_VISIBILITY -fvisibility=hidden)
set(FORTIFY_SOURCE_SUPPORTED 1)
endif()
if(MINGW)
# For MINGW we need to link ssp lib for security features such as
# stack protector and fortify_sources
check_library_exists(ssp __stack_chk_fail "" HAVE_LIBSSP)
if(NOT HAVE_LIBSSP)
message(WARNING "Could not find libssp in MinGW, disabling STACK_PROTECTOR and FORTIFY_SOURCE")
set(STACK_PROTECTOR_SUPPORTED 0)
set(FORTIFY_SOURCE_SUPPORTED 0)
endif()
endif() endif()
if(NOT MSVC) if(NOT MSVC)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment