Skip to content
4 changes: 3 additions & 1 deletion Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,9 @@ private void GeneratePostBuildOptions(IGenerationContext context, ProjectOptions

if (!context.Configuration.IsFastBuild)
{
if (context.Configuration.Output == Project.Configuration.OutputType.Exe || context.Configuration.ExecuteTargetCopy)
if ( context.Configuration.Output == Project.Configuration.OutputType.Exe
|| context.Configuration.Output == Project.Configuration.OutputType.Lib
|| context.Configuration.ExecuteTargetCopy)
{
foreach (var customEvent in context.Configuration.ResolvedEventPreBuildExe)
{
Expand Down
34 changes: 25 additions & 9 deletions Sharpmake/Project.Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public enum DependencySetting
/// </summary>
AdditionalUsingDirectories = 1 << 5,
ForceUsingAssembly = 1 << 6,
InheritBuildSteps = 1 << 7,

/// <summary>
/// Specifies that the dependent project inherits the dependency's library files, library
Expand All @@ -73,7 +74,8 @@ public enum DependencySetting
Default = LibraryFiles |
LibraryPaths |
IncludePaths |
Defines,
Defines |
InheritBuildSteps,

/// <summary>
/// Specifies that the dependent project inherits the dependency's include paths and
Expand All @@ -86,6 +88,12 @@ public enum DependencySetting
DefaultForceUsing = ForceUsingAssembly
| IncludePaths
| Defines,

DefaultWithoutBuildSteps = LibraryFiles
| LibraryPaths
| IncludePaths
| Defines,

}

/// <summary>
Expand Down Expand Up @@ -3099,7 +3107,7 @@ internal void Link(Builder builder)
dependency.Project.SharpmakeProjectType == ProjectTypeAttribute.Compile;

var dependencySetting = propagationSetting._dependencySetting;
if (dependencySetting != DependencySetting.OnlyBuildOrder)
if (dependencySetting.HasFlag(DependencySetting.InheritBuildSteps))
{
_resolvedEventPreBuildExe.AddRange(dependency.EventPreBuildExe);
_resolvedEventPostBuildExe.AddRange(dependency.EventPostBuildExe);
Expand Down Expand Up @@ -3264,15 +3272,23 @@ internal void Link(Builder builder)
case OutputType.IosApp:
case OutputType.Exe:
{
if (hasPublicPathToRoot)
resolvedDotNetPublicDependencies.Add(new DotNetDependency(dependency));
else if (isImmediate)
resolvedDotNetPrivateDependencies.Add(new DotNetDependency(dependency));
if(dependencySetting != DependencySetting.OnlyBuildOrder)
{
if (Output != OutputType.Utility && Output != OutputType.Exe && Output != OutputType.None)
throw new Error("Project {0} cannot depend on OutputType {1} {2}", this, Output, dependency);

if (dependencySetting == DependencySetting.OnlyBuildOrder)
BuildOrderDependencies.Add(dependency);
else
if (hasPublicPathToRoot)
resolvedDotNetPublicDependencies.Add(new DotNetDependency(dependency));
else if (isImmediate)
resolvedDotNetPrivateDependencies.Add(new DotNetDependency(dependency));

{}
ConfigurationDependencies.Add(dependency);
}
else
{
BuildOrderDependencies.Add(dependency);
}
}
break;
case OutputType.Utility:
Expand Down
8 changes: 8 additions & 0 deletions Sharpmake/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Sharpmake": {
"commandName": "Project",
"commandLineArgs": "/sources(\"C:\\Personal\\ElectronicJonaJoy\\main.Sharpmake.cs\") /multithread(false)"
}
}
}
142 changes: 142 additions & 0 deletions samples/PreBuildStepDependency/PreBuildStepDependency.sharpmake.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Copyright (c) 2017 Ubisoft Entertainment
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Sharpmake;

namespace PreBuildStepDependency
{
[Generate]
public class ToolProject : Project
{
public ToolProject()
{
Name = "Tool";

AddTargets(new Target(
Platform.win64,
DevEnv.vs2019,
Optimization.Debug // | Optimization.Release
));

SourceRootPath = @"[project.SharpmakeCsPath]\codebase\tool";
}

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

[Generate]
public class AppProject : Project
{
public AppProject()
{
Name = "App";


AddTargets(new Target(
Platform.win64,
DevEnv.vs2019,
Optimization.Debug // | Optimization.Release
));

SourceRootPath = @"[project.SharpmakeCsPath]\codebase\app";
}

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

conf.AddPrivateDependency<LibProject>(target, DependencySetting.DefaultWithoutBuildSteps);

Configuration.BuildStepExecutable tool = new Configuration.BuildStepExecutable(@"[project.SharpmakeCsPath]\projects\output\win64\debug\tool.exe", "", "", "-Flag1 -Flag2 -DoStuff=256");
conf.EventPreBuildExe.Add(tool);

}
}

[Generate]
public class LibProject : Project
{
public LibProject()
{
Name = "Lib";

AddTargets(new Target(
Platform.win64,
DevEnv.vs2019,
Optimization.Debug // | Optimization.Release
));

SourceRootPath = @"[project.SharpmakeCsPath]\codebase\lib";
}

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

conf.Output = Configuration.OutputType.Lib;
conf.IncludePaths.Add(conf.Project.SourceRootPath);

// Depend on our 'tool' to be build first
conf.AddPrivateDependency<ToolProject>(target, DependencySetting.OnlyBuildOrder);

Configuration.BuildStepExecutable tool = new Configuration.BuildStepExecutable(@"[project.SharpmakeCsPath]\projects\output\win64\debug\tool.exe", "", "", "-Flag1 -Flag2 -DoStuff=123");
conf.EventPreBuildExe.Add(tool);
}
}


[Sharpmake.Generate]
public class PreBuildStepDependencySolution : Sharpmake.Solution
{
public PreBuildStepDependencySolution()
{
Name = "PreBuildStepDependency";

AddTargets(new Target(
Platform.win64,
DevEnv.vs2019,
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<LibProject>(target);
conf.AddProject<AppProject>(target);
conf.AddProject<ToolProject>(target);
}

[Sharpmake.Main]
public static void SharpmakeMain(Sharpmake.Arguments arguments)
{
arguments.Generate<PreBuildStepDependencySolution>();
}
}
}
12 changes: 12 additions & 0 deletions samples/PreBuildStepDependency/codebase/app/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>

#include "lib.h"

int main(const int, char*)
{
printf("[APP]: Executing app");

execute_my_fn();

return 0;
}
5 changes: 5 additions & 0 deletions samples/PreBuildStepDependency/codebase/lib/lib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdio.h>

void execute_my_fn() {
printf("\"execute_my_fn\" has been called.");
}
3 changes: 3 additions & 0 deletions samples/PreBuildStepDependency/codebase/lib/lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void execute_my_fn();
12 changes: 12 additions & 0 deletions samples/PreBuildStepDependency/codebase/tool/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>
int main(const int argc, char* argvs[])
{
printf("[PREBUILD]: Calling prebuilt tool.\n");
printf("[PREBUILD]: ");
for (int i = 0; i < argc; ++i)
{
printf("%s ", argvs[i]);
}
printf("\n");
return 0;
}
11 changes: 11 additions & 0 deletions samples/Sharpmake.Samples.sharpmake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public CSharpWcfProject()
}
}


[Generate]
public class CustomBuildStepProject : SampleProject
{
Expand Down Expand Up @@ -344,6 +345,16 @@ public SimpleExeLibDependencyProject()
}
}

[Generate]
public class PreBuildStepDependency : SampleProject
{
public PreBuildStepDependency()
{
Name = "PreBuildStepDependency";
SharpmakeMainFile = "PreBuildStepDependency.sharpmake.cs";
}
}

[Generate]
public class VcpkgProject : SampleProject
{
Expand Down