diff options
author | JF Bastien <jfb@google.com> | 2015-07-27 18:26:30 +0000 |
---|---|---|
committer | JF Bastien <jfb@google.com> | 2015-07-27 18:26:30 +0000 |
commit | ba70e9e1e63d88f09403e2643421d1baaed4de41 (patch) | |
tree | dd9fafe0461e134df1b0da01d93fb2baca299c6b /llvm/tools/llvm-config/llvm-config.cpp | |
parent | 83934d3915f20347d9b8d916be40506beb752459 (diff) | |
download | bcm5719-llvm-ba70e9e1e63d88f09403e2643421d1baaed4de41.tar.gz bcm5719-llvm-ba70e9e1e63d88f09403e2643421d1baaed4de41.zip |
Fix `llvm-config` to emit the linker flag for the combined shared object built by autoconfig/make instead of the individual components.
Summary:
When LLVM is configured to build shared libraries, CMake builds each component as it's own shared object, while autoconfig/make builds them statically and then links them all together to create a single shared object. This change adds compile time config flags to `llvm-config` so it can know whether LLVM's components are separated or not and act accordingly.
This fixes `llvm-config` instead of fixing the makefiles to behave like CMake because, AIUI, LLVM's autoconfig/make build system is on the way out anyway.
This change only affects `llvm-config` from builds that use autoconfig/make.
Reviewers: jfb
Subscribers: echristo, dschuff, llvm-commits
Differential Revision: http://reviews.llvm.org/D11392
llvm-svn: 243297
Diffstat (limited to 'llvm/tools/llvm-config/llvm-config.cpp')
-rw-r--r-- | llvm/tools/llvm-config/llvm-config.cpp | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/llvm/tools/llvm-config/llvm-config.cpp b/llvm/tools/llvm-config/llvm-config.cpp index 879b9ab0945..c007d71baf1 100644 --- a/llvm/tools/llvm-config/llvm-config.cpp +++ b/llvm/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` is `OFF` and `BUILD_SHARED_LIBS` is `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,8 +384,23 @@ 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); + if (Lib.startswith("lib")) { + size_t FromEnd = 0; + if (Lib.endswith(".a")) { + FromEnd = 2; + } else if (Lib.endswith(".so")) { + FromEnd = 3; + } else if (Lib.endswith(".dylib")) { + FromEnd = 6; + } else { + FromEnd = 0; + } + + if (FromEnd != 0) { + OS << "-l" << Lib.slice(3, Lib.size() - FromEnd); + } else { + OS << "-l:" << Lib; + } continue; } |