summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorShoaib Meenai <smeenai@fb.com>2017-12-15 01:05:48 +0000
committerShoaib Meenai <smeenai@fb.com>2017-12-15 01:05:48 +0000
commit9d3546dc524277cf50ecfaca6e0be9ccd1a02b80 (patch)
tree9a4a9c058e63ce0f68634511d4a005da38cd2e0a /cmake
parent2955f15b7fc8eeed3fe7c4b3e636c185189379dc (diff)
[cmake] Fix clang-cl cross-compilation on macOS
macOS paths usually start with /Users, which clang-cl interprets as a macro undefine, leading to pretty much everything failing to compile. CMake should be taught to put a -- in its compilation rules for clang-cl (and I've been meaning to submit that upstream for a while). In the meantime, however, and to support older CMake versions, we can just create a custom make rules override to fix the compilation rules. Differential Revision: https://reviews.llvm.org/D41219 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320785 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rw-r--r--cmake/platforms/ClangClCMakeCompileRules.cmake9
-rw-r--r--cmake/platforms/WinMsvc.cmake3
2 files changed, 12 insertions, 0 deletions
diff --git a/cmake/platforms/ClangClCMakeCompileRules.cmake b/cmake/platforms/ClangClCMakeCompileRules.cmake
new file mode 100644
index 00000000000..a3bcf1c24a9
--- /dev/null
+++ b/cmake/platforms/ClangClCMakeCompileRules.cmake
@@ -0,0 +1,9 @@
+# macOS paths usually start with /Users/*. Unfortunately, clang-cl interprets
+# paths starting with /U as macro undefines, so we need to put a -- before the
+# input file path to force it to be treated as a path. CMake's compilation rules
+# should be tweaked accordingly, but until that's done, and to support older
+# CMake versions, overriding compilation rules works well enough. This file will
+# be included by cmake after the default compilation rules have already been set
+# up, so we can just modify them instead of duplicating them entirely.
+string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}")
+string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT}")
diff --git a/cmake/platforms/WinMsvc.cmake b/cmake/platforms/WinMsvc.cmake
index c4761636c92..a736a457872 100644
--- a/cmake/platforms/WinMsvc.cmake
+++ b/cmake/platforms/WinMsvc.cmake
@@ -299,3 +299,6 @@ set(CMAKE_SHARED_LINKER_FLAGS "${_CMAKE_SHARED_LINKER_FLAGS_INITIAL} ${LINK_FLAG
# control which libraries they require.
set(CMAKE_C_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
+
+# Allow clang-cl to work with macOS paths.
+set(CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_CURRENT_LIST_DIR}/ClangClCMakeCompileRules.cmake")