]> git.tdb.fi Git - builder.git/commitdiff
Create import libraries with MSVC linker
authorMikko Rasa <tdb@tdb.fi>
Mon, 2 Jan 2023 22:46:59 +0000 (00:46 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 2 Jan 2023 22:51:47 +0000 (00:51 +0200)
plugins/msvc/msvclinker.cpp
plugins/msvc/msvclinker.h

index ca77a28edddfb14d6920f910fd85d57f5bb89c0e..5ce9d32112688e36cd65768e8199ae6ade9ea315 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>
@@ -41,13 +42,34 @@ Target *MsvcLinker::create_target(const vector<Target *> &sources, const string
        const Component &comp = *objs.front()->get_component();
        Binary *bin = 0;
        if(arg=="shared")
-               bin = new SharedLibrary(builder, comp, objs);
+       {
+               SharedLibrary *shlib = new SharedLibrary(builder, comp, objs);
+               bin = shlib;
+               ImportLibrary *imp = new ImportLibrary(builder, comp, *shlib);
+               for(ObjectFile *o: objs)
+                       imp->add_dependency(*o);
+               imp->set_tool(*this);
+               shlib->add_side_effect(*imp);
+       }
        else
                bin = new Executable(builder, comp, objs);
        bin->set_tool(*this);
        return bin;
 }
 
+Target *MsvcLinker::create_install(Target &target) const
+{
+       if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(&target))
+       {
+               Tool &copy = builder.get_toolchain().get_tool("CP");
+               InstalledFile *inst_tgt = dynamic_cast<InstalledFile *>(copy.create_target(target));
+               builder.get_build_graph().add_installed_target(*shlib->get_import_library());
+               return inst_tgt;
+       }
+       else
+               return 0;
+}
+
 string MsvcLinker::create_build_signature(const BuildInfo &binfo) const
 {
        string result = Tool::create_build_signature(binfo);
index fe98c7d8501460f77d3ccb2aaa43c88d733369d8..fc9e9df364b68fd79972fadc7280603df232e9c4 100644 (file)
@@ -15,6 +15,7 @@ public:
        MsvcLinker(Builder &, const Architecture &, const MicrosoftTools &);
 
        Target *create_target(const std::vector<Target *> &, const std::string &) override;
+       Target *create_install(Target &) const override;
        std::string create_build_signature(const BuildInfo &) const override;
 
 protected: