Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions SamplesDef.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,20 @@
"&'./{testFolder}/projects/cpppackagereferences/output/{VsVersionSuffix}/{configuration}/cpppackagereferences.exe'"
]
},
{
"Name": "ProjectReferencesExport",
"CIs": [ "github", "gitlab" ],
"OSs": [ "windows-2022" ],
"Frameworks": [ "net6.0" ],
"Configurations": [ "debug", "release" ],
"TestFolder": "samples/ProjectReferencesExport",
"Commands":
[
"./RunSharpmake.ps1 -workingDirectory {testFolder} -sharpmakeFile \"ProjectReferencesExport.sharpmake.cs\" -framework {framework}",
"./Compile.ps1 -slnOrPrjFile \"projectreferencesexport_{VsVersionSuffix}_win64.sln\" -configuration {configuration} -platform \"x64\" -WorkingDirectory \"{testFolder}/projects\" -VsVersion {os} -compiler MsBuild",
"&'./{testFolder}/projects/output/win64/{configuration}/mainproject.exe'"
]
},
{
"Name": "QTFileCustomBuild",
"CIs": [],
Expand Down
4 changes: 2 additions & 2 deletions Sharpmake.Generators/VisualStudio/Vcxproj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ private void GenerateProjectReferences(

if (context.Builder.Diagnostics
&& context.Project.AllowInconsistentDependencies == false
&& context.ProjectConfigurations.Any(c => ConfigurationNeedReferences(c)))
&& (context.ProjectConfigurations.Any(c => ConfigurationNeedReferences(c)) || context.Project.ForceReferencesExport))
{
CheckReferenceDependenciesConsistency(context);
}
Expand All @@ -1067,7 +1067,7 @@ private void GenerateProjectReferences(
? context.ProjectConfigurations.Any(c => ConfigurationNeedReferences(c))
: ConfigurationNeedReferences(firstConf);

if (addDependencies)
if (addDependencies || context.Project.ForceReferencesExport)
{
var dependencies = new UniqueList<ProjectDependencyInfo>();
foreach (var configuration in context.ProjectConfigurations)
Expand Down
9 changes: 9 additions & 0 deletions Sharpmake/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ public uint DependenciesOrder
// Setting this to true will force dependencies regardless of different output types.
public bool AllowInconsistentDependencies = false;

/// <summary>
/// Forces project references to be exported regardless of different output types.
/// </summary>
/// <remarks>
/// Sharpmake does not export project references for output types when it is unnecessary.
/// If you wish to export them, anyway, set this boolean to <c>true</c>.
/// </remarks>
public bool ForceReferencesExport = false;

private string _blobPath = "[project.SourceRootPath]" + Path.DirectorySeparatorChar + "blob";
public string BlobPath
{
Expand Down
139 changes: 139 additions & 0 deletions samples/ProjectReferencesExport/ProjectReferencesExport.sharpmake.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Copyright (c) Ubisoft. All Rights Reserved.
// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information.

using System.IO;
using Sharpmake;

namespace ProjectReferencesExport
{
public partial class BaseProject : Project
{
public BaseProject()
{
AddTargets(new Target(Platform.win64, DevEnv.vs2022, Optimization.Debug | Optimization.Release));
SourceRootPath = @"[project.SharpmakeCsPath]\codebase\[project.Name]";
}

[Configure]
public void ConfigureAll(Configuration conf, Target target)
{
conf.ProjectPath = @"[project.SharpmakeCsPath]\projects";
conf.ProjectFileName = "[project.Name]_[target.DevEnv]_[target.Platform]";

conf.IntermediatePath = @"[conf.ProjectPath]\obj\[project.Name]\[target.Platform]\[target.Name]";

conf.IncludePaths.Add(@"[project.SourceRootPath]\include");
conf.IncludePrivatePaths.Add(@"[project.SourceRootPath]\src");

conf.Options.Add(Options.Vc.Compiler.Exceptions.Enable);
}
}

[Sharpmake.Generate]
public class FooBarProject : BaseProject
{
[Configure]
public void ConfigureOutput(Configuration conf, Target target)
{
conf.Output = Configuration.OutputType.Lib;
}

[Configure]
public void ConfigurePrecompHeader(Configuration conf, Target target)
{
conf.PrecompHeader = "stdafx.h";
conf.PrecompSource = "stdafx.cpp";
}
}

[Sharpmake.Generate]
public class DependantProject : BaseProject
{
public DependantProject()
{
ForceReferencesExport = true;
}

[Configure]
public void ConfigureDependencies(Configuration conf, Target target)
{
conf.AddPrivateDependency<FooBarProject>(target);
}

[Configure]
public void ConfigureOutput(Configuration conf, Target target)
{
conf.Output = Configuration.OutputType.Lib;
}

public override void PostLink()
{
base.PostLink();
ConfigureSharedPrecompiledHeader();
}

internal void ConfigureSharedPrecompiledHeader()
{
foreach (Configuration conf in Configurations)
{
var dependency = Builder.Instance.GetProject(typeof(FooBarProject));
var dependencyConf = dependency.GetConfiguration(conf.Target);

conf.CompilerPdbFilePath = dependencyConf.CompilerPdbFilePath;

string sourceRoot = Util.PathGetRelative(SourceRootPath, dependency.SourceRootPath);
string header = Path.Combine(sourceRoot, dependencyConf.PrecompHeader);

conf.PrecompHeader = header;
conf.PrecompSource = "use";

conf.ForcedIncludes.Add(header);

conf.PrecompHeaderOutputFolder = Util.PathGetRelative(conf.ProjectPath, dependencyConf.IntermediatePath);
conf.PrecompHeaderOutputFile = $"{dependencyConf.ProjectName}.pch";
}
}
}

[Sharpmake.Generate]
public class MainProject : BaseProject
{
[Configure]
public void ConfigureDependencies(Configuration conf, Target target)
{
conf.AddPrivateDependency<FooBarProject>(target);
conf.AddPrivateDependency<DependantProject>(target);
}
}

[Sharpmake.Generate]
public class ProjectReferencesExportSolution : Sharpmake.Solution
{
public ProjectReferencesExportSolution()
{
Name = "ProjectReferencesExport";
AddTargets(new Target(Platform.win64, DevEnv.vs2022, Optimization.Debug | Optimization.Release));
}

[Configure]
public void ConfigureAll(Configuration conf, Target target)
{
conf.SolutionFileName = "[solution.Name]_[target.DevEnv]_[target.Platform]";
conf.SolutionPath = @"[solution.SharpmakeCsPath]\projects";
conf.AddProject<FooBarProject>(target);
conf.AddProject<DependantProject>(target);
conf.AddProject<MainProject>(target);
}
}

public static class Main
{
[Sharpmake.Main]
public static void SharpmakeMain(Sharpmake.Arguments arguments)
{
KitsRootPaths.SetUseKitsRootForDevEnv(DevEnv.vs2022, KitsRootEnum.KitsRoot10, Options.Vc.General.WindowsTargetPlatformVersion.v10_0_19041_0);

arguments.Generate<ProjectReferencesExportSolution>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

std::string get_string();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <string>
#include "dependant.h"
#include "foobar.h"

std::string get_string()
{
return "Hello " + get_name() + "!";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

std::string get_name();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include <string>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "stdafx.h"
#include "foobar.h"

std::string get_name()
{
return "world";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "stdafx.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <iostream>
#include "dependant.h"

int main(int, char**)
{
std::cout << get_string() << std::endl;
return 0;
}
Loading
Loading