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.
This commit is contained in:
Brad King 2014-09-05 14:53:01 -04:00
parent 0f1f1271e6
commit b97736a23d
16 changed files with 146 additions and 31 deletions

View File

@ -3,10 +3,17 @@ Visual Studio 10 2010
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
generator using the name "Visual Studio 10" without the year component.
generator using the name ``Visual Studio 10`` without the year component.

View File

@ -3,10 +3,20 @@ Visual Studio 11 2012
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
generator using the name "Visual Studio 11" without the year component.

View File

@ -3,10 +3,17 @@ Visual Studio 12 2013
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
generator using the name "Visual Studio 12" without the year component.

View File

@ -3,7 +3,14 @@ Visual Studio 14
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``.

View File

@ -3,6 +3,14 @@ Visual Studio 8 2005
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.

View File

@ -3,7 +3,17 @@ Visual Studio 9 2008
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.

View File

@ -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.

View File

@ -125,6 +125,18 @@ bool cmGlobalVisualStudio10Generator::SetSystemName(std::string const& s,
{
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->IsExpressEdition() && !this->Find64BitTools(mf))
@ -132,7 +144,7 @@ bool cmGlobalVisualStudio10Generator::SetSystemName(std::string const& s,
return false;
}
}
return this->cmGlobalVisualStudio8Generator::SetSystemName(s, mf);
return true;
}
//----------------------------------------------------------------------------

View File

@ -31,6 +31,7 @@ public:
virtual bool MatchesGeneratorName(const std::string& name) const;
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 void GenerateBuildCommand(

View File

@ -262,12 +262,25 @@ cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator()
//----------------------------------------------------------------------------
std::string const& cmGlobalVisualStudio7Generator::GetPlatformName() const
{
if(!this->GeneratorPlatform.empty())
{
return this->GeneratorPlatform;
}
return this->DefaultPlatformName;
}
//----------------------------------------------------------------------------
bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
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")
{
@ -278,9 +291,7 @@ bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE");
}
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)

View File

@ -46,6 +46,8 @@ public:
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. */
static void GetDocumentation(cmDocumentationEntry& entry);
@ -175,6 +177,7 @@ protected:
// Set during OutputSLNFile with the name of the current project.
// There is one SLN file per project.
std::string CurrentProject;
std::string GeneratorPlatform;
std::string DefaultPlatformName;
bool MasmEnabled;

View File

@ -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
void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream& fout)

View File

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

View File

@ -2,6 +2,12 @@ include(RunCMake)
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()

View File

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

View File

@ -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()