-
Notifications
You must be signed in to change notification settings - Fork 379
Add CMake File API support to Microsoft.DotNet.CMake.Sdk #16233
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
ce43af6
9853820
c21baa8
6b4def4
7eaec0c
d5a1e0c
ad3848c
82e7b52
d7b41b6
f02c537
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,44 @@ | ||
| <Project Sdk="Microsoft.Build.NoTargets"> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>$(NetToolCurrent)</TargetFramework> | ||
| <TargetFrameworks>$(NetToolCurrent);$(NetFrameworkToolCurrent)</TargetFrameworks> | ||
| <IsPackable>true</IsPackable> | ||
| <IsBuildTaskProject>true</IsBuildTaskProject> | ||
| <Description>Common toolset for calling into CMake from MSBuild and easily reference native assets from managed projects.</Description> | ||
| <PackageType>MSBuildSdk</PackageType> | ||
| <NoWarn>$(NoWarn);NU5128</NoWarn> | ||
| <NoWarn>$(NoWarn);NU5128;CS0649</NoWarn> | ||
| <SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking> | ||
| <EnableDefaultItems>false</EnableDefaultItems> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="**/*.props;**/*.targets" | ||
| <PackageReference Include="Microsoft.Build.Utilities.Core" /> | ||
| <PackageReference Include="Microsoft.Build.Framework" /> | ||
| <PackageReference Include="System.Text.Json" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="src\**\*.cs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'"> | ||
| <Compile Include="..\Common\Internal\AssemblyResolver.cs" /> | ||
| <Compile Include="..\Common\Internal\AssemblyResolution.cs" /> | ||
| <Compile Include="..\Common\Internal\BuildTask.Desktop.cs" /> | ||
| <Reference Include="WindowsBase" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="..\Common\Internal\BuildTask.cs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="build\**\*.props;build\**\*.targets" | ||
| Pack="true" | ||
| PackagePath="build\%(RecursiveDir)%(Filename)%(Extension)" /> | ||
| <None Include="sdk\**\*.props;sdk\**\*.targets" | ||
| Pack="true" | ||
| PackagePath="%(RecursiveDir)%(Filename)%(Extension)" /> | ||
| <None Include="$(RepoRoot)LICENSE.TXT;$(RepoRoot)THIRD-PARTY-NOTICES.TXT" Pack="true" PackagePath="%(Filename)%(Extension)" /> | ||
| PackagePath="sdk\%(RecursiveDir)%(Filename)%(Extension)" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,20 @@ | ||
| <!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. --> | ||
| <Project DefaultTargets="Build"> | ||
|
|
||
| <PropertyGroup> | ||
| <MicrosoftDotNetCMakeSdkTaskAssembly Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\net\Microsoft.DotNet.CMake.Sdk.dll</MicrosoftDotNetCMakeSdkTaskAssembly> | ||
| <MicrosoftDotNetCMakeSdkTaskAssembly Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\netframework\Microsoft.DotNet.CMake.Sdk.dll</MicrosoftDotNetCMakeSdkTaskAssembly> | ||
| </PropertyGroup> | ||
|
|
||
| <UsingTask TaskName="Microsoft.DotNet.CMake.Sdk.CreateCMakeFileApiQuery" AssemblyFile="$(MicrosoftDotNetCMakeSdkTaskAssembly)" /> | ||
| <UsingTask TaskName="Microsoft.DotNet.CMake.Sdk.GetCMakeArtifactsFromFileApi" AssemblyFile="$(MicrosoftDotNetCMakeSdkTaskAssembly)" /> | ||
|
|
||
| <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" /> | ||
|
|
||
| <PropertyGroup> | ||
| <VSWhereVersion Condition="'$(VSWhereVersion)' == ''">3.1.7</VSWhereVersion> | ||
|
||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="vswhere" Version="$(VSWhereVersion)" IsImplicitlyDefined="true" GeneratePathProperty="true" /> | ||
| </ItemGroup> | ||
|
|
@@ -92,6 +104,12 @@ | |
| </ItemGroup> | ||
| </Target> | ||
|
|
||
| <Target Name="GetCMakeOutputDirProperty" Returns="$(CMakeOutputDir)"> | ||
| </Target> | ||
|
|
||
| <Target Name="GetConfigurationProperty" Returns="$(Configuration)"> | ||
| </Target> | ||
|
|
||
| <Target Name="_ResolveVSCompilerToolchainForNonVSGenerators" | ||
| Condition="$([MSBuild]::IsOsPlatform(Windows)) and !$(CMakeGenerator.StartsWith('Visual Studio')) and '$(CMakeCompilerToolchain)' == 'MSVC' and '$(CMakeCompilerSearchScript)' == ''"> | ||
| <Error Condition="'$(_VSNativeCompilerComponentArchName)' == ''" Text="Unable to determine location of MSVC tools installed for the '$(Platform)' architecture." /> | ||
|
|
@@ -175,8 +193,14 @@ | |
| </PropertyGroup> | ||
| </Target> | ||
|
|
||
| <Target Name="CreateFileApiQuery" | ||
| DependsOnTargets="GetConfigScript" | ||
| BeforeTargets="Configure"> | ||
| <CreateCMakeFileApiQuery CMakeOutputDir="$(CMakeOutputDir)" /> | ||
| </Target> | ||
|
|
||
| <Target Name="Configure" | ||
| DependsOnTargets="GetConfigScript"> | ||
| DependsOnTargets="GetConfigScript;CreateFileApiQuery"> | ||
| <Exec WorkingDirectory="$(MSBuildProjectDirectory)" Command=" | ||
| $(CMakeCompilerSearchScript) | ||
| $(CMakeConfigScript)" /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.Build.Framework; | ||
| using Microsoft.Build.Utilities; | ||
| using System; | ||
| using System.IO; | ||
|
|
||
| namespace Microsoft.DotNet.CMake.Sdk | ||
| { | ||
| /// <summary> | ||
| /// Creates a CMake File API query file to request codemodel information. | ||
| /// </summary> | ||
| public class CreateCMakeFileApiQuery : Task | ||
jkoritzinsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| /// <summary> | ||
| /// The CMake build output directory where the query should be created. | ||
| /// </summary> | ||
| [Required] | ||
| public string CMakeOutputDir { get; set; } | ||
|
|
||
| public override bool Execute() | ||
| { | ||
| try | ||
| { | ||
| string queryDir = Path.Combine(CMakeOutputDir, ".cmake", "api", "v1", "query"); | ||
| Directory.CreateDirectory(queryDir); | ||
|
|
||
| string queryFile = Path.Combine(queryDir, "codemodel-v2"); | ||
|
|
||
| // Create an empty file to request codemodel-v2 information | ||
| File.WriteAllText(queryFile, string.Empty); | ||
|
|
||
| Log.LogMessage(MessageImportance.Low, $"Created CMake File API query at: {queryFile}"); | ||
jkoritzinsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return true; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Log.LogErrorFromException(ex); | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.