hintonda updated this revision to Diff 130367.
hintonda added a comment.

Refactor to eliminate need for second stage and toolchain files.


Repository:
  rC Clang

https://reviews.llvm.org/D41829

Files:
  cmake/caches/Linux.cmake

Index: cmake/caches/Linux.cmake
===================================================================
--- /dev/null
+++ cmake/caches/Linux.cmake
@@ -0,0 +1,130 @@
+# This file is primarily for cross compiling clang+llvm, et al, for
+# Linux on Darwin, and can be invoked like this:
+#
+#  cmake -GNinja -DBOOTSTRAP_CMAKE_SYSROOT=<sysroot path> [OPTIONS] \
+#    -C <clang root>/cmake/caches/Linux.cmake ../llvm
+#
+# Known issues:
+#
+#  1) This toolchain assumes a flat, mono-repo layout.
+#
+#  2) Several sub-projects, including libcxx, libcxxabi, and
+#     libunwind, use find_path() to find the source path for headers
+#     in the source directories of other sub-projects on the host
+#     system, but fail because they don't specify
+#     NO_CMAKE_FIND_ROOT_PATH.  The following patches are reqired to
+#     build these projects:
+#
+#     Patch: libcxx       https://reviews.llvm.org/D41622
+#            libcxxabi    https://reviews.llvm.org/D41623
+#            libunwind    https://reviews.llvm.org/D41621
+#
+#     Workaround: None
+#
+#  3) Stage2 configuration fails for several sub-projects which don't
+#     explicitly handle rpath correctly, including compiler-rt,
+#     libcxx, libcxxabi, and libunwind.  LLVM handles this in the
+#     llvm_setup_rpath() function in AddLLVM.cmake.
+#
+#     Patch: TBD
+#
+#     Workaround: pass -DBOOTSTRAP_CMAKE_BUILD_WITH_INSTALL_RPATH=ON
+#
+#  4) To link elf binaries on Darwin, it's necessary to pass
+#     CLANG_DEFAULT_LINKER=lld when building the compiler used in
+#     stage2.  Unfortunately, ld64.lld does not yet handle several
+#     arguments sent by clang, causing Native tool configuration to
+#     fail.  In order to prevent this, it is necessary to pass
+#     CLANG_TABLEGEN, LLVM_TABLEGEN, and LLVM_CONFIG_EXE.
+#
+#     Patch: https://reviews.llvm.org/D41806
+#
+#     Workaround: None
+#
+#  5) If CMAKE_ASM_COMPILER is set, cmake assumes
+#     CMAKE_ASM_COMPILER_ID was also set, and doesn't try to set it.
+#     Without CMAKE_ASM_COMPILER_ID, cmake can't set
+#     CMAKE_ASM_COMPILER_OPTIONS_TARGET either, which means
+#     CMAKE_ASM_COMPILER_TARGET is ignored, causing cross compiling to
+#     fail, i.e., `--target=${CMAKE_ASM_COMPILER_TARGET}` isn't
+#     passed.
+#
+#     Patch: https://reviews.llvm.org/D42232
+#
+#     Workaround: pass -DBOOTSTRAP_CMAKE_ASM_COMPILER_ID=Clang
+
+if(NOT DEFINED BOOTSTRAP_CMAKE_SYSROOT)
+  message(FATAL_ERROR "Missing required argument -DBOOTSTRAP_CMAKE_SYSROOT=<sysroot path>.")
+endif()
+
+# FIXME: Default to Linux, but should this be required?
+if(NOT DEFINED BOOTSTRAP_CMAKE_SYSTEM_NAME)
+	set(BOOTSTRAP_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
+endif()
+
+# FIXME:  Should this default be based on BOOTSTRAP_CMAKE_SYSTEM_NAME?
+if(NOT DEFINED BOOTSTRAP_LLVM_DEFAULT_BOOTSTRAP_TRIPLE)
+  set(BOOTSTRAP_LLVM_DEFAULT_BOOTSTRAP_TRIPLE "x86_64-unknown-linux-gnu")
+endif()
+
+if(NOT DEFINED BOOTSTRAP_GCC_INSTALL_PREFIX)
+  # Force clang to look for gcc at runtime -- otherwise it will
+  # default to 4.2.1.
+  set(BOOTSTRAP_GCC_INSTALL_PREFIX "/usr" CACHE STRING "")
+endif()
+
+# Allow user to pass a custom stage2 cache file.
+if(DEFINED STAGE2_CACHE_FILE)
+	list(APPEND EXTRA_ARGS -C${STAGE2_CACHE_FILE})
+endif()
+
+list(APPEND EXTRA_ARGS
+	-DCMAKE_C_COMPILER_TARGET=${BOOTSTRAP_LLVM_DEFAULT_BOOTSTRAP_TRIPLE}
+	-DCMAKE_CXX_COMPILER_TARGET=${BOOTSTRAP_LLVM_DEFAULT_BOOTSTRAP_TRIPLE}
+	-DCMAKE_ASM_COMPILER_TARGET=${BOOTSTRAP_LLVM_DEFAULT_BOOTSTRAP_TRIPLE}
+
+	# Adjust the default behaviour of the FIND_XXX() commands to only
+	# search for headers and libraries in the
+	# CMAKE_SYSROOT/CMAKE_FIND_ROOT_PATH, and always search for programs
+	# in the host system.  These all default to BOTH.
+	-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
+	-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY
+	-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
+	)
+
+set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+
+set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
+set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
+set(LLVM_INCLUDE_RUNTIMES OFF CACHE BOOL "")
+set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
+set(LLVM_INCLUDE_UTILS OFF CACHE BOOL "")
+set(CLANG_BUILD_TOOLS OFF CACHE BOOL "")
+set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
+set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
+
+# FIXME: Is there a better way to specify this? i.e., target is elf,
+# but host isn't.
+if(CMAKE_HOST_APPLE)
+  # Make sure at least clang and lld are included.
+  set(LLVM_ENABLE_PROJECTS ${LLVM_ENABLE_PROJECTS} clang lld CACHE STRING "")
+
+  # Passing -fuse-ld=lld is hard for cmake to handle correctly, so
+  # make lld the default linker.
+  set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
+
+	list(APPEND EXTRA_ARGS
+		-DLLVM_ENABLE_LLD=ON
+		-DCMAKE_AR=${CMAKE_BINARY_DIR}/bin/llvm-ar
+		-DCMAKE_RANLIB=${CMAKE_BINARY_DIR}/bin/llvm-ranlib
+		-DCLANG_TABLEGEN=${CMAKE_BINARY_DIR}/bin/clang-tblgen
+		-DLLVM_TABLEGEN=${CMAKE_BINARY_DIR}/bin/llvm-tblgen
+		-DLLVM_CONFIG_EXE=${CMAKE_BINARY_DIR}/bin/llvm-config
+		)
+
+endif()
+
+set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
+set(CLANG_BOOTSTRAP_CMAKE_ARGS ${EXTRA_ARGS} CACHE STRING "")
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to