Fix CLANG_ENABLE_STATIC_ANALYZER=OFF building all analyzer source
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Mon, 20 Sep 2021 11:32:56 +0000 (12:32 +0100)
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Mon, 20 Sep 2021 11:55:56 +0000 (12:55 +0100)
commit6d7b3d6b3a8dbd62650b6c3dae1fe904a8ae9048
treeb2bb99d8a00e35836c93c14cebb24cd0870c9c47
parent7fc12b822c5d1360780667af94c218733c3fc4e0
Fix CLANG_ENABLE_STATIC_ANALYZER=OFF building all analyzer source

Since https://reviews.llvm.org/D87118, the StaticAnalyzer directory is
added unconditionally. In theory this should not cause the static analyzer
sources to be built unless they are referenced by another target. However,
the clang-cpp target (defined in clang/tools/clang-shlib) uses the
CLANG_STATIC_LIBS global property to determine which libraries need to
be included. To solve this issue, this patch avoids adding libraries to
that property if EXCLUDE_FROM_ALL is set.

In case something like this comes up again: `cmake --graphviz=targets.dot`
is quite useful to see why a target is included as part of `ninja all`.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D109611
clang/cmake/modules/AddClang.cmake
clang/lib/StaticAnalyzer/CMakeLists.txt
llvm/cmake/modules/AddLLVM.cmake