#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Config/config.h"
#include "llvm/Config/llvm-config.h"
/// are required to link the given components.
/// \param IncludeNonInstalled - Whether non-installed components should be
/// reported.
-void ComputeLibsForComponents(const std::vector<StringRef> &Components,
- std::vector<StringRef> &RequiredLibs,
- bool IncludeNonInstalled) {
+static void ComputeLibsForComponents(const std::vector<StringRef> &Components,
+ std::vector<StringRef> &RequiredLibs,
+ bool IncludeNonInstalled) {
std::set<AvailableComponent*> VisitedComponents;
// Build a map of component names to information.
/* *** */
-void usage() {
+static void usage() {
errs() << "\
usage: llvm-config <OPTION>... [<COMPONENT>...]\n\
\n\
--cflags C compiler flags for files that include LLVM headers.\n\
--cxxflags C++ compiler flags for files that include LLVM headers.\n\
--ldflags Print Linker flags.\n\
- --system-libs Sytem Libraries needed to link against LLVM components.\n\
+ --system-libs System Libraries needed to link against LLVM components.\n\
--libs Libraries needed to link against LLVM components.\n\
--libnames Bare library names for in-tree builds.\n\
--libfiles Fully qualified library filenames for makefile depends.\n\
// Check to see if we are inside a development tree by comparing to possible
// locations (prefix style or CMake style).
if (sys::fs::equivalent(CurrentExecPrefix,
- Twine(LLVM_OBJ_ROOT) + "/" + LLVM_BUILDMODE)) {
+ Twine(LLVM_OBJ_ROOT) + "/" + build_mode)) {
IsInDevelopmentTree = true;
DevelopmentTreeLayout = MakefileStyle;
// layout.
switch (DevelopmentTreeLayout) {
case MakefileStyle:
- ActiveBinDir = ActiveObjRoot + "/" + LLVM_BUILDMODE + "/bin";
- ActiveLibDir = ActiveObjRoot + "/" + LLVM_BUILDMODE + "/lib";
+ ActivePrefix = ActiveObjRoot;
+ ActiveBinDir = ActiveObjRoot + "/" + build_mode + "/bin";
+ ActiveLibDir =
+ ActiveObjRoot + "/" + build_mode + "/lib" + LLVM_LIBDIR_SUFFIX;
break;
case CMakeStyle:
ActiveBinDir = ActiveObjRoot + "/bin";
- ActiveLibDir = ActiveObjRoot + "/lib";
+ ActiveLibDir = ActiveObjRoot + "/lib" + LLVM_LIBDIR_SUFFIX;
break;
case CMakeBuildModeStyle:
ActivePrefix = ActiveObjRoot;
ActiveBinDir = ActiveObjRoot + "/bin/" + build_mode;
- ActiveLibDir = ActiveObjRoot + "/lib/" + build_mode;
+ ActiveLibDir =
+ ActiveObjRoot + "/lib" + LLVM_LIBDIR_SUFFIX + "/" + build_mode;
break;
}
ActivePrefix = CurrentExecPrefix;
ActiveIncludeDir = ActivePrefix + "/include";
ActiveBinDir = ActivePrefix + "/bin";
- ActiveLibDir = ActivePrefix + "/lib";
+ ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
ActiveIncludeOption = "-I" + ActiveIncludeDir;
}
} else if (Arg == "--targets-built") {
OS << LLVM_TARGETS_BUILT << '\n';
} else if (Arg == "--host-target") {
- OS << LLVM_DEFAULT_TARGET_TRIPLE << '\n';
+ OS << Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE) << '\n';
} else if (Arg == "--build-mode") {
OS << build_mode << '\n';
} else if (Arg == "--assertion-mode") {
OS << "ON\n";
#endif
} else if (Arg == "--obj-root") {
- OS << LLVM_OBJ_ROOT << '\n';
+ OS << ActivePrefix << '\n';
} else if (Arg == "--src-root") {
OS << LLVM_SRC_ROOT << '\n';
} else {
ComputeLibsForComponents(Components, RequiredLibs,
/*IncludeNonInstalled=*/IsInDevelopmentTree);
- for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {
- StringRef Lib = RequiredLibs[i];
- if (i)
- OS << ' ';
-
- if (PrintLibNames) {
- OS << Lib;
- } else if (PrintLibFiles) {
- 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 (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)
+ OS << ' ';
+
+ if (PrintLibNames) {
+ OS << Lib;
+ } else if (PrintLibFiles) {
+ OS << ActiveLibDir << '/' << Lib;
+ } else if (PrintLibs) {
+ // If this is a typical library name, include it using -l.
+ 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;
+ }
- // Otherwise, print the full path.
- OS << ActiveLibDir << '/' << Lib;
+ // Otherwise, print the full path.
+ OS << ActiveLibDir << '/' << Lib;
+ }
}
+ OS << '\n';
}
- OS << '\n';
// Print SYSTEM_LIBS after --libs.
// FIXME: Each LLVM component may have its dependent system libs.