1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[CMake] Default options for faster executables on MSVC

Differential Revision: https://reviews.llvm.org/D55056

llvm-svn: 361826
This commit is contained in:
Alexandre Ganea 2019-05-28 14:14:48 +00:00
parent 3de7a66873
commit 023ca6322c
3 changed files with 37 additions and 1 deletions

View File

@ -435,6 +435,10 @@ option(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF)
option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
if (MSVC)
option(LLVM_ENABLE_INCREMENTAL_LINK "Link incrementally. Enabling it might produce slower executables." OFF)
endif()
option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF) option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF)
if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )

View File

@ -50,6 +50,17 @@ macro(set_flag_in_var flagsvar regex flag)
set(${flagsvar} "${${flagsvar}}" CACHE STRING "${flagsvar_docs}" FORCE) set(${flagsvar} "${${flagsvar}}" CACHE STRING "${flagsvar_docs}" FORCE)
endmacro(set_flag_in_var) endmacro(set_flag_in_var)
macro(disable_MT_if_LLDB build message)
if (LLVM_TOOL_LLDB_BUILD)
if ((NOT ${build} STREQUAL "DEBUG") AND (LLVM_USE_CRT_${build} STREQUAL "MT"))
if (LLVM_TOOL_CLANG_BUILD OR LLVM_TOOL_LLD_BUILD)
set(performance " This might impact runtime performance for Clang or LLD. Preferably build them separately.")
endif()
message(WARNING "${message}.${performance}")
set(LLVM_USE_CRT_${build} "MD")
endif()
endif()
endmacro(disable_MT_if_LLDB)
macro(choose_msvc_crt MSVC_CRT) macro(choose_msvc_crt MSVC_CRT)
if(LLVM_USE_CRT) if(LLVM_USE_CRT)
@ -66,13 +77,26 @@ variables (LLVM_USE_CRT_DEBUG, etc) instead.")
get_current_crt(LLVM_USE_CRT_${build} get_current_crt(LLVM_USE_CRT_${build}
MSVC_CRT_REGEX MSVC_CRT_REGEX
CMAKE_CXX_FLAGS_${build}) CMAKE_CXX_FLAGS_${build})
# Make /MT the default in Release builds to make them faster
# and avoid the DLL function thunking.
if ((${build} STREQUAL "MINSIZEREL") OR
(${build} STREQUAL "RELEASE") OR
(${build} STREQUAL "RELWITHDEBINFO"))
set(LLVM_USE_CRT_${build} "MT")
endif()
disable_MT_if_LLDB(${build} "Using /MD as required by LLDB")
set(LLVM_USE_CRT_${build} set(LLVM_USE_CRT_${build}
"${LLVM_USE_CRT_${build}}" "${LLVM_USE_CRT_${build}}"
CACHE STRING "Specify VC++ CRT to use for ${build_type} configurations." CACHE STRING "Specify VC++ CRT to use for ${build_type} configurations."
FORCE) FORCE)
set_property(CACHE LLVM_USE_CRT_${build} set_property(CACHE LLVM_USE_CRT_${build}
PROPERTY STRINGS ;${${MSVC_CRT}}) PROPERTY STRINGS ;${${MSVC_CRT}})
endif(NOT LLVM_USE_CRT_${build}) else()
disable_MT_if_LLDB(${build} "Disabling /MT as required by LLDB")
endif()
endforeach(build_type) endforeach(build_type)
foreach(build_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE}) foreach(build_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})

View File

@ -418,6 +418,14 @@ if( MSVC )
# "Enforce type conversion rules". # "Enforce type conversion rules".
append("/Zc:rvalueCast" CMAKE_CXX_FLAGS) append("/Zc:rvalueCast" CMAKE_CXX_FLAGS)
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND NOT LLVM_ENABLE_INCREMENTAL_LINK)
foreach(CONFIG RELEASE RELWITHDEBINFO MINSIZEREL)
foreach(FLAG EXE MODULE SHARED STATIC)
string(REGEX REPLACE "[-/](INCREMENTAL:YES|INCREMENTAL:NO|INCREMENTAL)" "/INCREMENTAL:NO" CMAKE_${FLAG}_LINKER_FLAGS_${CONFIG} "${CMAKE_${FLAG}_LINKER_FLAGS_${CONFIG}}")
endforeach()
endforeach()
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT LLVM_ENABLE_LTO) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT LLVM_ENABLE_LTO)
# clang-cl and cl by default produce non-deterministic binaries because # clang-cl and cl by default produce non-deterministic binaries because
# link.exe /incremental requires a timestamp in the .obj file. clang-cl # link.exe /incremental requires a timestamp in the .obj file. clang-cl