[PATCH] D112787: [Support] Allow configuring the preferred type of slashes on Windows

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 29 02:08:15 PDT 2021


mstorsjo created this revision.
mstorsjo added reviewers: rnk, thakis, dexonsmith.
Herald added subscribers: hiraditya, mgorny.
mstorsjo requested review of this revision.
Herald added a project: LLVM.

Later we might want to make it settable at runtime - but even then,
we want to be able to set what the built-in default should be.

Default to preferring forward slashes when built for MinGW.

Not all tests pass yet, if configuring to prefer forward slashes though.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112787

Files:
  llvm/CMakeLists.txt
  llvm/include/llvm/Config/config.h.cmake
  llvm/lib/Support/Path.cpp


Index: llvm/lib/Support/Path.cpp
===================================================================
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Support/Path.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/Config/config.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Errc.h"
@@ -40,7 +41,8 @@
     if (style == Style::native) {
       if (is_style_posix(style))
         return Style::posix;
-      return Style::windows;
+      return LLVM_WINDOWS_PREFER_FORWARD_SLASH ? Style::windows_slash
+                                               : Style::windows_backslash;
     }
     return style;
   }
Index: llvm/include/llvm/Config/config.h.cmake
===================================================================
--- llvm/include/llvm/Config/config.h.cmake
+++ llvm/include/llvm/Config/config.h.cmake
@@ -19,6 +19,10 @@
 /* Define to 1 to enable crash memory dumps, and to 0 otherwise. */
 #cmakedefine01 LLVM_ENABLE_CRASH_DUMPS
 
+/* Define to 1 to prefer forward slashes on Windows, and to 0 prefer
+   backslashes. */
+#cmakedefine01 LLVM_WINDOWS_PREFER_FORWARD_SLASH
+
 /* Define to 1 if you have the `backtrace' function. */
 #cmakedefine HAVE_BACKTRACE ${HAVE_BACKTRACE}
 
Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -353,6 +353,12 @@
 
 option(LLVM_ENABLE_CRASH_DUMPS "Turn on memory dumps on crashes. Currently only implemented on Windows." OFF)
 
+set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT OFF)
+if (MINGW)
+  set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT ON)
+endif()
+option(LLVM_WINDOWS_PREFER_FORWARD_SLASH "Prefer path names with forward slashes on Windows." ${WINDOWS_PREFER_FORWARD_SLASH_DEFAULT})
+
 option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
 set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
 set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112787.383264.patch
Type: text/x-patch
Size: 2120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211029/701490cd/attachment.bin>


More information about the llvm-commits mailing list