Index: tools/llvm-config/BuildVariables.inc.in =================================================================== --- tools/llvm-config/BuildVariables.inc.in +++ tools/llvm-config/BuildVariables.inc.in @@ -29,5 +29,7 @@ #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" #define LLVM_HAS_RTTI "@LLVM_HAS_RTTI@" #define LLVM_ENABLE_DYLIB "@LLVM_BUILD_LLVM_DYLIB@" +#define LLVM_LINK_DYLIB "@LLVM_LINK_LLVM_DYLIB@" #define LLVM_ENABLE_SHARED "@LLVM_ENABLE_SHARED@" #define LLVM_DYLIB_COMPONENTS "@LLVM_DYLIB_COMPONENTS@" +#define LLVM_DYLIB_VERSION "@LLVM_DYLIB_VERSION@" Index: tools/llvm-config/CMakeLists.txt =================================================================== --- tools/llvm-config/CMakeLists.txt +++ tools/llvm-config/CMakeLists.txt @@ -26,6 +26,7 @@ set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}") set(LLVM_BUILD_SYSTEM cmake) set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI}) +set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX}") # Use the C++ link flags, since they should be a superset of C link flags. set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}") Index: tools/llvm-config/Makefile =================================================================== --- tools/llvm-config/Makefile +++ tools/llvm-config/Makefile @@ -44,6 +44,8 @@ LLVM_HAS_RTTI := YES endif +LLVM_DYLIB_VERSION := $(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR)$(LLVM_VERSION_SUFFIX) + # This is blank for now. We need to be careful about adding stuff here: # LDFLAGS tend not to be portable, and we don't currently require the # user to use libtool when linking against LLVM. @@ -83,6 +85,8 @@ >> temp.sed $(Verb) $(ECHO) 's/@LLVM_HAS_RTTI@/$(LLVM_HAS_RTTI)/' \ >> temp.sed + $(Verb) $(ECHO) 's/@LLVM_DYLIB_VERSION@/$(LLVM_DYLIB_VERSION)/' \ + >> temp.sed $(Verb) $(SED) -f temp.sed < $< > $@ $(Verb) $(RM) temp.sed Index: tools/llvm-config/llvm-config.cpp =================================================================== --- tools/llvm-config/llvm-config.cpp +++ tools/llvm-config/llvm-config.cpp @@ -179,6 +179,8 @@ --build-system Print the build system used to build LLVM (autoconf or cmake).\n\ --has-rtti Print whether or not LLVM was built with rtti (YES or NO).\n\ --shared-mode Print how the provided components can be collectively linked (`shared` or `static`).\n\ + --link-shared Link the components as a shared library.\n\ + --link-static Link the components as a static libraries.\n\ Typical components:\n\ all All LLVM libraries (default).\n\ engine Either a native JIT or a bitcode interpreter.\n"; @@ -327,21 +329,21 @@ const Triple HostTriple(Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE)); if (HostTriple.isOSWindows()) { SharedExt = "dll"; - SharedVersionedExt = PACKAGE_VERSION ".dll"; + SharedVersionedExt = LLVM_DYLIB_VERSION ".dll"; StaticExt = "a"; SharedDir = ActiveBinDir; StaticDir = ActiveLibDir; StaticPrefix = SharedPrefix = "lib"; } else if (HostTriple.isOSDarwin()) { SharedExt = "dylib"; - SharedVersionedExt = PACKAGE_VERSION ".dylib"; + SharedVersionedExt = LLVM_DYLIB_VERSION ".dylib"; StaticExt = "a"; StaticDir = SharedDir = ActiveLibDir; StaticPrefix = SharedPrefix = "lib"; } else { // default to the unix values: SharedExt = "so"; - SharedVersionedExt = PACKAGE_VERSION ".so"; + SharedVersionedExt = LLVM_DYLIB_VERSION ".so"; StaticExt = "a"; StaticDir = SharedDir = ActiveLibDir; StaticPrefix = SharedPrefix = "lib"; @@ -364,8 +366,18 @@ const std::string DyLibName = (SharedPrefix + "LLVM-" + SharedVersionedExt).str(); + // If LLVM_LINK_DYLIB is ON, the single shared library will be returned + // for "--libs", etc. This behaviour can be overridden with --link-static + // or --link-shared. + bool LinkDyLib = (std::strcmp(LLVM_LINK_DYLIB, "ON") == 0); + if (BuiltDyLib) { DyLibExists = sys::fs::exists(SharedDir + "/" + DyLibName); + if (!DyLibExists) { + // The shared library does not exist: don't error unless the user + // explicitly passes --link-shared. + LinkDyLib = false; + } } /// Get the component's library name without the lib prefix and the @@ -501,6 +513,10 @@ OS << ActivePrefix << '\n'; } else if (Arg == "--src-root") { OS << LLVM_SRC_ROOT << '\n'; + } else if (Arg == "--link-shared") { + LinkDyLib = true; + } else if (Arg == "--link-static") { + LinkDyLib = false; } else { usage(); } @@ -512,6 +528,11 @@ if (!HasAnyOption) usage(); + if (LinkDyLib && !DyLibExists) { + errs() << "llvm-config: error: " << DyLibName << " is missing\n\n"; + usage(); + } + if (PrintLibs || PrintLibNames || PrintLibFiles || PrintSystemLibs || PrintSharedMode) { @@ -549,7 +570,7 @@ } FullDyLibComponents.clear(); - if (HasMissing && DyLibExists) { + if ((LinkDyLib || HasMissing) && DyLibExists) { OS << "shared\n"; return 0; } else { @@ -581,7 +602,7 @@ } }; - if (HasMissing && DyLibExists) { + if ((LinkDyLib || HasMissing) && DyLibExists) { PrintForLib(DyLibName, true); } else { for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {