Suffixing #pragma comment(lib) library names with .lib if necessary. This matches MSVC behavior, as well as allows us to properly link libraries such as the ones provided by the MSDN examples.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182647 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp
index 45fc475..74db0e3 100644
--- a/lib/CodeGen/TargetInfo.cpp
+++ b/lib/CodeGen/TargetInfo.cpp
@@ -1266,6 +1266,17 @@
};
+static std::string qualifyWindowsLibrary(llvm::StringRef Lib) {
+ // If the argument does not end in .lib, automatically add the suffix. This
+ // matches the behavior of MSVC.
+ std::string ArgStr = Lib;
+ if (Lib.size() <= 4 ||
+ Lib.substr(Lib.size() - 4).compare_lower(".lib") != 0) {
+ ArgStr += ".lib";
+ }
+ return ArgStr;
+}
+
class WinX86_32TargetCodeGenInfo : public X86_32TargetCodeGenInfo {
public:
WinX86_32TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, unsigned RegParms)
@@ -1274,7 +1285,7 @@
void getDependentLibraryOption(llvm::StringRef Lib,
llvm::SmallString<24> &Opt) const {
Opt = "/DEFAULTLIB:";
- Opt += Lib;
+ Opt += qualifyWindowsLibrary(Lib);
}
};
@@ -1300,7 +1311,7 @@
void getDependentLibraryOption(llvm::StringRef Lib,
llvm::SmallString<24> &Opt) const {
Opt = "/DEFAULTLIB:";
- Opt += Lib;
+ Opt += qualifyWindowsLibrary(Lib);
}
};