Skip to content

Adding WindowsML CMake samples - #519

Merged
Mark Schofield (mschofie) merged 3 commits into
microsoft:mainfrom
mschofie:mschofie/cmake-samples
Oct 29, 2025
Merged

Adding WindowsML CMake samples#519
Mark Schofield (mschofie) merged 3 commits into
microsoft:mainfrom
mschofie:mschofie/cmake-samples

Conversation

@mschofie

@mschofie Mark Schofield (mschofie) commented Sep 17, 2025

Copy link
Copy Markdown
Contributor

Description

This PR adds some CMake samples for WindowsML. There's a few moving parts, so there's things to be discussed. Having a PR for folks to try out and get a "stake in the ground" should make things easier.

The samples need to add NuGet support to CMake, so I'm proposing that infrastructure, too. At the minute, that content is hosted in a personal repo - https://github.com/mschofie/NuGetCMakePackage - that would need to be moved somewhere more appropriate before this PR could be completed. That repo teaches CMake how to restore NuGet packages, and look for CMake scripts within those packages, allowing a NuGet package to have functional parity with MSBuild builds. Since the NuGet packages that I need to consume don't have CMake scripts within, the 'NuGetCMakePackage' infrastructure allows for 'overlay' files that are present as a stop-gap until I can migrate the content appropriately. I've created a PR for the NuGet infrastructure here if folks want to ask questions, or comment on the implementation.

Beyond the NuGet changes, the samples build two C++ console applications with CMake, using 'Visual Studio 17 2022' and 'Ninja Multi-Config' generators. The NuGet support is added through:

include(FetchContent)

FetchContent_Declare(
  NuGetCMakePackage
  GIT_REPOSITORY https://github.com/mschofie/NuGetCMakePackage
  GIT_TAG b13e013481605d134f498fd9fc3a123c416da197
)

FetchContent_MakeAvailable(NuGetCMakePackage)

Then NuGet dependencies are created with - for example:

add_nuget_packages(
    PACKAGES
        Microsoft.Windows.ImplementationLibrary 1.0.250325.1
        Microsoft.Windows.CppWinRT 2.0.250303.1
        Microsoft.WindowsAppSDK.Runtime 1.8.250907001
        Microsoft.WindowsAppSDK.ML 1.8.2084
)

Having called add_nuget_packages, the NuGet packages are findable through find_package:

find_package(Microsoft.Windows.ImplementationLibrary CONFIG REQUIRED)
find_package(Microsoft.WindowsAppSDK.ML CONFIG REQUIRED)

After which a CMake target is introduced with the same name that can be consumed by the CMake build, for example:

target_link_libraries(ResNetConsoleDesktop
    PRIVATE
        ResNetCommon
        Microsoft.WindowsAppSDK.ML_Framework # Use 'framework' mode.
        Microsoft.Windows.ImplementationLibrary
)

Feedback on any aspect - sample, naming conventions, approach, etc.. - is really appreciated.

Checklist

Note that /azp run currently isn't working for this repo.

Comment thread Samples/WindowsML/Resources/ResNet50/model.onnx.data
Comment thread Samples/WindowsML/cpp-cmake/ResNetCommon/pch.h
Comment thread Samples/WindowsML/cpp-cmake/Configuration.cmake
Comment thread Samples/WindowsML/cpp-cmake/CMakeLists.txt Outdated
Comment thread Samples/WindowsML/cpp-cmake/.gitignore Outdated
@@ -0,0 +1 @@
__* No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing something wrong because this has no effect on a local clone & build. I'm seeing all the build/* content as well as the __* dirs still listed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not sure what could be going on... it's all good on my end. The file was missing it's final new-line... Perhaps that was it? Added it just in case.

@mschofie
Mark Schofield (mschofie) force-pushed the mschofie/cmake-samples branch 4 times, most recently from a6d064e to 52ce69a Compare September 30, 2025 18:23
@mschofie
Mark Schofield (mschofie) force-pushed the mschofie/cmake-samples branch 3 times, most recently from 45f0b58 to 1323083 Compare October 13, 2025 21:35
@mschofie
Mark Schofield (mschofie) changed the base branch from feature/winml-stable to release/experimental October 13, 2025 21:35
Comment thread Samples/WindowsML/cpp-cmake/ResNetCommon/ResNetModelHelper.cpp Outdated
@mschofie
Mark Schofield (mschofie) changed the base branch from release/experimental to main October 16, 2025 00:13
@mschofie

Copy link
Copy Markdown
Contributor Author

I've completed the PR in https://github.com/mschofie/NuGetCMakePackage, and updated this PR with the commit hash from that repo's main.

@jonwis Jon Wiswall (jonwis) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Mark Schofield (@mschofie) ! This is great!

@mschofie
Mark Schofield (mschofie) merged commit 4be8a9f into microsoft:main Oct 29, 2025
@mschofie
Mark Schofield (mschofie) deleted the mschofie/cmake-samples branch October 29, 2025 21:45
@Scottj1s

Copy link
Copy Markdown
Member

Sorry for the belated feedback - my only concern is with the hardcoded activatableClass manifests in the NuGetCMakePackage project. I left a comment there suggesting build logic (e.g., an xslt) to transform each WinAppSDK nuget package's runtimes-framework\package.appxfragment into fusion schema, and then mt.exe merge up for the referencing app.

@mschofie

Copy link
Copy Markdown
Contributor Author

Sorry for the belated feedback - my only concern is with the hardcoded activatableClass manifests in the NuGetCMakePackage project. I left a comment there suggesting build logic (e.g., an xslt) to transform each WinAppSDK nuget package's runtimes-framework\package.appxfragment into fusion schema, and then mt.exe merge up for the referencing app.

Thanks! Yes, I 100% agree, the hardcoded 'activatableClass' entries are definitely a problem. I've been tracking Issues over in this repo, but don't have anything tracking that. Oh, hey! You filed an issue - thanks! I'll go and comment there. TBH, though, the main 'next step' is in this discussion, where I think there's an opportunity to move responsibilities around a little, and win32-manifest generation is definitely something I've been thinking about. As I mention there, having all the pieces "written down" is - I think - a useful milestone, but getting responsibilities in the right place with the right tooling, is going to take a little work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants