| 1 | set(NUGET_PACKAGES Microsoft.WSL.PluginApi.nuspec Microsoft.WSL.Containers.nuspec) |
| 2 | set(WSL_NUGET_TARGET_FRAMEWORK "net8.0-windows10.0.19041.0") |
| 3 | |
| 4 | # Generate vars with native paths since nuget won't accept unix path separators. |
| 5 | cmake_path(NATIVE_PATH CMAKE_SOURCE_DIR CMAKE_SOURCE_DIR_NATIVE) |
| 6 | cmake_path(NATIVE_PATH CMAKE_BINARY_DIR CMAKE_BINARY_DIR_NATIVE) |
| 7 | |
| 8 | # For the WSLC SDK, we allow packaging only one platform or not including the C# projection |
| 9 | # to make it easier to build a local package for development. |
| 10 | # The list files needed in each case are included conditionally from a nuspec fragment. |
| 11 | |
| 12 | # Read a nuspec fragment .in file and expand its CMake variables into the named variable. |
| 13 | # Pass PLATFORM <arch> to bind the ${PLATFORM} placeholder in the fragment. |
| 14 | function(read_nuspec_fragment var path) |
| 15 | cmake_parse_arguments(ARG "" "PLATFORM" "" ${ARGN}) |
| 16 | if(DEFINED ARG_PLATFORM) |
| 17 | set(PLATFORM "${ARG_PLATFORM}") |
| 18 | endif() |
| 19 | file(READ "${path}" content) |
| 20 | string(CONFIGURE "${content}" content) |
| 21 | set(${var} "${content}" PARENT_SCOPE) |
| 22 | endfunction() |
| 23 | |
| 24 | # C# SDK wrapper DLL — AnyCPU, produced for any TARGET_PLATFORM. |
| 25 | if(WSL_INCLUDE_SDK_CSHARP) |
| 26 | read_nuspec_fragment(NUGET_SDKCS_FILE "${CMAKE_CURRENT_LIST_DIR}/fragments/wslc-cs.nuspec.in") |
| 27 | else() |
| 28 | set(NUGET_SDKCS_FILE "") |
| 29 | endif() |
| 30 | |
| 31 | # x64 native runtime — include when this is an x64 build, or for a multi-arch package. |
| 32 | if(TARGET_PLATFORM STREQUAL "x64" OR NOT WSL_NUGET_SINGLE_PLATFORM) |
| 33 | read_nuspec_fragment(NUGET_X64_RUNTIMES "${CMAKE_CURRENT_LIST_DIR}/fragments/wslc-runtime.nuspec.in" PLATFORM x64) |
| 34 | else() |
| 35 | set(NUGET_X64_RUNTIMES "") |
| 36 | endif() |
| 37 | |
| 38 | # arm64 native runtime — include when this is an arm64 build, or for a multi-arch package. |
| 39 | if(TARGET_PLATFORM STREQUAL "arm64" OR NOT WSL_NUGET_SINGLE_PLATFORM) |
| 40 | read_nuspec_fragment(NUGET_ARM64_RUNTIMES "${CMAKE_CURRENT_LIST_DIR}/fragments/wslc-runtime.nuspec.in" PLATFORM arm64) |
| 41 | else() |
| 42 | set(NUGET_ARM64_RUNTIMES "") |
| 43 | endif() |
| 44 | |
| 45 | # Generate the .nuspec files |
| 46 | foreach(PACKAGE ${NUGET_PACKAGES}) |
| 47 | configure_file("${CMAKE_CURRENT_LIST_DIR}/${PACKAGE}.in" "${CMAKE_BINARY_DIR}/${PACKAGE}") |
| 48 | endforeach() |