[cmake] Support LLVM external project build

This makes it possible to build IWYU as part of LLVM using the
LLVM_EXTERNAL_PROJECTS feature of the LLVM build system.

Add separate instructions for this build mode to README.

Based on original patch from @bc-lee:
https://github.com/include-what-you-use/include-what-you-use/pull/994
This commit is contained in:
Kim Gräsman 2022-02-28 20:50:38 +01:00
parent 59509beca4
commit 3a793604c1
2 changed files with 25 additions and 7 deletions

View File

@ -22,6 +22,18 @@ if (iwyu_standalone_build)
list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})
include(AddLLVM)
include(HandleLLVMOptions)
set(iwyu_include_dirs
${LLVM_INCLUDE_DIRS}
${CLANG_INCLUDE_DIRS}
)
else()
set(iwyu_include_dirs
${LLVM_SOURCE_DIR}/include
${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include
${LLVM_BINARY_DIR}/include
${LLVM_BINARY_DIR}/tools/clang/include
)
endif()
message(STATUS "IWYU: configuring for LLVM ${LLVM_VERSION}...")
@ -118,8 +130,7 @@ target_compile_definitions(include-what-you-use PRIVATE
IWYU_GIT_REV="${iwyu_git_rev}"
)
target_include_directories(include-what-you-use PRIVATE
${LLVM_INCLUDE_DIRS}
${CLANG_INCLUDE_DIRS}
${iwyu_include_dirs}
)
if (MINGW)

View File

@ -52,11 +52,9 @@ We also have convenience tags and branches for released versions of Clang (calle
>
> Packaging for other platforms will likely be subtly different.
### How to build ###
### How to build standalone ###
We assume you already have compiled LLVM and Clang libraries on your system, either via packages for your platform or built from source.
To set up an environment for building:
This build mode assumes you already have compiled LLVM and Clang libraries on your system, either via packages for your platform or built from source. To set up an environment for building IWYU:
* Create a directory for IWYU development, e.g. `iwyu`
@ -91,7 +89,16 @@ To set up an environment for building:
iwyu/build$ make
Instructions for building Clang are available at <https://clang.llvm.org/get_started.html>.
### How to build as part of LLVM ###
Instructions for building LLVM and Clang are available at <https://clang.llvm.org/get_started.html>.
To include IWYU in the LLVM build, use the `LLVM_EXTERNAL_PROJECTS` and `LLVM_EXTERNAL_*_SOURCE_DIR` CMake variables when configuring LLVM:
llvm-project/build$ cmake -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS=clang -DLLVM_EXTERNAL_PROJECTS=iwyu -DLLVM_EXTERNAL_IWYU_SOURCE_DIR=/path/to/iwyu /path/to/llvm-project/llvm
llvm-project/build$ make
This builds all of LLVM, Clang and IWYU in a single tree.
### How to install ###