This is an archive of the discontinued LLVM Phabricator instance.

Simplify cross-compilation. Don't use native-compiled llvm-config.
Needs ReviewPublic

Authored by garious on Mar 28 2014, 1:26 PM.

Details

Reviewers
samsonov
eugenis
Summary

Simplify cross-compilation. Don't use native-compiled llvm-config. Instead use CMake's find_package() feature. This assumes CMAKE_PREFIX_PATH contains a path to the LLVM install directory.

Note: AddLLVM.cmake does not expose the LLVM source directory.

So if you want to run the test suite, you need to either:

1) set LLVM_MAIN_SRC_DIR explicitly (to find lit.py)
2) change AddLLVM.cmake to point to an installed 'lit'.
3) add_subdirectory(compiler-rt/test) from clang instead of compiler-rt.

Diff Detail

Event Timeline

Could you please describe the full suggested workflow? Is this a replacement of LLVM_BUILD_EXTERNAL_COMPILER_RT option and the code added for it in tools/clang/runtime/CMakeLists.txt? I.e., if we land this change, what is the sequence of commands one should write to use just-built Clang to build compiler-rt libs?

CMakeLists.txt
81

Will this work for multi-configuration build systems (the ones that can build Debug and Release binaries in a single build tree)?

The change is meant to be independent of LLVM_BUILD_EXTERNAL_COMPILER_RT. For that build, in "clang/runtime/CMakeLists.txt", use:

-DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}

instead of:

-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config

But doing that only works when the CMAKE_BINARY_DIR is the same for both the clang and llvm builds. That happens to be true for your build, but locally, I build clang against the llvm install directory using the same LLVM_PREFIX_PATH technique.

I don't use LLVM_BUILD_EXTERNAL_COMPILER_RT. Instead I have a custom little package manager that points each standalone build to its dependencies. If you don't have a package manager, you can get by with a Bash script similar to:

mkdir -p llvm/out && cd llvm/out
cmake .. -DCMAKE_INSTALL_PREFIX=ship
ninja check-all install
cd -

mkdir -p compiler-rt/out && cd compiler-rt/out
cmake .. -DCMAKE_PREFIX_PATH=`pwd`/../../llvm/out/ship

-DCMAKE_INSTALL_PREFIX=ship

ninja check-all install
cd -

mkdir -p clang/out && cd clang/out
cmake ..  -DCMAKE_PREFIX_PATH=`pwd`/../../llvm/out/ship:`pwd`/../../compiler-rt/out/ship

-DCMAKE_INSTALL_PREFIX=ship

ninja check-all install
cd -
CMakeLists.txt
81

Yes. There can be a single build tree with a separate install directory for each build variant of each component. Locally, my directory structure contains two top-level directories: 'llvm' and 'compiler-rt'. Within each of those directories are build directories: "out/release" and "out/debug". Within each of those directories is a 'ship' directory, which the 'install' step copies files to. So, for example, in the Release build of compiler-rt, LLVM_INSTALL_PREFIX points to "llvm/out/release/ship".