/*========================================================================= Program: CMake - Cross-Platform Makefile Generator Module: $RCSfile: cmGlobalVisualStudio8_WindowsMobile_Generator.cxx,v $ Language: C++ Date: $Date: 2008-04-02 13:16:04 $ Version: $Revision: 1.36.2.1 $ Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "windows.h" // this must be first to define GetCurrentDirectory #include "cmGlobalVisualStudio8_WindowsMobile_Generator.h" #include "cmLocalVisualStudio7Generator.h" #include "cmMakefile.h" #include "cmake.h" #include "cmGeneratedFileStream.h" cmWindowsMobileConfigParser::cmWindowsMobileConfigParser() : cmXMLParser() { current_platform_valid = false; } void cmWindowsMobileConfigParser::StartElement(const char* name, const char** atts) { if ( strcmp(name, "Macro") == 0 ) { const char* rev = this->FindAttribute(atts, "Name"); if (rev) { if ( strcmp(rev, "PLATFORMDEFINES") == 0 && current_platform_valid) { rev = this->FindAttribute(atts, "Value"); PlatformDefs * defs = &(this->platformVec.back()); defs->PlatformDefines = std::string(rev); } else if ( strcmp(rev, "CEVER") == 0 && current_platform_valid) { rev = this->FindAttribute(atts, "Value"); PlatformDefs * defs = &(this->platformVec.back()); defs->CEver = std::string(rev); } else if ( strcmp(rev, "ARCHFAM") == 0 && current_platform_valid) { rev = this->FindAttribute(atts, "Value"); PlatformDefs * defs = &(this->platformVec.back()); defs->Archfam = std::string(rev); } else if ( strcmp(rev, "_ARCHFAM_") == 0 && current_platform_valid) { rev = this->FindAttribute(atts, "Value"); PlatformDefs * defs = &(this->platformVec.back()); defs->Archfam_ = std::string(rev); } else if ( strcmp(rev, "INSTRUCTIONSET") == 0 && current_platform_valid) { rev = this->FindAttribute(atts, "Value"); PlatformDefs * defs = &(this->platformVec.back()); defs->InstructionSet= std::string(rev); } } } this->CharacterData.erase( this->CharacterData.begin(), this->CharacterData.end()); } void cmWindowsMobileConfigParser::EndElement(const char* name) { if ( strcmp(name, "PlatformName") == 0 ) { PlatformDefs defs; defs.added = false; defs.PlatformName = std::string(this->CharacterData.begin(),this->CharacterData.end()); // if(defs.PlatformName.find("ARMV4") != std::string::npos) { this->platformVec.push_back(defs); current_platform_valid = true; // } else // current_platform_valid = false; } else if ( strcmp(name, "OSMinorVersion") == 0 && current_platform_valid) { PlatformDefs * defs = &(this->platformVec.back()); defs->MinorVer = atoi(std::string(this->CharacterData.begin(),this->CharacterData.end()).c_str()); } else if ( strcmp(name, "OSMajorVersion") == 0 && current_platform_valid) { PlatformDefs * defs = &(this->platformVec.back()); defs->MajorVer = atoi(std::string(this->CharacterData.begin(),this->CharacterData.end()).c_str()); } this->CharacterData.erase(this->CharacterData.begin(), this->CharacterData.end()); } void cmWindowsMobileConfigParser::CharacterDataHandler(const char* data, int length) { this->CharacterData.insert(this->CharacterData.end(), data, data+length); } const char* cmWindowsMobileConfigParser::FindAttribute( const char** atts, const char* attribute ) { if ( !atts || !attribute ) { return 0; } const char **atr = atts; while ( *atr && **atr && **(atr+1) ) { if ( strcmp(*atr, attribute) == 0 ) { return *(atr+1); } atr+=2; } return 0; } //---------------------------------------------------------------------------- cmGlobalVisualStudio8_WindowsMobile_Generator::cmGlobalVisualStudio8_WindowsMobile_Generator() { this->FindMakeProgramFile = "CMakeVS8FindMake.cmake"; this->ProjectConfigurationSectionName = "ProjectConfigurationPlatforms"; this->PlatformName = "Undefined Mobile Platform"; } //---------------------------------------------------------------------------- ///! Create a local generator appropriate to this Global Generator cmLocalGenerator *cmGlobalVisualStudio8_WindowsMobile_Generator::CreateLocalGenerator() { cmLocalVisualStudio7Generator *lg = new cmLocalVisualStudio7Generator; lg->SetPlatformName(this->PlatformName.c_str()); lg->SetVersion8(); lg->SetExtraFlagTable(this->GetExtraFlagTableVS8()); lg->SetGlobalGenerator(this); return lg; } //---------------------------------------------------------------------------- // ouput standard header for dsw file void cmGlobalVisualStudio8_WindowsMobile_Generator::WriteSLNHeader(std::ostream& fout) { fout << "Microsoft Visual Studio Solution File, Format Version 9.00\n"; fout << "# Visual Studio 2005\n"; } //---------------------------------------------------------------------------- void cmGlobalVisualStudio8_WindowsMobile_Generator ::GetDocumentation(cmDocumentationEntry& entry) const { entry.Name = this->GetName(); entry.Brief = "Generates Visual Studio .NET 2005 WM5 project files."; entry.Full = ""; } //---------------------------------------------------------------------------- void cmGlobalVisualStudio8_WindowsMobile_Generator::AddPlatformDefinitions(cmMakefile* mf) { mf->AddDefinition("MSVC80", "1"); } //---------------------------------------------------------------------------- void cmGlobalVisualStudio8_WindowsMobile_Generator::Configure() { std::string regkey("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\VisualStudio\\"); regkey += "9.0"; // THIS MUST BE ADDED ACCORDING TO THE VS VERSION!!! regkey += std::string("\\Setup\\VS;"); std::string base; if (!cmSystemTools::ReadRegistryValue((regkey+ std::string("ProductDir")).c_str(), base)) { return; } cmSystemTools::ConvertToUnixSlashes(base); // NOW READ THE CONFIG FILE FOR THE SDKs std::string configFilename = base + std::string("/VC/vcpackages/WCE.VCPlatform.config"); cmWindowsMobileConfigParser *parser = new cmWindowsMobileConfigParser(); if(parser->ParseFile(configFilename.c_str()) == 0) { return; } std::vector sdksfound = parser->getPlatforms(); //platforms = parser->getPlatforms(); delete parser; // HERE WE FILTER THE PLATFORMS GIVEN AN ALREADY EXISTING CACHE ENTRY! cmake * c = this->GetCMakeInstance(); const char* ptr = c->GetCacheDefinition("PLATFORM_SDKS"); if(ptr) { char buf[200]; sprintf(buf,"%s",ptr); std::string platforms2use(buf); // "Windows Mobile 5.0 Pocket PC SDK (ARMV4I);Windows Mobile 5.0 Smartphone SDK (ARMV4I)"); if(platforms2use.size() != 0) { // now filter based on the list of sdks found bool breakloop = false; while(!breakloop) { int div = platforms2use.find_first_of(";"); std::string tpn; if(div < 0) { breakloop = true; tpn = platforms2use; } else if(div == platforms2use.size()-1) { breakloop = true; tpn = platforms2use.substr(0,div); } else { tpn = platforms2use.substr(0,div); platforms2use = platforms2use.substr(div+1,platforms2use.size() - div); } for(std::vector::iterator it = sdksfound.begin(); it != sdksfound.end(); it++) { if(tpn.compare(it->PlatformName) == 0 && !it->added) { PlatformDefs thissdk = *it; platforms.push_back(thissdk); it->added = true; } } } } } // simply add all sdks found if no useful SDKs were found if(platforms.size() == 0) platforms = sdksfound; // HERE WE CIRCUMVENT THE NEED FOR A TOOLCHAIN FILE - WE SHOULD CHANGE THIS TO USE A TOOLCHAIN FILE c->AddCacheEntry("CMAKE_SYSTEM_NAME", "WinCE", "Windows CE Define", 6); // 0 = bool, 3 = string c->AddCacheEntry("CMAKE_SYSTEM_VERSION", "5.1", "Mobile Platform Version Define", 6); // #5.1 = WM5, 5.2 = WM6 c->AddCacheEntry("CMAKE_SYSTEM_PROCESSOR", "ARMV4I", "Processor Define", 6); c->AddCacheEntry("ARM", "1", "System Define", 6); c->AddCacheEntry("CMAKE_C_COMPILER_ID", "MSVC", "Compiler ID Define", 6); c->AddCacheEntry("CMAKE_CXX_COMPILER_ID", "MSVC", "Compiler ID Define", 6); c->AddCacheEntry("CMAKE_CROSSCOMPILING","TRUE","Crosscompiling Flag",0); c->AddCacheEntry("CMAKE_WINCE_STACKSIZE","65536,4096", "Stack Size Definition", 6); c->AddCacheEntry("WINCE_HOST_CMAKE_PATH", (base + std::string("/VC/ce")).c_str(),"Path to Visual Studio CE Path",1); //c->AddCacheEntry("WINCE_SDK_CMAKE_PATH", "C:/Programme/Windows Mobile 5.0 SDK R2/PocketPC","Path to WinCE SDK",1); //c->AddCacheEntry("WINVS_SDK_CMAKE_PATH", "C:/Programme/Microsoft SDKs/Windows/v6.0A/bin","Path to VS SDK",1); char buf[200]; sprintf(buf,"%s/bin/x86_arm/cl.exe",c->GetCacheDefinition("WINCE_HOST_CMAKE_PATH")); c->AddCacheEntry("CMAKE_CXX_COMPILER", buf, "ARM cxx-Compiler",2); sprintf(buf,"%s/bin/x86_arm/cl.exe",c->GetCacheDefinition("WINCE_HOST_CMAKE_PATH")); c->AddCacheEntry("CMAKE_C_COMPILER", buf, "ARM c-Compiler",2); sprintf(buf,"%s/bin/x86_arm/link.exe",c->GetCacheDefinition("WINCE_HOST_CMAKE_PATH")); c->AddCacheEntry("CMAKE_CXX_LINKER", buf, "ARM cxx-Linker",2); sprintf(buf,"%s/bin/x86_arm/link.exe",c->GetCacheDefinition("WINCE_HOST_CMAKE_PATH")); c->AddCacheEntry("CMAKE_C_LINKER", buf, "ARM c-Linker",2); sprintf(buf,"%s/bin/x86_arm/link.exe",c->GetCacheDefinition("WINCE_HOST_CMAKE_PATH")); c->AddCacheEntry("CMAKE_LINKER", buf, "ARM Linker",2); sprintf(buf,"%s/bin/x86_arm/armasm.exe",c->GetCacheDefinition("WINCE_HOST_CMAKE_PATH")); c->AddCacheEntry("CMAKE_ASM_COMPILER", buf , "ARM Assembler",2); //sprintf(buf,"%s/rc.exe",c->GetCacheDefinition("WINVS_SDK_CMAKE_PATH")); //c->AddCacheEntry("CMAKE_RC_COMPILER", buf, "Resource Compiler",2); this->cmGlobalVisualStudio7Generator::Configure(); this->CreateGUID(CMAKE_CHECK_BUILD_SYSTEM_TARGET); } //---------------------------------------------------------------------------- std::string cmGlobalVisualStudio8_WindowsMobile_Generator::GetUserMacrosDirectory() { // Some VS8 sp0 versions cannot run macros. // See http://support.microsoft.com/kb/928209 const char* vc8sp1Registry = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\" "InstalledProducts\\KB926601;"; const char* vc8exSP1Registry = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\" "InstalledProducts\\KB926748;"; std::string vc8sp1; if (!cmSystemTools::ReadRegistryValue(vc8sp1Registry, vc8sp1) && !cmSystemTools::ReadRegistryValue(vc8exSP1Registry, vc8sp1)) { return ""; } std::string base; std::string path; // base begins with the VisualStudioProjectsLocation reg value... if (cmSystemTools::ReadRegistryValue( "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\8.0;" "VisualStudioProjectsLocation", base)) { cmSystemTools::ConvertToUnixSlashes(base); // 8.0 macros folder: path = base + "/VSMacros80"; } // path is (correctly) still empty if we did not read the base value from // the Registry value return path; } //---------------------------------------------------------------------------- std::string cmGlobalVisualStudio8_WindowsMobile_Generator::GetUserMacrosRegKeyBase() { return "Software\\Microsoft\\VisualStudio\\8.0\\vsmacros"; } //---------------------------------------------------------------------------- void cmGlobalVisualStudio8_WindowsMobile_Generator::Generate() { // Add a special target on which all other targets depend that // checks the build system and optionally re-runs CMake. const char* no_working_directory = 0; std::vector no_depends; std::map >::iterator it; for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it) { std::vector& generators = it->second; if(!generators.empty()) { // Add the build-system check target to the first local // generator of this project. cmLocalVisualStudio7Generator* lg = static_cast(generators[0]); cmMakefile* mf = lg->GetMakefile(); // Skip the target if no regeneration is to be done. if(mf->IsOn("CMAKE_SUPPRESS_REGENERATION")) { continue; } std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND"); cmCustomCommandLines noCommandLines; mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false, no_working_directory, no_depends, noCommandLines); cmTarget* tgt = mf->FindTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET); if(!tgt) { cmSystemTools::Error("Error adding target " CMAKE_CHECK_BUILD_SYSTEM_TARGET); continue; } // Create a list of all stamp files for this project. std::vector stamps; std::string stampList = cmake::GetCMakeFilesDirectoryPostSlash(); stampList += "generate.stamp.list"; { std::string stampListFile = generators[0]->GetMakefile()->GetCurrentOutputDirectory(); stampListFile += "/"; stampListFile += stampList; std::string stampFile; cmGeneratedFileStream fout(stampListFile.c_str()); for(std::vector::const_iterator gi = generators.begin(); gi != generators.end(); ++gi) { stampFile = (*gi)->GetMakefile()->GetCurrentOutputDirectory(); stampFile += "/"; stampFile += cmake::GetCMakeFilesDirectoryPostSlash(); stampFile += "generate.stamp"; stampFile = generators[0]->Convert(stampFile.c_str(), cmLocalGenerator::START_OUTPUT); fout << stampFile << "\n"; stamps.push_back(stampFile); } } // Add a custom rule to re-run CMake if any input files changed. { // Collect the input files used to generate all targets in this // project. std::vector listFiles; for(unsigned int j = 0; j < generators.size(); ++j) { cmMakefile* lmf = generators[j]->GetMakefile(); listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(), lmf->GetListFiles().end()); } // Sort the list of input files and remove duplicates. std::sort(listFiles.begin(), listFiles.end(), std::less()); std::vector::iterator new_end = std::unique(listFiles.begin(), listFiles.end()); listFiles.erase(new_end, listFiles.end()); // Create a rule to re-run CMake. std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash(); stampName += "generate.stamp"; const char* dsprule = mf->GetRequiredDefinition("CMAKE_COMMAND"); cmCustomCommandLine commandLine; commandLine.push_back(dsprule); std::string argH = "-H"; argH += lg->Convert(mf->GetHomeDirectory(), cmLocalGenerator::START_OUTPUT, cmLocalGenerator::UNCHANGED, true); commandLine.push_back(argH); std::string argB = "-B"; argB += lg->Convert(mf->GetHomeOutputDirectory(), cmLocalGenerator::START_OUTPUT, cmLocalGenerator::UNCHANGED, true); commandLine.push_back(argB); commandLine.push_back("--check-stamp-list"); commandLine.push_back(stampList.c_str()); commandLine.push_back("--vs-solution-file"); commandLine.push_back("\"$(SolutionPath)\""); cmCustomCommandLines commandLines; commandLines.push_back(commandLine); // Add the rule. Note that we cannot use the CMakeLists.txt // file as the main dependency because it would get // overwritten by the CreateVCProjBuildRule. // (this could be avoided with per-target source files) const char* no_main_dependency = 0; const char* no_working_directory = 0; mf->AddCustomCommandToOutput( stamps, listFiles, no_main_dependency, commandLines, "Checking Build System", no_working_directory, true); std::string ruleName = stamps[0]; ruleName += ".rule"; if(cmSourceFile* file = mf->GetSource(ruleName.c_str())) { tgt->AddSourceFile(file); } else { cmSystemTools::Error("Error adding rule for ", stamps[0].c_str()); } } } } // Now perform the main generation. this->cmGlobalVisualStudio7Generator::Generate(); } //---------------------------------------------------------------------------- void cmGlobalVisualStudio8_WindowsMobile_Generator::WriteSLNFile( std::ostream& fout, cmLocalGenerator* root, std::vector& generators) { // Make all targets depend on their respective project's build // system check target. unsigned int i; for(i = 0; i < generators.size(); ++i) { if(this->IsExcluded(root, generators[i])) { continue; } cmMakefile* mf = generators[i]->GetMakefile(); cmTargets& tgts = mf->GetTargets(); for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l) { if(l->first == CMAKE_CHECK_BUILD_SYSTEM_TARGET) { for(unsigned int j = 0; j < generators.size(); ++j) { // Every target in all generators should depend on this target. cmMakefile* lmf = generators[j]->GetMakefile(); cmTargets &atgts = lmf->GetTargets(); for(cmTargets::iterator al = atgts.begin(); al != atgts.end(); ++al) { al->second.AddUtility(l->first.c_str()); } } } } } // Now write the solution file. this->cmGlobalVisualStudio71Generator::WriteSLNFile(fout, root, generators); } //---------------------------------------------------------------------------- void cmGlobalVisualStudio8_WindowsMobile_Generator ::WriteSolutionConfigurations(std::ostream& fout) { fout << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n"; for(std::vector::iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { for(std::vector::iterator j = this->platforms.begin(); j != this->platforms.end(); ++j) fout << "\t\t" << *i << "|" << j->PlatformName << " = " << *i << "|" << j->PlatformName << "\n"; //fout << "\t\t" << *i << "|" << this->PlatformName << " = " << *i << "|" // << this->PlatformName << "\n"; } fout << "\tEndGlobalSection\n"; } //---------------------------------------------------------------------------- void cmGlobalVisualStudio8_WindowsMobile_Generator ::WriteProjectConfigurations(std::ostream& fout, const char* name, bool partOfDefaultBuild) { std::string guid = this->GetGUID(name); for(std::vector::iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { for(std::vector::iterator j = this->platforms.begin(); j != this->platforms.end(); ++j) { fout << "\t\t{" << guid << "}." << *i << "|" << j->PlatformName << ".ActiveCfg = " << *i << "|" << j->PlatformName << "\n"; if(partOfDefaultBuild) { fout << "\t\t{" << guid << "}." << *i << "|" << j->PlatformName << ".Build.0 = " << *i << "|" << j->PlatformName << "\n"; } } } } //---------------------------------------------------------------------------- static cmVS7FlagTable cmVS8ExtraFlagTable[] = { {"CallingConvention", "Gd", "cdecl", "0", 0 }, {"CallingConvention", "Gr", "fastcall", "1", 0 }, {"CallingConvention", "Gz", "stdcall", "2", 0 }, {"Detect64BitPortabilityProblems", "Wp64", "Detect 64Bit Portability Problems", "true", 0 }, {"ErrorReporting", "errorReport:prompt", "Report immediately", "1", 0 }, {"ErrorReporting", "errorReport:queue", "Queue for next login", "2", 0 }, // Precompiled header and related options. Note that the // UsePrecompiledHeader entries are marked as "Continue" so that the // corresponding PrecompiledHeaderThrough entry can be found. {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "2", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue}, {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "", cmVS7FlagTable::UserValueRequired}, // There is no YX option in the VS8 IDE. // Exception handling mode. If no entries match, it will be FALSE. {"ExceptionHandling", "GX", "enable c++ exceptions", "1", 0}, {"ExceptionHandling", "EHsc", "enable c++ exceptions", "1", 0}, {"ExceptionHandling", "EHa", "enable SEH exceptions", "2", 0}, {0,0,0,0,0} }; cmVS7FlagTable const* cmGlobalVisualStudio8_WindowsMobile_Generator::GetExtraFlagTableVS8() { return cmVS8ExtraFlagTable; }