]> git.tdb.fi Git - builder.git/blobdiff - plugins/msvc/msvclinker.cpp
Explicitly create import libraries from BinaryComponent
[builder.git] / plugins / msvc / msvclinker.cpp
index 19ee284e0b0a11fe3c0a9dae611e259e0a0e2f89..31f9a4f8189f8ff9be0549edbb88751e7767b72e 100644 (file)
@@ -2,6 +2,7 @@
 #include <msp/builder/component.h>
 #include <msp/builder/executable.h>
 #include <msp/builder/importlibrary.h>
+#include <msp/builder/installedfile.h>
 #include <msp/builder/objectfile.h>
 #include <msp/builder/sharedlibrary.h>
 #include <msp/builder/sourcepackage.h>
@@ -33,6 +34,20 @@ Target *MsvcLinker::create_target(const vector<Target *> &sources, const string
        if(sources.empty())
                throw invalid_argument("MsvcLinker::create_target");
 
+       if(arg=="import")
+       {
+               if(sources.size()!=1)
+                       throw invalid_argument("MsvcLinker::create_target");
+               SharedLibrary &shlib = dynamic_cast<SharedLibrary &>(*sources.front());
+
+               ImportLibrary *imp = new ImportLibrary(builder, *shlib.get_component(), shlib);
+               for(ObjectFile *o: shlib.get_objects())
+                       imp->add_dependency(*o);
+               shlib.add_side_effect(*imp);
+
+               return imp;
+       }
+
        vector<ObjectFile *> objs;
        objs.reserve(sources.size());
        for(Target *s: sources)
@@ -94,8 +109,13 @@ ExternalTask::Arguments MsvcLinker::_run(const Binary &bin, FS::Path &work_dir)
        argv.push_back(tool.get_executable()->get_path().str());
        argv.push_back("/NOLOGO");
 
-       if(dynamic_cast<const SharedLibrary *>(&bin))
+       string imp_fn;
+       if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&bin))
+       {
                argv.push_back("/DLL");
+               if(const ImportLibrary *imp = shlib->get_import_library())
+                       imp_fn = relative(imp->get_path(), work_dir).str();
+       }
 
        BuildInfo binfo;
        bin.collect_build_info(binfo);
@@ -105,9 +125,18 @@ ExternalTask::Arguments MsvcLinker::_run(const Binary &bin, FS::Path &work_dir)
        if(binfo.strip)
                argv.push_back("/INCREMENTAL:NO");
        else
+       {
                argv.push_back("/DEBUG:FULL");
+               FS::Path temp_dir = bin.get_package()->get_temp_directory()/bin.get_component()->get_name();
+               FS::Path ilk_path = temp_dir/(FS::basepart(FS::basename(bin.get_path()))+".ilk");
+               argv.push_back("/ILK:"+relative(ilk_path, work_dir).str());
+       }
 
        argv.push_back("/OUT:"+relative(bin.get_path(), work_dir).str());
+       if(!imp_fn.empty())
+               argv.push_back("/IMPLIB:"+imp_fn);
+       else
+               argv.push_back("/NOIMPLIB");
 
        for(Target *d: bin.get_dependencies())
        {