cmake: use MSVC_FRONTEND
This commit is contained in:
parent
278b25bad2
commit
e633694255
@ -97,6 +97,11 @@ elseif(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
|
||||
endif()
|
||||
|
||||
set(MSVC_FRONTEND 0)
|
||||
if(MSVC OR ",${CMAKE_C_COMPILER_FRONTEND_VARIANT}," STREQUAL ",MSVC,")
|
||||
set(MSVC_FRONTEND 1)
|
||||
endif()
|
||||
|
||||
#***********************************************************************
|
||||
# targets
|
||||
#***********************************************************************
|
||||
@ -166,14 +171,14 @@ if(NOT MSVC)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${b}" CACHE STRING "Flags used by the CXX compiler during RELEASE builds." FORCE)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
if(MSVC_FRONTEND)
|
||||
# disable silly warnings about using "deprecated" POSIX functions like fopen()
|
||||
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
|
||||
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
|
||||
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
# set __cplusplus according to selected C++ standard; use new preprocessor
|
||||
add_definitions(-Zc:__cplusplus -Zc:preprocessor)
|
||||
add_definitions(-J -Zc:__cplusplus -Zc:preprocessor)
|
||||
else()
|
||||
# protect against security threats caused by misguided compiler "optimizations"
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
@ -186,7 +191,7 @@ endif()
|
||||
|
||||
# compile a target with -O2 even in Debug build
|
||||
function(upx_compile_target_debug_with_O2 t)
|
||||
if(MSVC)
|
||||
if(MSVC_FRONTEND)
|
||||
# MSVC uses some Debug compile options like -RTC1 that are incompatible with -O2
|
||||
else()
|
||||
target_compile_options(${t} PRIVATE $<$<CONFIG:Debug>:-O2>)
|
||||
@ -195,7 +200,7 @@ endfunction()
|
||||
|
||||
function(upx_sanitize_target t)
|
||||
if(NOT UPX_CONFIG_DISABLE_SANITIZE)
|
||||
if(MSVC)
|
||||
if(MSVC_FRONTEND)
|
||||
# MSVC uses -GS (similar to -fstack-protector) by default
|
||||
elseif(CMAKE_C_PLATFORM_ID MATCHES "^MinGW" OR MINGW OR CYGWIN)
|
||||
# avoid link errors with current MinGW-w64 versions
|
||||
@ -213,8 +218,8 @@ set(t upx_vendor_ucl)
|
||||
target_include_directories(${t} PRIVATE vendor/ucl/include vendor/ucl)
|
||||
upx_compile_target_debug_with_O2(${t})
|
||||
upx_sanitize_target(${t})
|
||||
if(MSVC)
|
||||
target_compile_options(${t} PRIVATE -J ${warn_WN} ${warn_WX})
|
||||
if(MSVC_FRONTEND)
|
||||
target_compile_options(${t} PRIVATE ${warn_WN} ${warn_WX})
|
||||
else()
|
||||
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
|
||||
endif()
|
||||
@ -223,8 +228,8 @@ set(t upx_vendor_zlib)
|
||||
upx_compile_target_debug_with_O2(${t})
|
||||
upx_sanitize_target(${t})
|
||||
target_compile_definitions(${t} PRIVATE HAVE_STDARG_H=1 HAVE_VSNPRINTF=1)
|
||||
if(MSVC)
|
||||
target_compile_options(${t} PRIVATE -J -W3 ${warn_WX})
|
||||
if(MSVC_FRONTEND)
|
||||
target_compile_options(${t} PRIVATE -W3 ${warn_WX})
|
||||
else()
|
||||
target_compile_definitions(${t} PRIVATE HAVE_UNISTD_H=1)
|
||||
# clang-15: -Wno-strict-prototypes is needed to silence the new -Wdeprecated-non-prototype warning
|
||||
@ -237,8 +242,8 @@ set(t upx_vendor_zstd)
|
||||
upx_compile_target_debug_with_O2(${t})
|
||||
upx_sanitize_target(${t})
|
||||
target_compile_definitions(${t} PRIVATE DYNAMIC_BMI2=0 ZSTD_DISABLE_ASM=1)
|
||||
if(MSVC)
|
||||
target_compile_options(${t} PRIVATE -J ${warn_WN} ${warn_WX})
|
||||
if(MSVC_FRONTEND)
|
||||
target_compile_options(${t} PRIVATE ${warn_WN} ${warn_WX})
|
||||
else()
|
||||
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
|
||||
endif()
|
||||
@ -267,8 +272,8 @@ if(NOT UPX_CONFIG_DISABLE_ZSTD)
|
||||
endif()
|
||||
#upx_compile_target_debug_with_O2(${t})
|
||||
upx_sanitize_target(${t})
|
||||
if(MSVC)
|
||||
target_compile_options(${t} PRIVATE -EHsc -J ${warn_WN} ${warn_WX})
|
||||
if(MSVC_FRONTEND)
|
||||
target_compile_options(${t} PRIVATE -EHsc ${warn_WN} ${warn_WX})
|
||||
else()
|
||||
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
|
||||
endif()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user