VS: Select Windows SDK version

I have Win10 64 bit, and VS2017. I have a CMakeLists.txt and a Makefile which looks like this:

build/Makefile:	CMakeLists.txt
	mkdir -p build; \
	cd build; \
	cmake ../ -DCMAKE_TOOLCHAIN_FILE=~/github/vcpkg/scripts/buildsystems/vcpkg.cmake

clean:
	rm -rf build/

When I run make, I got:

    Build started 5/3/2022 12:36:26 PM.
    Project "C:\Project\MyProject\build\CMakeFiles\3.21.1\VCTargetsPath.vcxproj" on node 1 (default targets).
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.Cpp.WindowsSDK.targets(46,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [C:\Project\MyProject\build\CMakeFiles\3.21.1\VCTargetsPath.vcxproj]
    Done Building Project "C:\Project\MyProject\build\CMakeFiles\3.21.1\VCTargetsPath.vcxproj" (default targets) -- FAILED.

    Build FAILED.

    "C:\Project\MyProject\build\CMakeFiles\3.21.1\VCTargetsPath.vcxproj" (default target) (1) ->
    (_CheckWindowsSDKInstalled target) ->
      C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.Cpp.WindowsSDK.targets(46,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [C:\Project\MyProject\build\CMakeFiles\3.21.1\VCTargetsPath.vcxproj]

        0 Warning(s)
        1 Error(s)

    Time Elapsed 00:00:00.33


  Exit code: 1

My question is: how can I setup my current platform toolset, which is 10.0.17763.0 ?

You can pass -T to select a toolset for the Visual Studio generators. We pass v143,version=14.31.31103 for one of our CI builds. I feel like 10.0.17763.0 is an SDK version, not a toolchain version (unless you’re using a VS2010-era toolchain?). You might just be missing the right SDK selection in the VS installer.

Yes, that number, 10.0.17763.0, it’s Windows SDK version:

image

I’ll try what you said, to put my SDK version using -T option, first, I need to figure out where should I put this option … right now I have:

CMakeLists.txt and Makefile files only, CMakeCache.txt it’s generated.

I’m not cmake advanced :smiley:

The command I gave needs to know the toolchain version. I’m not actually sure how to specify the SDK version to CMake off hand… @brad.king?

I think you want to set CMAKE_SYSTEM_VERSION to 10.0.17763.0, but I’m not sure if you will also need to set CMAKE_SYSTEM_NAME to something as well. Ordinarily, you would set variables like these in your toolchain file, but I see that you’re using vcpkg’s toolchain file. I think that supports being able to pass in another toolchain file to chain along to, but you’d have to look up how to do that. Alternatively, you might be able to get away with setting these variables on the cmake command line using something along the lines of cmake -DCMAKE_SYSTEM_VERSION=10.0.17763.0 ...

Yes, CMAKE_SYSTEM_VERSION can be set on host builds to select the Windows SDK version with VS generators. Running cmake -DCMAKE_SYSTEM_VERSION=10.0.17763.0 ... should work.

Even if I got another errors, I guess my reported issue has been solved:

C:\Project\my-project>make
mkdir -p build; \
        cd build; \
        cmake ../ -DCMAKE_TOOLCHAIN_FILE=C:/Project/vcpkg/scripts/buildsystems/vcpkg.cmake
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19044.
-- The CXX compiler identification is MSVC 19.16.27045.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - broken
CMake Error at C:/Home/Flaviu/cmake-3.21.1-windows-x86_64/share/cmake-3.21/Modules/CMakeTestCXXCompiler.cmake:62 (message):
  The C++ compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe"

  is not able to compile a simple test program.

Note: Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19044.

So, I thank you for your assistance and implication !

BTW, commenting the following line:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")

into my CMakeLists.txt got me into generating successfully the solution. In case anyone need it.