Changeset View
Changeset View
Standalone View
Standalone View
src/CMakeLists.txt
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
endif() | endif() | ||||
# All windows code is PIC, forcing it on just adds useless compile warnings | # All windows code is PIC, forcing it on just adds useless compile warnings | ||||
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") | if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") | ||||
add_compiler_flag(-fPIC) | add_compiler_flag(-fPIC) | ||||
endif() | endif() | ||||
if(ENABLE_HARDENING) | if(ENABLE_HARDENING) | ||||
# Enable stack protection | |||||
add_cxx_compiler_flag(-fstack-protector-all -Wstack-protector) | |||||
# Enable some buffer overflow checking | |||||
add_compiler_flag(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2) | |||||
# Enable ASLR (these flags are primarily targeting MinGw) | |||||
add_linker_flag(-Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va) | |||||
# Make the relocated sections read-only | |||||
add_linker_flag(-Wl,-z,relro -Wl,-z,now) | |||||
# CMake provides the POSITION_INDEPENDENT_CODE property to set PIC/PIE. | # CMake provides the POSITION_INDEPENDENT_CODE property to set PIC/PIE. | ||||
# Unfortunately setting the -pie linker flag this way require CMake >= 3.14, | # Unfortunately setting the -pie linker flag this way require CMake >= 3.14, | ||||
# which is not widely distributed at the time of writing. | # which is not widely distributed at the time of writing. | ||||
# FIXME: use the POSITION_INDEPENDENT_CODE property instead | # FIXME: use the POSITION_INDEPENDENT_CODE property instead | ||||
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") | if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") | ||||
add_compiler_flag(-fPIE) | add_compiler_flag(-fPIE) | ||||
add_linker_flag(-pie) | add_linker_flag(-pie) | ||||
else() | |||||
# MinGw provides its own libssp for stack smashing protection | |||||
link_libraries(ssp) | |||||
endif() | endif() | ||||
endif() | endif() | ||||
# Enable warning | # Enable warning | ||||
add_c_compiler_flag(-Wnested-externs -Wstrict-prototypes) | add_c_compiler_flag(-Wnested-externs -Wstrict-prototypes) | ||||
add_compiler_flag( | add_compiler_flag( | ||||
-Wall | -Wall | ||||
-Wextra | -Wextra | ||||
▲ Show 20 Lines • Show All 270 Lines • Show Last 20 Lines |