Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library project references #146

Open
Cheaterdev opened this issue Oct 21, 2021 · 4 comments
Open

Library project references #146

Cheaterdev opened this issue Oct 21, 2021 · 4 comments

Comments

@Cheaterdev
Copy link

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.

@jspelletier
Copy link
Collaborator

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.

@Cheaterdev
Copy link
Author

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;
}

@belkiss
Copy link
Contributor

belkiss commented Oct 25, 2021

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!

ChemistAion added a commit to ChemistAion/sharpmake that referenced this issue Mar 10, 2023
@ChemistAion
Copy link

@Cheaterdev I have made a PR in your behalf - I am tired to "manually" add it every time I update the tool ;)
#253

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
@belkiss @Cheaterdev @ChemistAion @jspelletier and others