summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorShoaib Meenai <smeenai@fb.com>2019-07-11 21:20:38 +0000
committerShoaib Meenai <smeenai@fb.com>2019-07-11 21:20:38 +0000
commitf90a391b76e51e3bbcc071d2d0f1f2bac45a08d3 (patch)
treec3644d89ce1c5121eb98b3a4da39a1816f2940d9 /tools
parentb0978dd75c68e5f940737cff71fdd363273ac498 (diff)
downloadclang-f90a391b76e51e3bbcc071d2d0f1f2bac45a08d3.tar.gz
[clang-shlib] Fix clang-shlib for PRIVATE dependencies
Any static library with a PRIVATE dependency ends up with a $<LINK_ONLY:...> generator expression in its INTERFACE_LINK_LIBRARIES, which won't be evaluated by the $<TARGET_PROPERTY:...>, so we end up with an unevaluated generator expression in the generated build file and Ninja chokes on the dollar sign. Just use the static library directly for its dependencies instead of trying to propagate dependencies manually. Differential Revision: https://reviews.llvm.org/D64579 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365825 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/clang-shlib/CMakeLists.txt31
1 files changed, 29 insertions, 2 deletions
diff --git a/tools/clang-shlib/CMakeLists.txt b/tools/clang-shlib/CMakeLists.txt
index 162a935301..313598a092 100644
--- a/tools/clang-shlib/CMakeLists.txt
+++ b/tools/clang-shlib/CMakeLists.txt
@@ -7,8 +7,35 @@ get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
foreach (lib ${clang_libs})
list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>)
- list(APPEND _DEPS $<TARGET_PROPERTY:${lib},INTERFACE_LINK_LIBRARIES>)
- list(APPEND _DEPS $<TARGET_PROPERTY:${lib},LINK_LIBRARIES>)
+ # Use the static library for its dependencies. The objects that constitute the
+ # static library will appear on the link line before the library, so it'll
+ # just be ignored, but the dependencies of the library will still be linked
+ # correctly.
+ #
+ # We could propagate the dependencies manually using the library's
+ # INTERFACE_LINK_LIBRARIES property, but that will contain $<LINK_ONLY:...>
+ # generator expressions if a static library has a private dependency, so we
+ # can't use a $<TARGET_PROPERTY:...> generator expression to get the property
+ # (since it wouldn't evaluate any generator expressions inside the property).
+ # We could use get_property and do string manipulation to manually evaluate
+ # the $<LINK_ONLY:...>, but that would miss any dependencies added after we
+ # evaluate the get_property. We could also use the LINK_LIBRARIES property
+ # instead, which should be free of any generator expressions, but that's
+ # technically incorrect (it'd most likely work fine in practice, but still).
+ #
+ # Another alternative would be to use --whole-archive or equivalent instead of
+ # using the object library at all. However, CMake reorders static libraries on
+ # the link line so that a library appears after all its dependents, which can
+ # reorder static libraries out of their --whole-archive --no-whole-archive
+ # sandwich. It's really hard to avoid that reordering while still propagating
+ # dependencies, which defeats the whole point.
+ #
+ # The ideal solution here is to bump our minimum CMake requirement to 3.12,
+ # which adds support for dependencies on object libraries. Until then, linking
+ # both the object and the static libraries seems like the least bad solution.
+ #
+ # TODO: Rework this when we bump our minimum CMake version to 3.12 or newer.
+ list(APPEND _DEPS ${lib})
endforeach ()
add_clang_library(clang_shared