Browse Source

VS: Implement CMAKE_GENERATOR_PLATFORM for VS >= 8

For VS generator names that do not specify the platform name, read
CMAKE_GENERATOR_PLATFORM to get it.

Extend the RunCMake.GeneratorPlatform test with a case covering
use of the x64 platform when the test generator is a Visual Studio
generator whose name does not specify a platform.
Brad King 11 years ago
parent
commit
b97736a23d

+ 12 - 5
Help/generator/Visual Studio 10 2010.rst

@@ -3,10 +3,17 @@ Visual Studio 10 2010
 
 
 Generates Visual Studio 10 (VS 2010) project files.
 Generates Visual Studio 10 (VS 2010) project files.
 
 
-It is possible to append a space followed by the platform name to
-create project files for a specific target platform.  E.g.
-"Visual Studio 10 2010 Win64" will create project files for the
-x64 processor; "Visual Studio 10 2010 IA64" for Itanium.
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
+to specify a target platform name.
+
+For compatibility with CMake versions prior to 3.1, one may specify
+a target platform name optionally at the end of this generator name:
+
+``Visual Studio 10 2010 Win64``
+  Specify target platform ``x64``.
+
+``Visual Studio 10 2010 IA64``
+  Specify target platform ``Itanium``.
 
 
 For compatibility with CMake versions prior to 3.0, one may specify this
 For compatibility with CMake versions prior to 3.0, one may specify this
-generator using the name "Visual Studio 10" without the year component.
+generator using the name ``Visual Studio 10`` without the year component.

+ 14 - 4
Help/generator/Visual Studio 11 2012.rst

@@ -3,10 +3,20 @@ Visual Studio 11 2012
 
 
 Generates Visual Studio 11 (VS 2012) project files.
 Generates Visual Studio 11 (VS 2012) project files.
 
 
-It is possible to append a space followed by the platform name to
-create project files for a specific target platform.  E.g.
-"Visual Studio 11 2012 Win64" will create project files for the
-x64 processor; "Visual Studio 11 2012 ARM" for ARM.
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
+to specify a target platform name.
+
+For compatibility with CMake versions prior to 3.1, one may specify
+a target platform name optionally at the end of this generator name:
+
+``Visual Studio 11 2012 Win64``
+  Specify target platform ``x64``.
+
+``Visual Studio 11 2012 ARM``
+  Specify target platform ``ARM``.
+
+``Visual Studio 11 2012 <WinCE-SDK>``
+  Specify target platform matching a Windows CE SDK name.
 
 
 For compatibility with CMake versions prior to 3.0, one may specify this
 For compatibility with CMake versions prior to 3.0, one may specify this
 generator using the name "Visual Studio 11" without the year component.
 generator using the name "Visual Studio 11" without the year component.

+ 11 - 4
Help/generator/Visual Studio 12 2013.rst

@@ -3,10 +3,17 @@ Visual Studio 12 2013
 
 
 Generates Visual Studio 12 (VS 2013) project files.
 Generates Visual Studio 12 (VS 2013) project files.
 
 
-It is possible to append a space followed by the platform name to
-create project files for a specific target platform.  E.g.
-"Visual Studio 12 2013 Win64" will create project files for the
-x64 processor; "Visual Studio 12 2013 ARM" for ARM.
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
+to specify a target platform name.
+
+For compatibility with CMake versions prior to 3.1, one may specify
+a target platform name optionally at the end of this generator name:
+
+``Visual Studio 12 2013 Win64``
+  Specify target platform ``x64``.
+
+``Visual Studio 12 2013 ARM``
+  Specify target platform ``ARM``.
 
 
 For compatibility with CMake versions prior to 3.0, one may specify this
 For compatibility with CMake versions prior to 3.0, one may specify this
 generator using the name "Visual Studio 12" without the year component.
 generator using the name "Visual Studio 12" without the year component.

+ 11 - 4
Help/generator/Visual Studio 14.rst

@@ -3,7 +3,14 @@ Visual Studio 14
 
 
 Generates Visual Studio 14 project files.
 Generates Visual Studio 14 project files.
 
 
-It is possible to append a space followed by the platform name to
-create project files for a specific target platform.  E.g.
-"Visual Studio 14 Win64" will create project files for the
-x64 processor; "Visual Studio 14 ARM" for ARM.
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
+to specify a target platform name.
+
+For compatibility with CMake versions prior to 3.1, one may specify
+a target platform name optionally at the end of this generator name:
+
+``Visual Studio 14 Win64``
+  Specify target platform ``x64``.
+
+``Visual Studio 14 ARM``
+  Specify target platform ``ARM``.

+ 11 - 3
Help/generator/Visual Studio 8 2005.rst

@@ -3,6 +3,14 @@ Visual Studio 8 2005
 
 
 Generates Visual Studio 8 2005 project files.
 Generates Visual Studio 8 2005 project files.
 
 
-It is possible to append a space followed by the platform name to
-create project files for a specific target platform.  E.g.  "Visual
-Studio 8 2005 Win64" will create project files for the x64 processor.
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
+to specify a target platform name.
+
+For compatibility with CMake versions prior to 3.1, one may specify
+a target platform name optionally at the end of this generator name:
+
+``Visual Studio 8 2005 Win64``
+  Specify target platform ``x64``.
+
+``Visual Studio 8 2005 <WinCE-SDK>``
+  Specify target platform matching a Windows CE SDK name.

+ 14 - 4
Help/generator/Visual Studio 9 2008.rst

@@ -3,7 +3,17 @@ Visual Studio 9 2008
 
 
 Generates Visual Studio 9 2008 project files.
 Generates Visual Studio 9 2008 project files.
 
 
-It is possible to append a space followed by the platform name to
-create project files for a specific target platform.  E.g.  "Visual
-Studio 9 2008 Win64" will create project files for the x64 processor;
-"Visual Studio 9 2008 IA64" for Itanium.
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
+to specify a target platform name.
+
+For compatibility with CMake versions prior to 3.1, one may specify
+a target platform name optionally at the end of this generator name:
+
+``Visual Studio 9 2008 Win64``
+  Specify target platform ``x64``.
+
+``Visual Studio 9 2008 IA64``
+  Specify target platform ``Itanium``.
+
+``Visual Studio 9 2008 <WinCE-SDK>``
+  Specify target platform matching a Windows CE SDK name.

+ 7 - 0
Help/release/dev/vs-generator-platform.rst

@@ -0,0 +1,7 @@
+vs-generator-platform
+---------------------
+
+* The Visual Studio generators for versions 8 (2005) and above
+  learned to read the target platform name from a new
+  :variable:`CMAKE_GENERATOR_PLATFORM` variable when it is
+  not specified as part of the generator name.

+ 13 - 1
Source/cmGlobalVisualStudio10Generator.cxx

@@ -125,6 +125,18 @@ bool cmGlobalVisualStudio10Generator::SetSystemName(std::string const& s,
     {
     {
     return false;
     return false;
     }
     }
+  return this->cmGlobalVisualStudio8Generator::SetSystemName(s, mf);
+}
+
+//----------------------------------------------------------------------------
+bool
+cmGlobalVisualStudio10Generator::SetGeneratorPlatform(std::string const& p,
+                                                      cmMakefile* mf)
+{
+  if(!this->cmGlobalVisualStudio8Generator::SetGeneratorPlatform(p, mf))
+    {
+    return false;
+    }
   if(this->GetPlatformName() == "Itanium" || this->GetPlatformName() == "x64")
   if(this->GetPlatformName() == "Itanium" || this->GetPlatformName() == "x64")
     {
     {
     if(this->IsExpressEdition() && !this->Find64BitTools(mf))
     if(this->IsExpressEdition() && !this->Find64BitTools(mf))
@@ -132,7 +144,7 @@ bool cmGlobalVisualStudio10Generator::SetSystemName(std::string const& s,
       return false;
       return false;
       }
       }
     }
     }
-  return this->cmGlobalVisualStudio8Generator::SetSystemName(s, mf);
+  return true;
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------

+ 1 - 0
Source/cmGlobalVisualStudio10Generator.h

@@ -31,6 +31,7 @@ public:
   virtual bool MatchesGeneratorName(const std::string& name) const;
   virtual bool MatchesGeneratorName(const std::string& name) const;
 
 
   virtual bool SetSystemName(std::string const& s, cmMakefile* mf);
   virtual bool SetSystemName(std::string const& s, cmMakefile* mf);
+  virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf);
   virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf);
   virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf);
 
 
   virtual void GenerateBuildCommand(
   virtual void GenerateBuildCommand(

+ 14 - 3
Source/cmGlobalVisualStudio7Generator.cxx

@@ -262,12 +262,25 @@ cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator()
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 std::string const& cmGlobalVisualStudio7Generator::GetPlatformName() const
 std::string const& cmGlobalVisualStudio7Generator::GetPlatformName() const
 {
 {
+  if(!this->GeneratorPlatform.empty())
+    {
+    return this->GeneratorPlatform;
+    }
   return this->DefaultPlatformName;
   return this->DefaultPlatformName;
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
 bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
                                                    cmMakefile* mf)
                                                    cmMakefile* mf)
+{
+  mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
+                    this->GetIntelProjectVersion());
+  return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf);
+}
+
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio7Generator::SetGeneratorPlatform(std::string const& p,
+                                                          cmMakefile* mf)
 {
 {
   if(this->GetPlatformName() == "x64")
   if(this->GetPlatformName() == "x64")
     {
     {
@@ -278,9 +291,7 @@ bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
     mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE");
     mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE");
     }
     }
   mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName().c_str());
   mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName().c_str());
-  mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
-                    this->GetIntelProjectVersion());
-  return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf);
+  return this->cmGlobalVisualStudioGenerator::SetGeneratorPlatform(p, mf);
 }
 }
 
 
 void cmGlobalVisualStudio7Generator::GenerateConfigurations(cmMakefile* mf)
 void cmGlobalVisualStudio7Generator::GenerateConfigurations(cmMakefile* mf)

+ 3 - 0
Source/cmGlobalVisualStudio7Generator.h

@@ -46,6 +46,8 @@ public:
 
 
   virtual bool SetSystemName(std::string const& s, cmMakefile* mf);
   virtual bool SetSystemName(std::string const& s, cmMakefile* mf);
 
 
+  virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf);
+
   /** Get the documentation entry for this generator.  */
   /** Get the documentation entry for this generator.  */
   static void GetDocumentation(cmDocumentationEntry& entry);
   static void GetDocumentation(cmDocumentationEntry& entry);
 
 
@@ -175,6 +177,7 @@ protected:
   // Set during OutputSLNFile with the name of the current project.
   // Set during OutputSLNFile with the name of the current project.
   // There is one SLN file per project.
   // There is one SLN file per project.
   std::string CurrentProject;
   std::string CurrentProject;
+  std::string GeneratorPlatform;
   std::string DefaultPlatformName;
   std::string DefaultPlatformName;
   bool MasmEnabled;
   bool MasmEnabled;
 
 

+ 15 - 0
Source/cmGlobalVisualStudio8Generator.cxx

@@ -158,6 +158,21 @@ void cmGlobalVisualStudio8Generator::AddPlatformDefinitions(cmMakefile* mf)
   }
   }
 }
 }
 
 
+//----------------------------------------------------------------------------
+bool cmGlobalVisualStudio8Generator::SetGeneratorPlatform(std::string const& p,
+                                                          cmMakefile* mf)
+{
+  if(this->DefaultPlatformName == "Win32")
+    {
+    this->GeneratorPlatform = p;
+    return this->cmGlobalVisualStudio7Generator::SetGeneratorPlatform("", mf);
+    }
+  else
+    {
+    return this->cmGlobalVisualStudio7Generator::SetGeneratorPlatform(p, mf);
+    }
+}
+
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 // ouput standard header for dsw file
 // ouput standard header for dsw file
 void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream& fout)
 void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream& fout)

+ 2 - 0
Source/cmGlobalVisualStudio8Generator.h

@@ -40,6 +40,8 @@ public:
                               cmMakefile *, bool optional);
                               cmMakefile *, bool optional);
   virtual void AddPlatformDefinitions(cmMakefile* mf);
   virtual void AddPlatformDefinitions(cmMakefile* mf);
 
 
+  virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf);
+
   /**
   /**
    * Override Configure and Generate to add the build-system check
    * Override Configure and Generate to add the build-system check
    * target.
    * target.

+ 9 - 3
Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake

@@ -2,6 +2,12 @@ include(RunCMake)
 
 
 run_cmake(NoPlatform)
 run_cmake(NoPlatform)
 
 
-set(RunCMake_TEST_OPTIONS "-DCMAKE_GENERATOR_PLATFORM=Bad Platform")
-run_cmake(BadPlatform)
-unset(RunCMake_TEST_OPTIONS)
+if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio ([89]|1[0124])( 20[0-9][0-9])?$")
+  set(RunCMake_TEST_OPTIONS "-DCMAKE_GENERATOR_PLATFORM=x64")
+  run_cmake(x64Platform)
+  unset(RunCMake_TEST_OPTIONS)
+else()
+  set(RunCMake_TEST_OPTIONS "-DCMAKE_GENERATOR_PLATFORM=Bad Platform")
+  run_cmake(BadPlatform)
+  unset(RunCMake_TEST_OPTIONS)
+endif()

+ 2 - 0
Tests/RunCMake/GeneratorPlatform/x64Platform-stdout.txt

@@ -0,0 +1,2 @@
+-- CMAKE_GENERATOR_PLATFORM is 'x64' as expected.
+-- CMAKE_VS_PLATFORM_NAME is 'x64' as expected.

+ 7 - 0
Tests/RunCMake/GeneratorPlatform/x64Platform.cmake

@@ -0,0 +1,7 @@
+foreach(v CMAKE_GENERATOR_PLATFORM CMAKE_VS_PLATFORM_NAME)
+  if("x${${v}}" STREQUAL "xx64")
+    message(STATUS "${v} is 'x64' as expected.")
+  else()
+    message(FATAL_ERROR "${v} is '${${v}}' but should be 'x64'!")
+  endif()
+endforeach()