From e15d7d9bf98de4ba8aa7d89c505164711ee7d8aa Mon Sep 17 00:00:00 2001 From: Zhao Yuhang <2546789017@qq.com> Date: Mon, 9 Oct 2023 19:43:42 +0800 Subject: [PATCH] update --- utils.cmake | 57 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/utils.cmake b/utils.cmake index a3f7c9b..8b91d45 100644 --- a/utils.cmake +++ b/utils.cmake @@ -645,7 +645,7 @@ function(setup_compile_params) message(WARNING "setup_compile_params: Current toolchain is not supported. Only LLVM-MinGW (https://github.com/mstorsjo/llvm-mingw) has partial support.") return() endif() - cmake_parse_arguments(COM_ARGS "SPECTRE;EHCONTGUARD;PERMISSIVE;INTELCET;INTELJCC;CFGUARD;FORCE_LTO" "" "TARGETS" ${ARGN}) + cmake_parse_arguments(COM_ARGS "SPECTRE;EHCONTGUARD;PERMISSIVE;INTELCET;INTELJCC;CFGUARD;FORCE_LTO;SECURE_CODE" "" "TARGETS" ${ARGN}) if(NOT COM_ARGS_TARGETS) message(AUTHOR_WARNING "setup_compile_params: You need to specify at least one target for this function!") return() @@ -698,8 +698,23 @@ function(setup_compile_params) ) if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) target_compile_options(${__target} PRIVATE - /bigobj /utf-8 $<$:/fp:fast /GT /Gw /Gy /Zc:inline> + /bigobj /FS /MP /utf-8 $<$:/fp:fast /GT /Gw /Gy /Oi /Ot /Oy /Zc:inline> ) + if(COM_ARGS_SECURE_CODE) + target_compile_options(${__target} PRIVATE + /GS /sdl + ) + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + target_link_options(${__target} PRIVATE /SAFESEH) + endif() + else() + target_compile_options(${__target} PRIVATE + /GS- /sdl- + ) + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + target_link_options(${__target} PRIVATE /SAFESEH:NO) + endif() + endif() target_link_options(${__target} PRIVATE # We want to get the PDB files so we add the "/DEBUG" parameter here, # however, MSVC will disable some optimizations if it found this flag, @@ -712,9 +727,6 @@ function(setup_compile_params) target_compile_options(${__target} PRIVATE $<$:/GA>) target_link_options(${__target} PRIVATE /TSAWARE) endif() - #if(CMAKE_SIZEOF_VOID_P EQUAL 4) - # target_link_options(${__target} PRIVATE /SAFESEH) - #endif() if(CMAKE_SIZEOF_VOID_P EQUAL 8) target_link_options(${__target} PRIVATE /HIGHENTROPYVA) endif() @@ -831,7 +843,7 @@ function(setup_compile_params) if(APPLE) target_link_options(${__target} PRIVATE -Wl,-fatal_warnings -Wl,-undefined,error - $<$:-Wl,-dead_strip -Wl,-no_data_in_code_info -Wl,-no_function_starts> + $<$:-Wl,-dead_strip> # -Wl,-no_data_in_code_info -Wl,-no_function_starts ) else() target_link_options(${__target} PRIVATE @@ -889,16 +901,26 @@ function(setup_compile_params) get_target_property(__lto_enabled ${__target} INTERPROCEDURAL_OPTIMIZATION) endif() if(__lto_enabled) - target_compile_options(${__target} PRIVATE - $<$:-fwhole-program-vtables> # -fsplit-lto-unit -funified-lto - ) + #target_compile_options(${__target} PRIVATE + # $<$:-fsplit-lto-unit -funified-lto> + #) + if(__target_type STREQUAL "EXECUTABLE") + target_compile_options(${__target} PRIVATE + $<$:-fwhole-program-vtables> + ) + endif() if(MSVC) target_link_options(${__target} PRIVATE - $<$:/OPT:lldltojobs=all /OPT:lldlto=3 /OPT:lldltocgo=3> # /lldltocachepolicy:cache_size=10%:cache_size_bytes=40g:cache_size_files=100000 + $<$:/OPT:lldltojobs=all /OPT:lldlto=3 /OPT:lldltocgo=3> ) else() + if(__target_type STREQUAL "EXECUTABLE") + target_link_options(${__target} PRIVATE + $<$:-fwhole-program-vtables> + ) + endif() target_link_options(${__target} PRIVATE - $<$:-fwhole-program-vtables -Wl,--thinlto-jobs=all -Wl,--lto-O3 -Wl,--lto-CGO3> # -Wl,--thinlto-cache-policy=cache_size=10%:cache_size_bytes=40g:cache_size_files=100000 + $<$:-Wl,--thinlto-jobs=all -Wl,--lto-O3 -Wl,--lto-CGO3> ) endif() endif() @@ -932,9 +954,18 @@ function(setup_compile_params) -fansi-escape-codes /Zc:dllexportInlines- # Do not export inline member functions. This is similar to "-fvisibility-inlines-hidden". /Zc:char8_t /Zc:sizedDealloc /Zc:strictStrings /Zc:threadSafeInit /Zc:trigraphs /Zc:twoPhase - /clang:-mcx16 # Needed by _InterlockedCompareExchange128() from CPP/WinRT. - $<$:/clang:-mbranches-within-32B-boundaries /clang:-ffp-contract=fast /Gw /Gy /Zc:inline> + $<$:/clang:-mbranches-within-32B-boundaries /fp:fast /Gw /Gy /Oi /Ot /Zc:inline> ) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + target_compile_options(${__target} PRIVATE + /clang:-mcx16 # Needed by _InterlockedCompareExchange128() from CPP/WinRT. + ) + endif() + if(COM_ARGS_SECURE_CODE) + target_compile_options(${__target} PRIVATE /GS) + else() + target_compile_options(${__target} PRIVATE /GS-) + endif() target_link_options(${__target} PRIVATE --color-diagnostics $<$:/DEBUG /OPT:REF /OPT:ICF /OPT:LBR /OPT:lldtailmerge>