From b97736a23d5d83eb65b6ee0b0429ada9fb331c12 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 5 Sep 2014 14:53:01 -0400 Subject: [PATCH] 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. --- Help/generator/Visual Studio 10 2010.rst | 17 ++++++++++++----- Help/generator/Visual Studio 11 2012.rst | 18 ++++++++++++++---- Help/generator/Visual Studio 12 2013.rst | 15 +++++++++++---- Help/generator/Visual Studio 14.rst | 15 +++++++++++---- Help/generator/Visual Studio 8 2005.rst | 14 +++++++++++--- Help/generator/Visual Studio 9 2008.rst | 18 ++++++++++++++---- Help/release/dev/vs-generator-platform.rst | 7 +++++++ Source/cmGlobalVisualStudio10Generator.cxx | 14 +++++++++++++- Source/cmGlobalVisualStudio10Generator.h | 1 + Source/cmGlobalVisualStudio7Generator.cxx | 17 ++++++++++++++--- Source/cmGlobalVisualStudio7Generator.h | 3 +++ Source/cmGlobalVisualStudio8Generator.cxx | 15 +++++++++++++++ Source/cmGlobalVisualStudio8Generator.h | 2 ++ .../GeneratorPlatform/RunCMakeTest.cmake | 12 +++++++++--- .../GeneratorPlatform/x64Platform-stdout.txt | 2 ++ .../GeneratorPlatform/x64Platform.cmake | 7 +++++++ 16 files changed, 146 insertions(+), 31 deletions(-) create mode 100644 Help/release/dev/vs-generator-platform.rst create mode 100644 Tests/RunCMake/GeneratorPlatform/x64Platform-stdout.txt create mode 100644 Tests/RunCMake/GeneratorPlatform/x64Platform.cmake diff --git a/Help/generator/Visual Studio 10 2010.rst b/Help/generator/Visual Studio 10 2010.rst index 000677a94..77ea9df02 100644 --- a/Help/generator/Visual Studio 10 2010.rst +++ b/Help/generator/Visual Studio 10 2010.rst @@ -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. diff --git a/Help/generator/Visual Studio 11 2012.rst b/Help/generator/Visual Studio 11 2012.rst index 42f6f9160..5fa7f2c76 100644 --- a/Help/generator/Visual Studio 11 2012.rst +++ b/Help/generator/Visual Studio 11 2012.rst @@ -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 `` + 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. diff --git a/Help/generator/Visual Studio 12 2013.rst b/Help/generator/Visual Studio 12 2013.rst index d2f491202..2c3b119a4 100644 --- a/Help/generator/Visual Studio 12 2013.rst +++ b/Help/generator/Visual Studio 12 2013.rst @@ -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. diff --git a/Help/generator/Visual Studio 14.rst b/Help/generator/Visual Studio 14.rst index 7f4fdc3ae..d621b7e5b 100644 --- a/Help/generator/Visual Studio 14.rst +++ b/Help/generator/Visual Studio 14.rst @@ -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``. diff --git a/Help/generator/Visual Studio 8 2005.rst b/Help/generator/Visual Studio 8 2005.rst index d7b6de25f..29012c371 100644 --- a/Help/generator/Visual Studio 8 2005.rst +++ b/Help/generator/Visual Studio 8 2005.rst @@ -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 `` + Specify target platform matching a Windows CE SDK name. diff --git a/Help/generator/Visual Studio 9 2008.rst b/Help/generator/Visual Studio 9 2008.rst index ade9fd5de..40471b92e 100644 --- a/Help/generator/Visual Studio 9 2008.rst +++ b/Help/generator/Visual Studio 9 2008.rst @@ -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 `` + Specify target platform matching a Windows CE SDK name. diff --git a/Help/release/dev/vs-generator-platform.rst b/Help/release/dev/vs-generator-platform.rst new file mode 100644 index 000000000..df90e1946 --- /dev/null +++ b/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. diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index e753c3c26..e2d4645fa 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -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; } //---------------------------------------------------------------------------- diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 1155508f4..f1ff9a462 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -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( diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index cb82e54f8..401e4758d 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -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) diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index dc8b9157e..04a74dbd5 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -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; diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index c91730f21..745515bcf 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/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 void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream& fout) diff --git a/Source/cmGlobalVisualStudio8Generator.h b/Source/cmGlobalVisualStudio8Generator.h index cb6d3d9f1..4b41ed7d6 100644 --- a/Source/cmGlobalVisualStudio8Generator.h +++ b/Source/cmGlobalVisualStudio8Generator.h @@ -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. diff --git a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake index 60217bcaf..442eb9f9a 100644 --- a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake @@ -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() diff --git a/Tests/RunCMake/GeneratorPlatform/x64Platform-stdout.txt b/Tests/RunCMake/GeneratorPlatform/x64Platform-stdout.txt new file mode 100644 index 000000000..05a83ff7c --- /dev/null +++ b/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. diff --git a/Tests/RunCMake/GeneratorPlatform/x64Platform.cmake b/Tests/RunCMake/GeneratorPlatform/x64Platform.cmake new file mode 100644 index 000000000..a23bdc74b --- /dev/null +++ b/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()