Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: tools/llvm-config/llvm-config.cpp

Issue 1196003003: Make `llvm-config` detect whether or not LLVM is a shared library. If it is, then only try to link … (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Review changes. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/llvm-config/Makefile ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/llvm-config/llvm-config.cpp
diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
index 879b9ab0945ba64235584f2d1e2652bff8bc7c23..012884c971680e23582ae93c0101f4e21f66f6df 100644
--- a/tools/llvm-config/llvm-config.cpp
+++ b/tools/llvm-config/llvm-config.cpp
@@ -349,6 +349,30 @@ int main(int argc, char **argv) {
/*IncludeNonInstalled=*/IsInDevelopmentTree);
if (PrintLibs || PrintLibNames || PrintLibFiles) {
+ // If LLVM was built as a shared library, there will be only one thing
+ // that users should link against.
+ const bool IsSharedLib = (std::strcmp(BUILD_SHARED_LIBS, "ON") == 0);
+ const bool WasBuiltWithCMake = (std::strcmp(WAS_BUILT_WITH_CMAKE, "ON") == 0);
+ // CMake correctly builds components as separate shared libraries, however
+ // autoconfig/make builds components a static libraries and then links
+ // them all together to form a single shared library. Thus, only when
+ // `WAS_BUILT_WITH_CMAKE` and `BUILD_SHARED_LIBS` are `ON` do we override
+ // `RequiredLibs` with the single library name.
+ if (IsSharedLib && !WasBuiltWithCMake) {
+ RequiredLibs.clear();
+ std::string Name = "libLLVM-" PACKAGE_VERSION;
+ const Triple HostTriple(LLVM_DEFAULT_TARGET_TRIPLE);
+ if (HostTriple.isOSWindows()) {
+ Name += ".dll";
+ } else if (HostTriple.isOSDarwin()) {
+ Name += ".dylib";
+ } else {
+ // default to linux' ext:
+ Name += ".so";
+ }
+ RequiredLibs.push_back(Name);
+ }
+
for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {
StringRef Lib = RequiredLibs[i];
if (i)
@@ -360,9 +384,22 @@ int main(int argc, char **argv) {
OS << ActiveLibDir << '/' << Lib;
} else if (PrintLibs) {
// If this is a typical library name, include it using -l.
- if (Lib.startswith("lib") && Lib.endswith(".a")) {
- OS << "-l" << Lib.slice(3, Lib.size()-2);
- continue;
+ if (Lib.startswith("lib")) {
+ size_t FromEnd = 0;
+ do {
+ if (Lib.endswith(".a")) {
+ FromEnd = 2;
+ } else if (Lib.endswith(".so")) {
+ FromEnd = 3;
+ } else if (Lib.endswith(".dylib")) {
+ FromEnd = 6;
+ } else {
+ FromEnd = 0;
+ break;
+ }
+ OS << "-l" << Lib.slice(3, Lib.size() - FromEnd);
+ } while(false);
+ if (FromEnd != 0) { continue; }
}
// Otherwise, print the full path.
« no previous file with comments | « tools/llvm-config/Makefile ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698