diff options
Diffstat (limited to 'tools/llvm-config/llvm-config.cpp')
-rw-r--r-- | tools/llvm-config/llvm-config.cpp | 85 |
1 files changed, 56 insertions, 29 deletions
diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp index 3924e2e..ed1c8c3 100644 --- a/tools/llvm-config/llvm-config.cpp +++ b/tools/llvm-config/llvm-config.cpp @@ -20,6 +20,7 @@ #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" @@ -147,6 +148,7 @@ Options:\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 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\ @@ -154,6 +156,7 @@ Options:\n\ --targets-built List of all targets currently built.\n\ --host-target Target triple used to configure LLVM.\n\ --build-mode Print build mode of LLVM tree (e.g. Debug or Release).\n\ + --assertion-mode Print assertion mode of LLVM tree (ON or OFF).\n\ Typical components:\n\ all All LLVM libraries (default).\n\ engine Either a native JIT or a bitcode interpreter.\n"; @@ -171,6 +174,7 @@ std::string GetExecutablePath(const char *Argv0) { int main(int argc, char **argv) { std::vector<StringRef> Components; bool PrintLibs = false, PrintLibNames = false, PrintLibFiles = false; + bool PrintSystemLibs = false; bool HasAnyOption = false; // llvm-config is designed to support being run both from a development tree @@ -183,6 +187,13 @@ int main(int argc, char **argv) { std::string CurrentExecPrefix; std::string ActiveObjRoot; + // If CMAKE_CFG_INTDIR is given, honor it as build mode. + char const *build_mode = LLVM_BUILDMODE; +#if defined(CMAKE_CFG_INTDIR) + if (!(CMAKE_CFG_INTDIR[0] == '.' && CMAKE_CFG_INTDIR[1] == '\0')) + build_mode = CMAKE_CFG_INTDIR; +#endif + // Create an absolute path, and pop up one directory (we expect to be inside a // bin dir). sys::fs::make_absolute(CurrentPath); @@ -192,7 +203,7 @@ int main(int argc, char **argv) { // 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; @@ -230,16 +241,18 @@ int main(int argc, char **argv) { // 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"; break; case CMakeStyle: ActiveBinDir = ActiveObjRoot + "/bin"; ActiveLibDir = ActiveObjRoot + "/lib"; break; case CMakeBuildModeStyle: - ActiveBinDir = ActiveObjRoot + "/bin/" + LLVM_BUILDMODE; - ActiveLibDir = ActiveObjRoot + "/lib/" + LLVM_BUILDMODE; + ActivePrefix = ActiveObjRoot; + ActiveBinDir = ActiveObjRoot + "/bin/" + build_mode; + ActiveLibDir = ActiveObjRoot + "/lib/" + build_mode; break; } @@ -277,8 +290,9 @@ int main(int argc, char **argv) { } else if (Arg == "--cxxflags") { OS << ActiveIncludeOption << ' ' << LLVM_CXXFLAGS << '\n'; } else if (Arg == "--ldflags") { - OS << "-L" << ActiveLibDir << ' ' << LLVM_LDFLAGS - << ' ' << LLVM_SYSTEM_LIBS << '\n'; + OS << "-L" << ActiveLibDir << ' ' << LLVM_LDFLAGS << '\n'; + } else if (Arg == "--system-libs") { + PrintSystemLibs = true; } else if (Arg == "--libs") { PrintLibs = true; } else if (Arg == "--libnames") { @@ -298,11 +312,17 @@ int main(int argc, char **argv) { } 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 << LLVM_BUILDMODE << '\n'; + OS << build_mode << '\n'; + } else if (Arg == "--assertion-mode") { +#if defined(NDEBUG) + OS << "OFF\n"; +#else + 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 { @@ -316,7 +336,7 @@ int main(int argc, char **argv) { if (!HasAnyOption) usage(); - if (PrintLibs || PrintLibNames || PrintLibFiles) { + if (PrintLibs || PrintLibNames || PrintLibFiles || PrintSystemLibs) { // If no components were specified, default to "all". if (Components.empty()) Components.push_back("all"); @@ -326,27 +346,34 @@ int main(int argc, char **argv) { 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) { + for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) { + StringRef Lib = RequiredLibs[i]; + if (i) + OS << ' '; - // Otherwise, print the full path. - OS << ActiveLibDir << '/' << Lib; + 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; + } + + // 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. + if (PrintSystemLibs) + OS << LLVM_SYSTEM_LIBS << '\n'; } else if (!Components.empty()) { errs() << "llvm-config: error: components given, but unused\n\n"; usage(); |