[PATCH] D41219: [cmake] Fix clang-cl cross-compilation on macOS

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 19:49:53 PST 2017


I don’t know anything about MacOS command lines, so hopefully someone else
can comment on this
On Wed, Dec 13, 2017 at 6:57 PM Shoaib Meenai via Phabricator <
reviews at reviews.llvm.org> wrote:

> smeenai created this revision.
> smeenai added reviewers: compnerd, rnk, zturner.
> Herald added a subscriber: mgorny.
>
> 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.
>
>
> https://reviews.llvm.org/D41219
>
> Files:
>   cmake/platforms/ClangClCMakeCompileRules.cmake
>   cmake/platforms/WinMsvc.cmake
>
>
> Index: cmake/platforms/WinMsvc.cmake
> ===================================================================
> --- cmake/platforms/WinMsvc.cmake
> +++ cmake/platforms/WinMsvc.cmake
> @@ -306,3 +306,5 @@
>  # resulting warnings about missing libraries.
>  set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
>
> +# Allow clang-cl to work with macOS paths.
> +set(CMAKE_USER_MAKE_RULES_OVERRIDE
> "${CMAKE_CURRENT_LIST_DIR}/ClangClCMakeCompileRules.cmake")
> Index: cmake/platforms/ClangClCMakeCompileRules.cmake
> ===================================================================
> --- /dev/null
> +++ 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}")
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171214/e7313fd9/attachment.html>


More information about the llvm-commits mailing list