Sharpmake icon indicating copy to clipboard operation
Sharpmake copied to clipboard

Library project references

Open Cheaterdev opened this issue 3 years ago • 4 comments

Hello! In order to use compiled module files from other projects we have to use Project References. While using OutputType.Lib its only possible with ExportAdditionalLibrariesEvenForStaticLib = true. But it also includes .lib files and linker is going crazy.

It would be good to add another property like ForceCreateReferences.

Cheaterdev avatar Oct 21 '21 13:10 Cheaterdev

You could do something like this to link libraries from external projects

[Sharpmake.Export]
class Curl : ExportProject
{
    public override void ConfigureAll(Configuration conf, Target target)
    {
        conf.AddPublicDependency<VCPKG>(target);
        conf.AddPublicDependency<ZLib>(target);

        // Dependencies on windows libraries when using Curl
        conf.LibraryFiles.Add("Crypt32.lib", "Wldap32.lib");
    }

    public override void ConfigureDebug(Configuration conf, Target target)
    {
        conf.LibraryFiles.Add(@"libcurl-d.lib");
    }

    public override void ConfigureRelease(Configuration conf, Target target)
    {
        conf.LibraryFiles.Add(@"libcurl.lib");
    }
}

And then in your project you do
[Sharpmake.Generate]
class MyProject : Project
{
   [Configure()]
   public override void ConfigureAll(Configuration conf, Target target)
   {
       conf.AddPrivateDependency<Curl>(conf);
   }
}

Hopefully this will help you a bit.

jspelletier avatar Oct 21 '21 17:10 jspelletier

Sorry, but it won't help in my case.

For example I have library project A with c++20 modules and library project B with code that imports modules from project A. To make modules from A visible to B I have to add A as a reference to B. I dont want to include any output library file from library A to library B specifically.

This change makes what I need:

private static bool ConfigurationNeedReferences(Project.Configuration conf)
{
    return conf.Output == Project.Configuration.OutputType.Exe
        || conf.Output == Project.Configuration.OutputType.Dll
/*rem   || (conf.Output == Project.Configuration.OutputType.Lib && conf.ExportAdditionalLibrariesEvenForStaticLib) */
/*add*/ || conf.Output == Project.Configuration.OutputType.Lib
        || conf.Output == Project.Configuration.OutputType.DotNetConsoleApp
        || conf.Output == Project.Configuration.OutputType.DotNetClassLibrary
        || conf.Output == Project.Configuration.OutputType.DotNetWindowsApp;
}

Cheaterdev avatar Oct 21 '21 17:10 Cheaterdev

Hum ok, thanks for letting us know. As said previously, we haven't looked into modules support for sharpmake yet, but sounds like we need to clarify and fix the reference management in vcxproj when it comes to static libraries. The current behavior was done to improve build times but can create issues. Do you think you could create a small sample project exhibiting the issue? So we can add it to the batch of samples tested in the CI.

Thanks!

belkiss avatar Oct 25 '21 09:10 belkiss

@Cheaterdev I have made a PR in your behalf - I am tired to "manually" add it every time I update the tool ;) https://github.com/ubisoft/Sharpmake/pull/253

ChemistAion avatar Mar 10 '23 19:03 ChemistAion