CMake: make building with /MT an option instead of always forcing it
authorHans Wennborg <hans@hanshq.net>
Wed, 13 Nov 2013 19:12:02 +0000 (19:12 +0000)
committerHans Wennborg <hans@hanshq.net>
Wed, 13 Nov 2013 19:12:02 +0000 (19:12 +0000)
for release builds.

This is a follow-up to r194589. Aaron pointed out that building
libraries with /MT and using them in an application that uses a
different run-time library can be a bad idea.

Move the option to build with /MT behind a CMake option so it can be
turned on selectively, such as when building the toolchain installer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194596 91177308-0d34-0410-b5e6-96231b3b80d8

CMakeLists.txt
cmake/modules/HandleLLVMOptions.cmake
docs/CMake.rst

index e6fd506f784fdbf446cc955127da26b5cee02237..5a8eb980271d520f864cbac27d651c3e79057e77 100644 (file)
@@ -17,6 +17,8 @@ set(PACKAGE_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}svn")
 
 option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
 
+option(LLVM_STATIC_MSVC_RUNTIME "When using MSVC, link against the static run-time (/MT)" OFF)
+
 option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
 if ( LLVM_USE_FOLDERS )
   set_property(GLOBAL PROPERTY USE_FOLDERS ON)
index ff71c00544fdab85a51c4bce748d48f758552f64..9fdc708abd7ac94f58521e489f950ee5dc2ab19d 100644 (file)
@@ -41,13 +41,16 @@ else()
   endif()
 endif()
 
-if(MSVC)
-  # Link release builds against the static runtime.
+if(MSVC AND LLVM_STATIC_MSVC_RUNTIME)
+  # Link against the static runtime.
   foreach(flag CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO
       CMAKE_C_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELEASE
       CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_MINSIZEREL)
     llvm_replace_compiler_option("${flag}" "/MD" "/MT")
   endforeach()
+  foreach(flag CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG)
+    llvm_replace_compiler_option("${flag}" "/MDd" "/MTd")
+  endforeach()
 endif()  
 
 if(WIN32)
index c9fe538c9dfa1e2067a939758eda667260f4bc9c..69eeaab529d7b8c497793ed2fd91661dd6212485 100644 (file)
@@ -280,6 +280,11 @@ LLVM-specific variables
   are ``Address``, ``Memory`` and ``MemoryWithOrigins``. Defaults to empty
   string.
 
+**LLVM_STATIC_MSVC_RUNTIME**:BOOL
+  When building with MSVC, link against the static runtime library (/MT or /MTd
+  for release and debug builds, respectively) instead of the dynamic one.
+  Defaults to OFF.
+
 Executing the test suite
 ========================