[PATCH] Use a sufficiently current MSVCRT when using MinGW

Johannes S. Mueller-Roemer johannes.sebastian.mueller-roemer at igd.fraunhofer.de
Wed Jan 28 01:52:11 PST 2015


The patch finds all installed MSVCRT versions from 11.0 (highest currently supported by MinGW) down to 9.0 and sets the appropriate compiler and linker flags for the newest version found. An installed MSVCRT is required due to the call to llvm-tblgen at build time.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D7224

Files:
  CMakeLists.txt

Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -542,6 +542,32 @@
   # People report that -O3 is unreliable on MinGW. The traditional
   # build also uses -O2 for that reason:
   llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
+
+  # _set_abort_behavior requires an MSVCRT version >= 9.0
+  # as llvm-tblgen is called during the build process only installed
+  # MSVCRT versions should be used
+  function(get_newest_msvcrt OUTVAR)
+    file(TO_CMAKE_PATH $ENV{WINDIR} WINDIR)
+    file(GLOB INSTALLED_MSVCRT_RUNTIMES "${WINDIR}/System32/msvcr*.dll")
+    set(INSTALLED_MSVCRT_NAMES)
+    foreach(MSVCRT ${INSTALLED_MSVCRT_RUNTIMES})
+      get_filename_component(MSVCRT ${MSVCRT} NAME_WE)
+      list(APPEND INSTALLED_MSVCRT_NAMES ${MSVCRT})
+    endforeach()
+    foreach(VERSION 110 100 90) # try newest first
+      list(FIND INSTALLED_MSVCRT_NAMES "msvcr${VERSION}" INDEX)
+      if(INDEX GREATER -1)
+        set(${OUTVAR} ${VERSION} PARENT_SCOPE)
+        return()
+        endif()
+    endforeach()
+    message(FATAL_ERROR "No compatible MSVCRT runtime installed")
+  endfunction()
+  get_newest_msvcrt(NEWEST_MSVCRT)
+  foreach(LANG C CXX)
+    set(CMAKE_${LANG}_FLAGS "${CMAKE_${LANG}_FLAGS} -D__MSVCRT_VERSION__=0x${NEWEST_MSVCRT}0")
+    set(CMAKE_${LANG}_STANDARD_LIBRARIES "${CMAKE_${LANG}_STANDARD_LIBRARIES} -lmsvcr${NEWEST_MSVCRT}")
+  endforeach()
 endif()
 
 # Put this before tblgen. Else we have a circular dependence.

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7224.18879.patch
Type: text/x-patch
Size: 1542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150128/491986c0/attachment.bin>


More information about the llvm-commits mailing list