[llvm] r320785 - [cmake] Fix clang-cl cross-compilation on macOS

Shoaib Meenai via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 17:05:48 PST 2017


Author: smeenai
Date: Thu Dec 14 17:05:48 2017
New Revision: 320785

URL: http://llvm.org/viewvc/llvm-project?rev=320785&view=rev
Log:
[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

Added:
    llvm/trunk/cmake/platforms/ClangClCMakeCompileRules.cmake
Modified:
    llvm/trunk/cmake/platforms/WinMsvc.cmake

Added: llvm/trunk/cmake/platforms/ClangClCMakeCompileRules.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/platforms/ClangClCMakeCompileRules.cmake?rev=320785&view=auto
==============================================================================
--- llvm/trunk/cmake/platforms/ClangClCMakeCompileRules.cmake (added)
+++ llvm/trunk/cmake/platforms/ClangClCMakeCompileRules.cmake Thu Dec 14 17:05:48 2017
@@ -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}")

Modified: llvm/trunk/cmake/platforms/WinMsvc.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/platforms/WinMsvc.cmake?rev=320785&r1=320784&r2=320785&view=diff
==============================================================================
--- llvm/trunk/cmake/platforms/WinMsvc.cmake (original)
+++ llvm/trunk/cmake/platforms/WinMsvc.cmake Thu Dec 14 17:05:48 2017
@@ -299,3 +299,6 @@ set(CMAKE_SHARED_LINKER_FLAGS "${_CMAKE_
 # 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")




More information about the llvm-commits mailing list