Skip to content

Commit df0ba47

Browse files
committed
[Support] Allow configuring the preferred type of slashes on Windows
Default to preferring forward slashes when built for MinGW, as many usecases, when e.g. Clang is used as a drop-in replacement for GCC, requires the compiler to output paths with forward slashes. Not all tests pass yet, if configuring to prefer forward slashes though. Differential Revision: https://reviews.llvm.org/D112787
1 parent f4d83c5 commit df0ba47

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

llvm/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,14 @@ endif()
359359

360360
option(LLVM_ENABLE_CRASH_DUMPS "Turn on memory dumps on crashes. Currently only implemented on Windows." OFF)
361361

362+
set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT OFF)
363+
if (MINGW)
364+
# Cygwin doesn't identify itself as Windows, and thus gets path::Style::posix
365+
# as native path style, regardless of what this is set to.
366+
set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT ON)
367+
endif()
368+
option(LLVM_WINDOWS_PREFER_FORWARD_SLASH "Prefer path names with forward slashes on Windows." ${WINDOWS_PREFER_FORWARD_SLASH_DEFAULT})
369+
362370
option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
363371
set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
364372
set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")

llvm/include/llvm/Config/config.h.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
/* Define to 1 to enable crash memory dumps, and to 0 otherwise. */
2020
#cmakedefine01 LLVM_ENABLE_CRASH_DUMPS
2121

22+
/* Define to 1 to prefer forward slashes on Windows, and to 0 prefer
23+
backslashes. */
24+
#cmakedefine01 LLVM_WINDOWS_PREFER_FORWARD_SLASH
25+
2226
/* Define to 1 if you have the `backtrace' function. */
2327
#cmakedefine HAVE_BACKTRACE ${HAVE_BACKTRACE}
2428

llvm/lib/Support/Path.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "llvm/Support/Path.h"
1414
#include "llvm/ADT/ArrayRef.h"
15+
#include "llvm/Config/config.h"
1516
#include "llvm/Config/llvm-config.h"
1617
#include "llvm/Support/Endian.h"
1718
#include "llvm/Support/Errc.h"
@@ -41,7 +42,8 @@ namespace {
4142
return style;
4243
if (is_style_posix(style))
4344
return Style::posix;
44-
return Style::windows;
45+
return LLVM_WINDOWS_PREFER_FORWARD_SLASH ? Style::windows_slash
46+
: Style::windows_backslash;
4547
}
4648

4749
inline const char *separators(Style style) {

0 commit comments

Comments
 (0)