Select Windows SDK version when building using cmake

Read cmake online doc carefully, https://cmake.org/cmake/help/latest/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.html

So when we build project which has CMakeLists.txt, we can select Windows SDK version in this way:

  1. In explorer, navigate to like C:\Program Files (x86)\Windows Kits\10\Include.
  2. For cmake always finds the newest version to build our project, we can just rename all sdk versions which is newer than we want. e.g. if we want 10.0.19041.0 to build our project, but 10.0.22581.0 is newer, we rename 10.0.22581.0 to 10.0.0.22581.0, the rule is among tokens split by period signs, the third token number is the key word that cmake sorts them to get the largest as newest.
  3. Start cmake to configure the project, it will find the right sdk version.
  4. After cmake is done in configuration, rename 10.0.0.22581.0 back to 10.0.22581.0.