diff --git a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs index 2980e12a8..6e7da6812 100644 --- a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs +++ b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs @@ -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) { diff --git a/Sharpmake/Project.Configuration.cs b/Sharpmake/Project.Configuration.cs index f567d1e98..226968040 100644 --- a/Sharpmake/Project.Configuration.cs +++ b/Sharpmake/Project.Configuration.cs @@ -65,6 +65,7 @@ public enum DependencySetting /// AdditionalUsingDirectories = 1 << 5, ForceUsingAssembly = 1 << 6, + InheritBuildSteps = 1 << 7, /// /// Specifies that the dependent project inherits the dependency's library files, library @@ -73,7 +74,8 @@ public enum DependencySetting Default = LibraryFiles | LibraryPaths | IncludePaths | - Defines, + Defines | + InheritBuildSteps, /// /// Specifies that the dependent project inherits the dependency's include paths and @@ -86,6 +88,12 @@ public enum DependencySetting DefaultForceUsing = ForceUsingAssembly | IncludePaths | Defines, + + DefaultWithoutBuildSteps = LibraryFiles + | LibraryPaths + | IncludePaths + | Defines, + } /// @@ -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); @@ -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: diff --git a/Sharpmake/Properties/launchSettings.json b/Sharpmake/Properties/launchSettings.json new file mode 100644 index 000000000..5d229b43c --- /dev/null +++ b/Sharpmake/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Sharpmake": { + "commandName": "Project", + "commandLineArgs": "/sources(\"C:\\Personal\\ElectronicJonaJoy\\main.Sharpmake.cs\") /multithread(false)" + } + } +} \ No newline at end of file diff --git a/samples/PreBuildStepDependency/PreBuildStepDependency.sharpmake.cs b/samples/PreBuildStepDependency/PreBuildStepDependency.sharpmake.cs new file mode 100644 index 000000000..673199f98 --- /dev/null +++ b/samples/PreBuildStepDependency/PreBuildStepDependency.sharpmake.cs @@ -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(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(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(target); + conf.AddProject(target); + conf.AddProject(target); + } + + [Sharpmake.Main] + public static void SharpmakeMain(Sharpmake.Arguments arguments) + { + arguments.Generate(); + } + } +} diff --git a/samples/PreBuildStepDependency/codebase/app/main.cpp b/samples/PreBuildStepDependency/codebase/app/main.cpp new file mode 100644 index 000000000..e3d21d2ca --- /dev/null +++ b/samples/PreBuildStepDependency/codebase/app/main.cpp @@ -0,0 +1,12 @@ +#include + +#include "lib.h" + +int main(const int, char*) +{ + printf("[APP]: Executing app"); + + execute_my_fn(); + + return 0; +} diff --git a/samples/PreBuildStepDependency/codebase/lib/lib.cpp b/samples/PreBuildStepDependency/codebase/lib/lib.cpp new file mode 100644 index 000000000..4ffc22694 --- /dev/null +++ b/samples/PreBuildStepDependency/codebase/lib/lib.cpp @@ -0,0 +1,5 @@ +#include + +void execute_my_fn() { + printf("\"execute_my_fn\" has been called."); +} diff --git a/samples/PreBuildStepDependency/codebase/lib/lib.h b/samples/PreBuildStepDependency/codebase/lib/lib.h new file mode 100644 index 000000000..48ff23cde --- /dev/null +++ b/samples/PreBuildStepDependency/codebase/lib/lib.h @@ -0,0 +1,3 @@ +#pragma once + +void execute_my_fn(); diff --git a/samples/PreBuildStepDependency/codebase/tool/main.cpp b/samples/PreBuildStepDependency/codebase/tool/main.cpp new file mode 100644 index 000000000..7ec6b74a4 --- /dev/null +++ b/samples/PreBuildStepDependency/codebase/tool/main.cpp @@ -0,0 +1,12 @@ +#include +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; +} diff --git a/samples/Sharpmake.Samples.sharpmake.cs b/samples/Sharpmake.Samples.sharpmake.cs index e73e7b739..3e10faeb3 100644 --- a/samples/Sharpmake.Samples.sharpmake.cs +++ b/samples/Sharpmake.Samples.sharpmake.cs @@ -119,6 +119,7 @@ public CSharpWcfProject() } } + [Generate] public class CustomBuildStepProject : SampleProject { @@ -344,6 +345,16 @@ public SimpleExeLibDependencyProject() } } + [Generate] + public class PreBuildStepDependency : SampleProject + { + public PreBuildStepDependency() + { + Name = "PreBuildStepDependency"; + SharpmakeMainFile = "PreBuildStepDependency.sharpmake.cs"; + } + } + [Generate] public class VcpkgProject : SampleProject {