llvm.org GIT mirror llvm / ef1b6ff
[CMake] Default options for faster executables on MSVC Differential Revision: https://reviews.llvm.org/D55056 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361826 91177308-0d34-0410-b5e6-96231b3b80d8 Alexandre Ganea a month ago
3 changed file(s) with 37 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
434434 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
435435 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
436436
437 if (MSVC)
438 option(LLVM_ENABLE_INCREMENTAL_LINK "Link incrementally. Enabling it might produce slower executables." OFF)
439 endif()
440
437441 option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF)
438442
439443 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
4949 set(${flagsvar} "${${flagsvar}}" CACHE STRING "${flagsvar_docs}" FORCE)
5050 endmacro(set_flag_in_var)
5151
52 macro(disable_MT_if_LLDB build message)
53 if (LLVM_TOOL_LLDB_BUILD)
54 if ((NOT ${build} STREQUAL "DEBUG") AND (LLVM_USE_CRT_${build} STREQUAL "MT"))
55 if (LLVM_TOOL_CLANG_BUILD OR LLVM_TOOL_LLD_BUILD)
56 set(performance " This might impact runtime performance for Clang or LLD. Preferably build them separately.")
57 endif()
58 message(WARNING "${message}.${performance}")
59 set(LLVM_USE_CRT_${build} "MD")
60 endif()
61 endif()
62 endmacro(disable_MT_if_LLDB)
5263
5364 macro(choose_msvc_crt MSVC_CRT)
5465 if(LLVM_USE_CRT)
6576 get_current_crt(LLVM_USE_CRT_${build}
6677 MSVC_CRT_REGEX
6778 CMAKE_CXX_FLAGS_${build})
79
80 # Make /MT the default in Release builds to make them faster
81 # and avoid the DLL function thunking.
82 if ((${build} STREQUAL "MINSIZEREL") OR
83 (${build} STREQUAL "RELEASE") OR
84 (${build} STREQUAL "RELWITHDEBINFO"))
85 set(LLVM_USE_CRT_${build} "MT")
86 endif()
87
88 disable_MT_if_LLDB(${build} "Using /MD as required by LLDB")
89
6890 set(LLVM_USE_CRT_${build}
6991 "${LLVM_USE_CRT_${build}}"
7092 CACHE STRING "Specify VC++ CRT to use for ${build_type} configurations."
7193 FORCE)
7294 set_property(CACHE LLVM_USE_CRT_${build}
7395 PROPERTY STRINGS ;${${MSVC_CRT}})
74 endif(NOT LLVM_USE_CRT_${build})
96 else()
97 disable_MT_if_LLDB(${build} "Disabling /MT as required by LLDB")
98 endif()
7599 endforeach(build_type)
76100
77101 foreach(build_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
416416
417417 # "Enforce type conversion rules".
418418 append("/Zc:rvalueCast" CMAKE_CXX_FLAGS)
419
420 if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND NOT LLVM_ENABLE_INCREMENTAL_LINK)
421 foreach(CONFIG RELEASE RELWITHDEBINFO MINSIZEREL)
422 foreach(FLAG EXE MODULE SHARED STATIC)
423 string(REGEX REPLACE "[-/](INCREMENTAL:YES|INCREMENTAL:NO|INCREMENTAL)" "/INCREMENTAL:NO" CMAKE_${FLAG}_LINKER_FLAGS_${CONFIG} "${CMAKE_${FLAG}_LINKER_FLAGS_${CONFIG}}")
424 endforeach()
425 endforeach()
426 endif()
419427
420428 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT LLVM_ENABLE_LTO)
421429 # clang-cl and cl by default produce non-deterministic binaries because