Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 11 additions & 33 deletions Samples/CMake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ FetchContent_Declare(

FetchContent_MakeAvailable(NuGetCMakePackage)

#----------------------------------------------------------------------------------------------------------------------
# These samples illustrate individual component usage — picking and choosing between the
# NuGet packages shipped as part of the WindowsAppSDK. If you want the entirety of the
# WindowsAppSDK pulled in via a single dependency, see the Metapackage sample for a
# better illustration of that use case.
#----------------------------------------------------------------------------------------------------------------------

add_nuget_packages(
CONFIG_FILE ${CMAKE_SOURCE_DIR}/nuget.config
LOCK_FILE ${CMAKE_SOURCE_DIR}/packages.lock.json
Expand All @@ -42,12 +49,13 @@ add_nuget_packages(
Microsoft.WindowsAppSDK.Widgets 2.0.4-experimental
Microsoft.WindowsAppSDK.AI 2.0.179-experimental
Microsoft.WindowsAppSDK.ML 2.0.325-experimental
Microsoft.Web.WebView2 1.0.3719.77
Microsoft.WindowsAppSDK.WinUI 2.0.10-experimental
)

find_package(Microsoft.WindowsAppSDK.Base CONFIG REQUIRED)
find_package(Microsoft.WindowsAppSDK.Runtime CONFIG REQUIRED)
find_package(Microsoft.WindowsAppSDK.Foundation CONFIG REQUIRED)
find_package(Microsoft.WindowsAppSDK.InteractiveExperiences CONFIG REQUIRED)
find_package(Microsoft.WindowsAppSDK.DWrite CONFIG REQUIRED)
find_package(Microsoft.WindowsAppSDK.Widgets CONFIG REQUIRED)
find_package(Microsoft.WindowsAppSDK.AI CONFIG REQUIRED)
Expand All @@ -58,38 +66,8 @@ find_package(Microsoft.WindowsAppSDK.WinUI CONFIG REQUIRED)
include(${CMAKE_SOURCE_DIR}/Configuration.cmake)
link_libraries(Configuration)

# Macro to copy runtime DLLs to the output directory
macro(post_build_runtime_dll_copy target_name)
if(WIN32)
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND "${CMAKE_COMMAND};-E;$<IF:$<BOOL:$<TARGET_RUNTIME_DLLS:${target_name}>>,copy;$<TARGET_RUNTIME_DLLS:${target_name}>;$<TARGET_FILE_DIR:${target_name}>,true>"
COMMAND_EXPAND_LISTS
)
endif()
endmacro()

# For pure WinRT components (Widgets, AI, WinUI) that have no import libraries (.lib).
# These components store DLL paths in a custom INTERFACE_SELFCONTAINED_RUNTIME_DLLS property instead. This macro
# reads that property and copies the DLLs via post-build commands.
macro(post_build_selfcontained_dll_copy target_name)
foreach(_sc_target
Microsoft.WindowsAppSDK.Widgets_SelfContained
Microsoft.WindowsAppSDK.AI_SelfContained
Microsoft.WindowsAppSDK.ML_SelfContained
Microsoft.WindowsAppSDK.WinUI_SelfContained
)
if(TARGET ${_sc_target})
get_property(_sc_dlls TARGET ${_sc_target} PROPERTY INTERFACE_SELFCONTAINED_RUNTIME_DLLS)
if(_sc_dlls)
foreach(_dll IN LISTS _sc_dlls)
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_dll}" "$<TARGET_FILE_DIR:${target_name}>"
)
endforeach()
endif()
endif()
endforeach()
endmacro()
# Post-build helpers are provided by
# Microsoft.WindowsAppSDK.Base via WindowsAppSDKHelpers.cmake.

# Subdirectories
add_subdirectory(UnpackagedSelfContained)
Expand Down
74 changes: 74 additions & 0 deletions Samples/CMake/Metapackage/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#----------------------------------------------------------------------------------------------------------------------
# Metapackage samples — shared root
#
# Demonstrates the new umbrella consumption shape for Microsoft.WindowsAppSDK across the four
# deployment-matrix combinations (Packaged/Unpackaged × Framework-dep/Self-contained):
#
# - Single add_nuget_packages() entry for the metapackage. Every component the metapackage
# transitively pulls in is automatically materialized.
# - Single find_package(Microsoft.WindowsAppSDK CONFIG REQUIRED). The umbrella config
# materializes every component.
# - Each sample subdirectory is thin: project + add_executable + per-target properties
# (WindowsPackageType, WindowsAppSDKSelfContained, auto-init switches) + single
# target_link_libraries(... Microsoft.WindowsAppSDK).
# - No per-component find_package or per-target *_Framework / *_SelfContained suffix linking.
#----------------------------------------------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.31)

cmake_policy(SET CMP0141 NEW)
cmake_policy(SET CMP0117 NEW)

if(CMAKE_GENERATOR MATCHES "^Visual Studio")
file(WRITE "${CMAKE_BINARY_DIR}/Directory.Build.rsp" "-m -graphBuild:true -p:UseMultiToolTask=true -nodeReuse:false -terminalLogger:auto")
file(WRITE "${CMAKE_BINARY_DIR}/Directory.Build.props" "<Project></Project>")
file(WRITE "${CMAKE_BINARY_DIR}/Directory.Build.targets" "<Project></Project>")
elseif(CMAKE_GENERATOR MATCHES "^Ninja")
if(NOT (DEFINED ENV{Platform}))
message(FATAL_ERROR "When using the Ninja generator, you must build from a platform-specific Developer Command Prompt.")
endif()
endif()

project(MetapackageSamples LANGUAGES CXX)

include(FetchContent)

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

FetchContent_MakeAvailable(NuGetCMakePackage)

add_nuget_packages(
CONFIG_FILE ${CMAKE_SOURCE_DIR}/../nuget.config
LOCK_FILE ${CMAKE_SOURCE_DIR}/packages.lock.json
FRAMEWORK native
PACKAGES
Microsoft.Windows.CppWinRT 2.0.251203.1
Microsoft.WindowsAppSDK 2.0.0-experimental7
)

# Single find_package — the metapackage's umbrella config materializes every component.
find_package(Microsoft.WindowsAppSDK CONFIG REQUIRED)

# Common compiler configuration
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN UNICODE _UNICODE)

#----------------------------------------------------------------------------------------------------------------------
# Post-build helpers
#
# wasdk_post_build_copy() and friends are provided by Microsoft.WindowsAppSDK.Base via
# WindowsAppSDKHelpers.cmake. Loaded transitively by every component find_package call,
# so consumer CMakeLists files do not need to define any post-build plumbing themselves.
#----------------------------------------------------------------------------------------------------------------------

#----------------------------------------------------------------------------------------------------------------------
# Sub-samples (one per deployment matrix cell)
#----------------------------------------------------------------------------------------------------------------------
add_subdirectory(PackagedFrameworkDependent)
add_subdirectory(PackagedSelfContained)
add_subdirectory(UnpackagedFrameworkDependent)
add_subdirectory(UnpackagedSelfContained)
36 changes: 36 additions & 0 deletions Samples/CMake/Metapackage/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 31,
"patch": 0
},
"configurePresets": [
{
"name": "vs2022-x64",
"displayName": "Visual Studio 2022 x64",
"generator": "Visual Studio 17 2022",
"architecture": "x64",
"binaryDir": "D:/b/meta-vs64",
"cacheVariables": {
"FETCHCONTENT_SOURCE_DIR_NUGETCMAKEPACKAGE": "D:/UndockedProjects/NugetCMakePackage"
}
},
{
"name": "ninja-x64",
"displayName": "Ninja Multi-Config x64",
"generator": "Ninja Multi-Config",
"binaryDir": "D:/b/meta-nx64",
"cacheVariables": {
"CMAKE_OBJECT_PATH_MAX": "1000",
"FETCHCONTENT_SOURCE_DIR_NUGETCMAKEPACKAGE": "D:/UndockedProjects/NugetCMakePackage"
}
}
],
"buildPresets": [
{ "name": "vs2022-x64-debug", "configurePreset": "vs2022-x64", "configuration": "Debug" },
{ "name": "vs2022-x64-release", "configurePreset": "vs2022-x64", "configuration": "Release" },
{ "name": "ninja-x64-debug", "configurePreset": "ninja-x64", "configuration": "Debug" },
{ "name": "ninja-x64-release", "configurePreset": "ninja-x64", "configuration": "Release" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#----------------------------------------------------------------------------------------------------------------------
# Metapackage_PackagedFrameworkDependent
# Packaged + Framework-dependent. Default mode (no WindowsAppSDKSelfContained property set).
#----------------------------------------------------------------------------------------------------------------------
project(Metapackage_PackagedFrameworkDependent LANGUAGES CXX)

add_executable(Metapackage_PackagedFrameworkDependent WIN32
main.cpp
)

set_target_properties(Metapackage_PackagedFrameworkDependent PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL"
# Packaged FW: WindowsPackageType defaults to MSIX → DeploymentManager auto-init enabled by default.
WindowsAppSdkDeploymentManagerInitialize TRUE
# WindowsAppSDKSelfContained unset (default FALSE) → basic component targets resolve to _Framework.
)

# Single link entry — basic component targets inside the umbrella resolve to _Framework.
target_link_libraries(Metapackage_PackagedFrameworkDependent
PRIVATE
Microsoft.WindowsAppSDK
)

wasdk_post_build_copy(Metapackage_PackagedFrameworkDependent)

# Generate AppxManifest.xml with framework PackageDependency auto-injected.
wasdk_generate_appx_manifest(
TARGET Metapackage_PackagedFrameworkDependent
IDENTITY_NAME "CMake-Metapackage-PackagedFrameworkDependent"
IDENTITY_PUBLISHER "CN=TestPublisher"
IDENTITY_VERSION "1.0.0.0"
DISPLAY_NAME "Metapackage Packaged FW (CMake)"
DESCRIPTION "Packaged framework-dependent CMake test using metapackage umbrella"
)

add_custom_command(TARGET Metapackage_PackagedFrameworkDependent POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/Logo.png
$<TARGET_FILE_DIR:Metapackage_PackagedFrameworkDependent>
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading