Repository: conan-io/conan

Issue:
Cannot set CMAKE_SYSTEM_VERSION without setting CMAKE_SYSTEM_NAME
To help us debug your issue please explain:

- [ x] I've read the [CONTRIBUTING guide](https://raw.githubusercontent.com/conan-io/conan/develop/.github/CONTRIBUTING.md).
- [ x] I've specified the Conan version, operating system version and any tool that can be relevant.
- [x ] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.

Using conan 1.5.2, on Windows, with CMake and Visual Studio 2015.

Conan's CMake support seems to assume that `CMAKE_SYSTEM_VERSION` is only useful for cross-compiling, so it ignores the `CONAN_CMAKE_SYSTEM_VERSION` environment variable unless you also set `CMAKE_SYSTEM_NAME` somehow. However, with Visual Studio, it can be used to select the Windows Kit to use (eg: 8.1 to target Windows versions back to Vista). This works like the `MACOSX_DEPLOYMENT_TARGET` environment variable on macOS.

I'm using profiles to manage these. So in our macos profiles, I've set

    [env]
    MACOSX_DEPLOYMENT_TARGET=10.10

and in the Windows ones, I want to set

    [env]
    CONAN_CMAKE_SYSTEM_VERSION=8.1

However, I also need to set `CONAN_CMAKE_SYSTEM_NAME=Windows` for this to work. This isn't a bit problem, but it is somewhat redundant. The bigger issue is that the documentation does not make this clear at all - I only found this out by digging through the conan source code.

In summary, I would like to see `CONAN_CMAKE_SYSTEM_VERSION` respected even if `CONAN_CMAKE_SYSTEM_NAME` is not set, or - if that's not acceptable for whatever reason - the dependency should at least be documented at https://docs.conan.io/en/latest/reference/env_vars.html#cmake-related-variables.


Discussion:
Hi, thanks for sharing it. We will take a look for the 1.7 release. The 1.6 is already packed and would be impossible.

Resolving patch:
diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py
--- a/conans/client/build/cmake.py
+++ b/conans/client/build/cmake.py
@@ -178,17 +178,16 @@ def _cmake_cross_build_defines(self):
         # System name and system version
         if self._cmake_system_name is not True:  # String not empty
             ret["CMAKE_SYSTEM_NAME"] = self._cmake_system_name
-            ret["CMAKE_SYSTEM_VERSION"] = os_ver
         else:  # detect if we are cross building and the system name and version
             if cross_building(self._conanfile.settings):  # We are cross building
                 if self._os != self._os_build:
                     if self._os:  # the_os is the host (regular setting)
                         ret["CMAKE_SYSTEM_NAME"] = "Darwin" if self._os in ["iOS", "tvOS",
                                                                             "watchOS"] else self._os
-                        if os_ver:
-                            ret["CMAKE_SYSTEM_VERSION"] = os_ver
                     else:
                         ret["CMAKE_SYSTEM_NAME"] = "Generic"
+        if os_ver:
+            ret["CMAKE_SYSTEM_VERSION"] = os_ver
 
         # system processor
         cmake_system_processor = os.getenv("CONAN_CMAKE_SYSTEM_PROCESSOR", None)


Test patch: