Repository: conan-io/conan

Issue:
Improper CMake generator string
Currently, the generator string passed to CMake is formatted like this in cmake.py: `"Visual Studio %s" % self._settings.compiler.version`, which results in e.g. "Visual Studio 14". However, the correct string would be "Visual Studio 14 2015". For newer compiler versions, CMake supports the short version due to backward compatibility reasons, but when e.g. trying to use Visual Studio 2008, the generated string "Visual Studio 9" results in a CMake error (generator cannot be found), since it only supports the full string there ("Visual Studio 9 2008").



Discussion:

Resolving patch:
diff --git a/conans/client/cmake.py b/conans/client/cmake.py
--- a/conans/client/cmake.py
+++ b/conans/client/cmake.py
@@ -21,8 +21,8 @@ def options_cmd_line(options, option_upper=True, value_upper=True):
     @property
     def generator(self):
         if (not self._settings.compiler or
-            not self._settings.compiler.version or
-            not self._settings.arch):
+                not self._settings.compiler.version or
+                not self._settings.arch):
             raise ConanException("You must specify compiler, compiler.version and arch in "
                                  "your settings to use a CMake generator")
 
@@ -31,7 +31,14 @@ def generator(self):
         arch = str(self._settings.arch) if self._settings.arch else None
 
         if compiler == "Visual Studio":
-            base = "Visual Studio %s" % self._settings.compiler.version
+            _visuals = {'8': '8 2005',
+                        '9': '9 2008',
+                        '10': '10 2010',
+                        '11': '11 2012',
+                        '12': '12 2013',
+                        '14': '14 2015'}
+            str_ver = str(self._settings.compiler.version)
+            base = "Visual Studio %s" % _visuals.get(str_ver, "UnknownVersion %s" % str_ver)
             if arch == "x86_64":
                 return base + " Win64"
             elif arch == "arm":
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -18,7 +18,7 @@
 
 def get_requires(filename):
     requirements = []
-    with open(filename) as req_file:
+    with open(filename, "rt") as req_file:
         for line in req_file.read().splitlines():
             if not line.strip().startswith("#"):
                 requirements.append(line)
@@ -31,8 +31,9 @@ def get_requires(filename):
 
 def load_version():
     '''Loads a file content'''
-    filename = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "conans", "__init__.py"))
-    with open(filename) as version_file:
+    filename = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
+                                            "conans", "__init__.py"))
+    with open(filename, "rt") as version_file:
         conan_init = version_file.read()
         version = re.search("__version__ = '([0-9a-z.]+)'", conan_init).group(1)
         return version
@@ -40,7 +41,7 @@ def load_version():
 
 # def generate_long_description_file():
 #     import pypandoc
-# 
+#
 #     output = pypandoc.convert('README.md', 'rst')
 #     return output
 


Test patch:
diff --git a/conans/test/cmake_test.py b/conans/test/cmake_test.py
--- a/conans/test/cmake_test.py
+++ b/conans/test/cmake_test.py
@@ -13,16 +13,16 @@ def loads_default_test(self):
         settings.arch = "x86"
 
         cmake = CMake(settings)
-        self.assertEqual('-G "Visual Studio 12"   -DCONAN_COMPILER="Visual Studio" '
+        self.assertEqual('-G "Visual Studio 12 2013"   -DCONAN_COMPILER="Visual Studio" '
                          '-DCONAN_COMPILER_VERSION="12" -Wno-dev', cmake.command_line)
         self.assertEqual('', cmake.build_config)
         settings.build_type = "Debug"
-        self.assertEqual('-G "Visual Studio 12"   -DCONAN_COMPILER="Visual Studio" '
+        self.assertEqual('-G "Visual Studio 12 2013"   -DCONAN_COMPILER="Visual Studio" '
                          '-DCONAN_COMPILER_VERSION="12" -Wno-dev', cmake.command_line)
         self.assertEqual('--config Debug', cmake.build_config)
 
         settings.arch = "x86_64"
-        self.assertEqual('-G "Visual Studio 12 Win64"   -DCONAN_COMPILER="Visual Studio" '
+        self.assertEqual('-G "Visual Studio 12 2013 Win64"   -DCONAN_COMPILER="Visual Studio" '
                          '-DCONAN_COMPILER_VERSION="12" -Wno-dev', cmake.command_line)
 
         settings.os = "Windows"