[PATCH] D109611: Fix CLANG_ENABLE_STATIC_ANALYZER=OFF building all analyzer source
Alexander Richardson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 10 10:02:36 PDT 2021
arichardson created this revision.
arichardson added reviewers: thakis, hans, tstellar.
Herald added subscribers: manas, steakhal, ASDenysPetrov, martong, dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware, mgorny.
arichardson requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.
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`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109611
Files:
clang/cmake/modules/AddClang.cmake
clang/lib/StaticAnalyzer/CMakeLists.txt
llvm/cmake/modules/AddLLVM.cmake
Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -429,10 +429,13 @@
# This is used to specify that this is a component library of
# LLVM which means that the source resides in llvm/lib/ and it is a
# candidate for inclusion into libLLVM.so.
+# EXCLUDE_FROM_ALL
+# Do not build this library as part of the default target, only
+# if explicitly requested or when linked against.
# )
function(llvm_add_library name)
cmake_parse_arguments(ARG
- "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME;NO_INSTALL_RPATH;COMPONENT_LIB"
+ "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME;NO_INSTALL_RPATH;COMPONENT_LIB;EXCLUDE_FROM_ALL"
"OUTPUT_NAME;PLUGIN_TOOL;ENTITLEMENTS;BUNDLE_PATH"
"ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
${ARGN})
@@ -535,6 +538,9 @@
# FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY.
set(ARG_STATIC)
+ if(ARG_EXCLUDE_FROM_ALL OR EXCLUDE_FROM_ALL)
+ set_target_properties(${name_static} PROPERTIES EXCLUDE_FROM_ALL ON)
+ endif()
endif()
if(ARG_MODULE)
@@ -546,6 +552,10 @@
add_library(${name} STATIC ${ALL_FILES})
endif()
+ if(ARG_EXCLUDE_FROM_ALL OR EXCLUDE_FROM_ALL)
+ set_target_properties(${name} PROPERTIES EXCLUDE_FROM_ALL ON)
+ endif()
+
if(ARG_COMPONENT_LIB)
set_target_properties(${name} PROPERTIES LLVM_COMPONENT TRUE)
set_property(GLOBAL APPEND PROPERTY LLVM_COMPONENT_LIBS ${name})
Index: clang/lib/StaticAnalyzer/CMakeLists.txt
===================================================================
--- clang/lib/StaticAnalyzer/CMakeLists.txt
+++ clang/lib/StaticAnalyzer/CMakeLists.txt
@@ -1,3 +1,10 @@
+# These directories can significantly impact build time, only build
+# them if anything depends on the clangStaticAnalyzer* libraries.
+if(NOT CLANG_ENABLE_STATIC_ANALYZER)
+ set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL ON)
+ set(EXCLUDE_FROM_ALL ON)
+endif()
+
add_subdirectory(Core)
add_subdirectory(Checkers)
add_subdirectory(Frontend)
Index: clang/cmake/modules/AddClang.cmake
===================================================================
--- clang/cmake/modules/AddClang.cmake
+++ clang/cmake/modules/AddClang.cmake
@@ -100,7 +100,12 @@
# The Xcode generator doesn't handle object libraries correctly.
list(APPEND LIBTYPE OBJECT)
endif()
- set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
+ if (NOT EXCLUDE_FROM_ALL)
+ # Only include libraries that don't have EXCLUDE_FROM_ALL set. This
+ # ensure that the clang static analyzer libraries are not compiled
+ # as part of clang-shlib if CLANG_ENABLE_STATIC_ANALYZER=OFF.
+ set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
+ endif()
endif()
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
@@ -110,6 +115,9 @@
endif()
foreach(lib ${libs})
+ if (EXCLUDE_FROM_ALL)
+ continue()
+ endif()
if(TARGET ${lib})
target_link_libraries(${lib} INTERFACE ${LLVM_COMMON_LIBS})
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109611.371944.patch
Type: text/x-patch
Size: 3218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210910/955cf6aa/attachment-0001.bin>
More information about the cfe-commits
mailing list