From df0ba47c36f6bd0865e3286853b76d37e037c2d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Storsj=C3=B6?= Date: Wed, 13 Oct 2021 12:18:32 +0000 Subject: [PATCH] [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 --- llvm/CMakeLists.txt | 8 ++++++++ llvm/include/llvm/Config/config.h.cmake | 4 ++++ llvm/lib/Support/Path.cpp | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index f07f29a..d3fb7dc 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -359,6 +359,14 @@ endif() 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) + # Cygwin doesn't identify itself as Windows, and thus gets path::Style::posix + # as native path style, regardless of what this is set to. + 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") diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake index 37a0d23..1d982b5 100644 --- a/llvm/include/llvm/Config/config.h.cmake +++ b/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} diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index cea6df8..3957547 100644 --- a/llvm/lib/Support/Path.cpp +++ b/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" @@ -41,7 +42,8 @@ namespace { return style; if (is_style_posix(style)) return Style::posix; - return Style::windows; + return LLVM_WINDOWS_PREFER_FORWARD_SLASH ? Style::windows_slash + : Style::windows_backslash; } inline const char *separators(Style style) { -- 2.7.4