From 0e22d1a51ce6b07279706469a7c30a247f54aff8 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao Date: Sat, 10 Jun 2023 20:41:00 +0800 Subject: [PATCH] update --- utils.cmake | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/utils.cmake b/utils.cmake index c7b3e54..66a577d 100644 --- a/utils.cmake +++ b/utils.cmake @@ -423,14 +423,14 @@ function(setup_compile_params) endif() if(MSVC) target_compile_definitions(${__target} PRIVATE - _CRT_NON_CONFORMING_SWPRINTFS _CRT_SECURE_NO_WARNINGS - _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_WARNINGS - _CRT_NONSTDC_NO_DEPRECATE + _CRT_NON_CONFORMING_SWPRINTFS + _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE + _CRT_NONSTDC_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE _SCL_SECURE_NO_WARNINGS _SCL_SECURE_NO_DEPRECATE _ENABLE_EXTENDED_ALIGNED_STORAGE # STL fixed a bug which breaks binary compatibility, thus need to be enabled manually by defining this. - _USE_MATH_DEFINES # Enable the PI constant define for the math headers. - NOMINMAX # Avoid the Win32 macros conflict with std::min() and std::max(). - UNICODE _UNICODE # Use the -W APIs by default. + _USE_MATH_DEFINES # Enable the PI constant define for the math headers and also fix the redefinition error caused by Windows SDK's unguarded math macros. + NOMINMAX # Avoid the Win32 macros min/max conflict with std::min()/std::max(). + UNICODE _UNICODE # Use the -W APIs by default (the -A APIs are just wrappers of the -W APIs internally, so calling the -W APIs directly is more efficient). STRICT # https://learn.microsoft.com/en-us/windows/win32/winprog/enabling-strict WIN32_LEAN_AND_MEAN WINRT_LEAN_AND_MEAN # Filter out some rarely used headers, to increase compilation speed. ) @@ -452,9 +452,10 @@ function(setup_compile_params) if(CMAKE_SIZEOF_VOID_P EQUAL 8) target_link_options(${__target} PRIVATE /HIGHENTROPYVA) endif() - #[[if(MSVC_VERSION GREATER_EQUAL 1910) # Visual Studio 2017 version 15.0 - target_link_options(${__target} PRIVATE /DEPENDENTLOADFLAG:0x800) - endif()]] + if(MSVC_VERSION GREATER_EQUAL 1910) # Visual Studio 2017 version 15.0 ~ 15.2 + #target_link_options(${__target} PRIVATE /DEPENDENTLOADFLAG:0x800) + target_compile_options(${__target} PRIVATE $<$:/Zf>) + endif() if(MSVC_VERSION GREATER_EQUAL 1915) # Visual Studio 2017 version 15.8 target_compile_options(${__target} PRIVATE $<$:/JMC>) endif() @@ -463,6 +464,9 @@ function(setup_compile_params) target_compile_options(${__target} PRIVATE /d2FH4) endif() endif() + if(MSVC_VERSION GREATER_EQUAL 1924) # Visual Studio 2019 version 16.4 + target_compile_options(${__target} PRIVATE $<$:/ZH:SHA_256>) + endif() if(MSVC_VERSION GREATER_EQUAL 1925) # Visual Studio 2019 version 16.5 target_compile_options(${__target} PRIVATE $<$>:/QIntel-jcc-erratum>) endif() @@ -547,26 +551,28 @@ function(setup_compile_params) endif() endif() else() - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # Use pipes for communicating between sub-processes. Faster. Have no effect for Clang. - target_compile_options(${__target} PRIVATE -pipe) - endif() target_compile_options(${__target} PRIVATE - $<$>:-ffp-contract=fast -fomit-frame-pointer -ffunction-sections -fdata-sections> + -fthreadsafe-statics + $<$>:-ffp-contract=fast -fomit-frame-pointer -ffunction-sections -fdata-sections -funroll-all-loops> + ) + target_link_options(${__target} PRIVATE + $<$>:-Wl,--no-keep-memory -Wl,-z,relro> + $<$:-Wl,--strip-all> ) if(APPLE) target_link_options(${__target} PRIVATE - -Wl,-fatal_warnings + -Wl,-fatal_warnings -Wl,-undefined,error $<$>:-Wl,-dead_strip -Wl,-no_data_in_code_info -Wl,-no_function_starts> ) else() target_link_options(${__target} PRIVATE - -Wl,--fatal-warnings -Wl,--build-id=sha1 - $<$>:-Wl,--gc-sections -Wl,-O3> # Specifically tell the linker to perform optimizations. + -Wl,--fatal-warnings -Wl,--build-id=sha1 -Wl,--no-undefined + $<$>:-Wl,--gc-sections -Wl,-O3 -Wl,-z,now -Wl,-z,noexecstack> ) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options(${__target} PRIVATE + -pipe # Use pipes for communicating between sub-processes. Faster. Have no effect for Clang. $<$>:-Wa,-mbranches-within-32B-boundaries> ) endif() @@ -691,7 +697,7 @@ function(setup_compile_params) else() target_link_options(${__target} PRIVATE -fuse-ld=lld -Wl,--color-diagnostics) if(APPLE) - # TODO: -fobjc-arc (http://clang.llvm.org/docs/AutomaticReferenceCounting.html) + # TODO: -fobjc-arc, -fobjc-arc-exceptions (http://clang.llvm.org/docs/AutomaticReferenceCounting.html) target_compile_options(${__target} PRIVATE -fobjc-call-cxx-cdtors) target_link_options(${__target} PRIVATE $<$>:-Wl,--strict-auto-link>) else() @@ -701,12 +707,6 @@ function(setup_compile_params) target_compile_options(${__target} PRIVATE $<$>:-mretpoline -mspeculative-load-hardening> ) - # AppleClang can't recognize "-z" parameters, why? - if(NOT APPLE) - target_link_options(${__target} PRIVATE - $<$>:-Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wl,-z,separate-code> - ) - endif() endif() if(COM_ARGS_CFGUARD) if(NOT APPLE)