diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index fa174bc2f..4de20c900 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -353,6 +353,8 @@ if (WIN32) cmLocalVisualStudio7Generator.h cmLocalVisualStudioGenerator.cxx cmLocalVisualStudioGenerator.h + cmVisualStudioWCEPlatformParser.h + cmVisualStudioWCEPlatformParser.cxx cmWin32ProcessExecution.cxx cmWin32ProcessExecution.h ) diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index be1bedc76..39b31a0c7 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -13,32 +13,57 @@ #include "cmGlobalVisualStudio8Generator.h" #include "cmLocalVisualStudio7Generator.h" #include "cmMakefile.h" +#include "cmVisualStudioWCEPlatformParser.h" #include "cmake.h" #include "cmGeneratedFileStream.h" -static const char vs8Win32generatorName[] = "Visual Studio 8 2005"; -static const char vs8Win64generatorName[] = "Visual Studio 8 2005 Win64"; +static const char vs8generatorName[] = "Visual Studio 8 2005"; class cmGlobalVisualStudio8Generator::Factory : public cmGlobalGeneratorFactory { public: virtual cmGlobalGenerator* CreateGlobalGenerator(const char* name) const { - if(!strcmp(name, vs8Win32generatorName)) + if(strstr(name, vs8generatorName) != name) + { + return 0; + } + + const char* p = name + sizeof(vs8generatorName) - 1; + if(p[0] == '\0') { return new cmGlobalVisualStudio8Generator( - vs8Win32generatorName, NULL, NULL); + name, NULL, NULL); } - if(!strcmp(name, vs8Win64generatorName)) + + if(p[0] != ' ') + { + return 0; + } + + ++p; + + if(!strcmp(p, "Win64")) { return new cmGlobalVisualStudio8Generator( - vs8Win64generatorName, "x64", "CMAKE_FORCE_WIN64"); + name, "x64", "CMAKE_FORCE_WIN64"); } - return 0; + + cmVisualStudioWCEPlatformParser parser(p); + parser.ParseVersion("8.0"); + if (!parser.Found()) + { + return 0; + } + + cmGlobalVisualStudio8Generator* ret = new cmGlobalVisualStudio8Generator( + name, parser.GetArchitectureFamily(), NULL); + ret->WindowsCEVersion = parser.GetOSVersion(); + return ret; } virtual void GetDocumentation(cmDocumentationEntry& entry) const { - entry.Name = "Visual Studio 8 2005"; + entry.Name = vs8generatorName; entry.Brief = "Generates Visual Studio 8 2005 project files."; entry.Full = "It is possible to append a space followed by the platform name " @@ -48,8 +73,18 @@ public: } virtual void GetGenerators(std::vector& names) const { - names.push_back(vs8Win32generatorName); - names.push_back(vs8Win64generatorName); } + names.push_back(vs8generatorName); + names.push_back(vs8generatorName + std::string(" Win64")); + cmVisualStudioWCEPlatformParser parser; + parser.ParseVersion("8.0"); + const std::vector& availablePlatforms = + parser.GetAvailablePlatforms(); + for(std::vector::const_iterator i = + availablePlatforms.begin(); i != availablePlatforms.end(); ++i) + { + names.push_back("Visual Studio 8 2005 " + *i); + } + } }; //---------------------------------------------------------------------------- diff --git a/Source/cmGlobalVisualStudio8Generator.h b/Source/cmGlobalVisualStudio8Generator.h index 8163d6a3e..08674cda3 100644 --- a/Source/cmGlobalVisualStudio8Generator.h +++ b/Source/cmGlobalVisualStudio8Generator.h @@ -64,6 +64,10 @@ public: LinkLibraryDependencies and link to .sln dependencies. */ virtual bool NeedLinkLibraryDependencies(cmTarget& target); + /** Return true if building for Windows CE */ + virtual bool TargetsWindowsCE() const { + return !this->WindowsCEVersion.empty(); } + protected: virtual const char* GetIDEVersion() { return "8.0"; } @@ -83,8 +87,10 @@ protected: const char* path, cmTarget &t); std::string Name; + std::string WindowsCEVersion; private: class Factory; + friend class Factory; }; #endif diff --git a/Source/cmGlobalVisualStudio9Generator.cxx b/Source/cmGlobalVisualStudio9Generator.cxx index 87599efd3..dbe093e4a 100644 --- a/Source/cmGlobalVisualStudio9Generator.cxx +++ b/Source/cmGlobalVisualStudio9Generator.cxx @@ -13,37 +13,62 @@ #include "cmGlobalVisualStudio9Generator.h" #include "cmLocalVisualStudio7Generator.h" #include "cmMakefile.h" +#include "cmVisualStudioWCEPlatformParser.h" #include "cmake.h" -static const char vs9Win32generatorName[] = "Visual Studio 9 2008"; -static const char vs9Win64generatorName[] = "Visual Studio 8 2005 Win64"; -static const char vs9IA64generatorName[] = "Visual Studio 9 2008 IA64"; +static const char vs9generatorName[] = "Visual Studio 9 2008"; class cmGlobalVisualStudio9Generator::Factory : public cmGlobalGeneratorFactory { public: virtual cmGlobalGenerator* CreateGlobalGenerator(const char* name) const { - if(!strcmp(name, vs9Win32generatorName)) + if(strstr(name, vs9generatorName) != name) + { + return 0; + } + + const char* p = name + sizeof(vs9generatorName) - 1; + if(p[0] == '\0') { return new cmGlobalVisualStudio9Generator( - vs9Win32generatorName, NULL, NULL); + name, NULL, NULL); } - if(!strcmp(name, vs9Win64generatorName)) + + if(p[0] != ' ') + { + return 0; + } + + ++p; + + if(!strcmp(p, "IA64")) { return new cmGlobalVisualStudio9Generator( - vs9Win64generatorName, "x64", "CMAKE_FORCE_WIN64"); + name, "Itanium", "CMAKE_FORCE_IA64"); } - if(!strcmp(name, vs9IA64generatorName)) + + if(!strcmp(p, "Win64")) { return new cmGlobalVisualStudio9Generator( - vs9IA64generatorName, "Itanium", "CMAKE_FORCE_IA64"); + name, "x64", "CMAKE_FORCE_WIN64"); } - return 0; + + cmVisualStudioWCEPlatformParser parser(p); + parser.ParseVersion("9.0"); + if (!parser.Found()) + { + return 0; + } + + cmGlobalVisualStudio9Generator* ret = new cmGlobalVisualStudio9Generator( + name, parser.GetArchitectureFamily(), NULL); + ret->WindowsCEVersion = parser.GetOSVersion(); + return ret; } virtual void GetDocumentation(cmDocumentationEntry& entry) const { - entry.Name = "Visual Studio 9 2008"; + entry.Name = vs9generatorName; entry.Brief = "Generates Visual Studio 9 2008 project files."; entry.Full = "It is possible to append a space followed by the platform name " @@ -53,9 +78,19 @@ public: } virtual void GetGenerators(std::vector& names) const { - names.push_back(vs9Win32generatorName); - names.push_back(vs9Win64generatorName); - names.push_back(vs9IA64generatorName); } + names.push_back(vs9generatorName); + names.push_back(vs9generatorName + std::string(" Win64")); + names.push_back(vs9generatorName + std::string(" IA64")); + cmVisualStudioWCEPlatformParser parser; + parser.ParseVersion("9.0"); + const std::vector& availablePlatforms = + parser.GetAvailablePlatforms(); + for(std::vector::const_iterator i = + availablePlatforms.begin(); i != availablePlatforms.end(); ++i) + { + names.push_back("Visual Studio 9 2008 " + *i); + } + } }; //---------------------------------------------------------------------------- diff --git a/Source/cmGlobalVisualStudio9Generator.h b/Source/cmGlobalVisualStudio9Generator.h index f05d3773d..1310a93ac 100644 --- a/Source/cmGlobalVisualStudio9Generator.h +++ b/Source/cmGlobalVisualStudio9Generator.h @@ -55,5 +55,6 @@ protected: virtual const char* GetIDEVersion() { return "9.0"; } private: class Factory; + friend class Factory; }; #endif diff --git a/Source/cmVisualStudioWCEPlatformParser.cxx b/Source/cmVisualStudioWCEPlatformParser.cxx new file mode 100644 index 000000000..0afcf678e --- /dev/null +++ b/Source/cmVisualStudioWCEPlatformParser.cxx @@ -0,0 +1,139 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2012 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmVisualStudioWCEPlatformParser.h" +#include "cmGlobalVisualStudioGenerator.h" +#include "cmXMLParser.h" + +int cmVisualStudioWCEPlatformParser::ParseVersion(const char* version) +{ + std::string vskey = cmGlobalVisualStudioGenerator::GetRegistryBase(version); + vskey += "\\Setup\\VS;ProductDir"; + + std::string vsInstallPath; + if(!cmSystemTools::ReadRegistryValue(vskey.c_str(), vsInstallPath)) + { + return 0; + } + cmSystemTools::ConvertToUnixSlashes(vsInstallPath); + + const std::string configFilename = + vsInstallPath + "/VC/vcpackages/WCE.VCPlatform.config"; + + return this->ParseFile(configFilename.c_str()); +} + +std::string cmVisualStudioWCEPlatformParser::GetOSVersion() const +{ + if (this->OSMinorVersion.empty()) + { + return OSMajorVersion; + } + + return OSMajorVersion + "." + OSMinorVersion; +} + +const char* cmVisualStudioWCEPlatformParser::GetArchitectureFamily() const +{ + std::map::const_iterator it = + this->Macros.find("ARCHFAM"); + if (it != this->Macros.end()) + { + return it->second.c_str(); + } + + return 0; +} + +void cmVisualStudioWCEPlatformParser::StartElement(const char* name, + const char** attributes) +{ + if(this->FoundRequiredName) + { + return; + } + + this->CharacterData = ""; + + if(strcmp(name, "PlatformData") == 0) + { + this->PlatformName = ""; + this->OSMajorVersion = ""; + this->OSMinorVersion = ""; + this->Macros.clear(); + } + + if(strcmp(name, "Macro") == 0) + { + std::string macroName; + std::string macroValue; + + for(const char** attr = attributes; *attr; attr += 2) + { + if(strcmp(attr[0], "Name") == 0) + { + macroName = attr[1]; + } + else if(strcmp(attr[0], "Value") == 0) + { + macroValue = attr[1]; + } + } + + if(!macroName.empty()) + { + this->Macros[macroName] = macroValue; + } + } +} + +void cmVisualStudioWCEPlatformParser::EndElement(const char* name) +{ + if(!this->RequiredName) + { + if(strcmp(name, "PlatformName") == 0) + { + this->AvailablePlatforms.push_back(this->CharacterData); + } + return; + } + + if(this->FoundRequiredName) + { + return; + } + + if(strcmp(name, "PlatformName") == 0) + { + this->PlatformName = this->CharacterData; + } + else if(strcmp(name, "OSMajorVersion") == 0) + { + this->OSMajorVersion = this->CharacterData; + } + else if(strcmp(name, "OSMinorVersion") == 0) + { + this->OSMinorVersion = this->CharacterData; + } + else if(strcmp(name, "Platform") == 0) + { + if(this->PlatformName == this->RequiredName) + { + this->FoundRequiredName = true; + } + } +} + +void cmVisualStudioWCEPlatformParser::CharacterDataHandler(const char* data, + int length) +{ + this->CharacterData.append(data, length); +} diff --git a/Source/cmVisualStudioWCEPlatformParser.h b/Source/cmVisualStudioWCEPlatformParser.h new file mode 100644 index 000000000..28061fd23 --- /dev/null +++ b/Source/cmVisualStudioWCEPlatformParser.h @@ -0,0 +1,55 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2012 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmVisualStudioWCEPlatformParser_h +#define cmVisualStudioWCEPlatformParser_h +#include "cmStandardIncludes.h" + +#include "cmXMLParser.h" + +// This class is used to parse XML with configuration +// of installed SDKs in system +class cmVisualStudioWCEPlatformParser : public cmXMLParser +{ +public: + cmVisualStudioWCEPlatformParser(const char* name = NULL) + : RequiredName(name) + , FoundRequiredName(false) + { + } + + int ParseVersion(const char* version); + + bool Found() const {return this->FoundRequiredName;} + const char* GetArchitectureFamily() const; + std::string GetOSVersion() const; + const std::vector& GetAvailablePlatforms() const { + return this->AvailablePlatforms; } + +protected: + virtual void StartElement(const char* name, const char** attributes); + void EndElement(const char* name); + void CharacterDataHandler(const char* data, int length); + +private: + std::string CharacterData; + + std::string PlatformName; + std::string OSMajorVersion; + std::string OSMinorVersion; + std::map Macros; + std::vector AvailablePlatforms; + + const char* RequiredName; + bool FoundRequiredName; +}; + +#endif