This is the MSBuild SDK which does configure,build,and other task for CMake project.
- cmake
- you should add path to
cmake
to "PATH" environment variable
- you should add path to
- dotnet core sdk 2.1.300 or later
- build tools for C/C++
- Depends on CMake
- creating initial cmake project
- create msbuild project file like following next to CMakeLists.txt
<Project Sdk="MSBuild.Sdk.CMake/[version of this package]">
</Project>
- execute
dotnet build [project file]
- if you want to get release build,
dotnet build -c Release [project file]
- if you do not want to add cmake to PATH,
CMakeExe
property can be used- property can be spcified by
dotnet build -p:CMakeExe=/path/to/cmake
- property can be spcified by
- if you want to get release build,
Then you will get built binary in /dir/to/project/builddir/[Configuration]/[Platform(default is 'any')]/[Configuration]
if you want to create project from dotnet new
, you can do it by installing templates for cmake project.
- do
dotnet new -i MSBuild.Sdk.CMake.Template.Library
to install library template - do
dotnet new -i MSBuild.Sdk.CMake.Template.Console
to install console template - do
dotnet new cmlib --name [project name]
, then cmake library project will be created - do
dotnet new cmconsole --name [project name]
, then cmake console project will be created - after project creation, you can build project by
dotnet build
By default, build
task execute Configure
task before main build.
If you want to configure project only, execute dotnet msbuild [path to project file] /t:Configure
if you want to clean up the built binary, execute dotnet clean [path to project file]
.
Note this target only delete CMake cache file(CMakeCache.txt) and some intermediate files.
if you want to delete whole directory including all intermediated objects, execute dotnet msbuild /t:AllClean
if you want to custom cmake target(like install
), execute dotnet msbuild [path to project file] /t:ExecuteTarget /p:CMakeTarget=[your custom target name]
.
Or you can add custom target by edit project file.
<Project Sdk="MSBuild.Sdk.CMake/0.1.0">
<Target Name="Install">
<MSBuild Projects="$(MSBuildThisFileFullPath)"
Targets="ExecuteTarget"
Properties="CMakeTarget=install;Configuration=$(Configuration);Platform=$(Platform)"/>
</Target>
</Project>
and then, execute dotnet msbuild /t:Install
Following item can be added to ItemGroup
Definitions passed when Configure
task.
you must set Value
metadata.
for example;
<ItemGroup>
<CMakeDefine Include="A" Value="B"/>
</ItemGroup>
then passed -D"A=B"
to Configure
task.
Path to cmake
executable file,default is cmake
Name of cmake generator(available items can be seen by cmake --help
)
build platform, default using msbuild's $(Platform)
value, or default
if not set $(Platform)
build configuration, default using msbuild's $(Configuration)
value
the value passed as CMAKE_INSTALL_PREFIX when configure task.
do cmake configure task(cd $(CMakeBuildRootDirectory) && cmake $(CMakeRootDirectory)
)
do cmake's default build target.
depends on Congiure
task.
do cmake's clean
target.
This task will be skipped if Configure
task is not executed.
delete $(CMakeBuildDirectory)/CMakeCache.txt
.
do BuildClean
and ConfigClean
do Clean
and Build
delete $(CMakeBuildRootDirectory)
do custom cmake target.
do cmake install
target