cmGlobalVisualStudio7Generator.cxx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "windows.h" // this must be first to define GetCurrentDirectory
  11. #include "cmGlobalVisualStudio7Generator.h"
  12. #include "cmGeneratedFileStream.h"
  13. #include "cmLocalVisualStudio7Generator.h"
  14. #include "cmMakefile.h"
  15. #include "cmake.h"
  16. cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator()
  17. {
  18. this->FindMakeProgramFile = "CMakeVS7FindMake.cmake";
  19. }
  20. void cmGlobalVisualStudio7Generator
  21. ::EnableLanguage(std::vector<std::string>const & lang,
  22. cmMakefile *mf, bool optional)
  23. {
  24. mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
  25. mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
  26. mf->AddDefinition("CMAKE_GENERATOR_RC", "rc");
  27. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  28. mf->AddDefinition("CMAKE_GENERATOR_FC", "ifort");
  29. this->AddPlatformDefinitions(mf);
  30. // Create list of configurations requested by user's cache, if any.
  31. this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
  32. this->GenerateConfigurations(mf);
  33. // if this environment variable is set, then copy it to
  34. // a static cache entry. It will be used by
  35. // cmLocalGenerator::ConstructScript, to add an extra PATH
  36. // to all custom commands. This is because the VS IDE
  37. // does not use the environment it is run in, and this allows
  38. // for running commands and using dll's that the IDE environment
  39. // does not know about.
  40. const char* extraPath = cmSystemTools::GetEnv("CMAKE_MSVCIDE_RUN_PATH");
  41. if(extraPath)
  42. {
  43. mf->AddCacheDefinition
  44. ("CMAKE_MSVCIDE_RUN_PATH", extraPath,
  45. "Saved environment variable CMAKE_MSVCIDE_RUN_PATH",
  46. cmCacheManager::STATIC);
  47. }
  48. }
  49. std::string cmGlobalVisualStudio7Generator
  50. ::GenerateBuildCommand(const char* makeProgram,
  51. const char *projectName,
  52. const char* additionalOptions, const char *targetName,
  53. const char* config, bool ignoreErrors, bool)
  54. {
  55. // Ingoring errors is not implemented in visual studio 6
  56. (void) ignoreErrors;
  57. // now build the test
  58. std::string makeCommand =
  59. cmSystemTools::ConvertToOutputPath(makeProgram);
  60. std::string lowerCaseCommand = makeCommand;
  61. cmSystemTools::LowerCase(lowerCaseCommand);
  62. // if there are spaces in the makeCommand, assume a full path
  63. // and convert it to a path with no spaces in it as the
  64. // RunSingleCommand does not like spaces
  65. #if defined(_WIN32) && !defined(__CYGWIN__)
  66. if(makeCommand.find(' ') != std::string::npos)
  67. {
  68. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  69. }
  70. #endif
  71. makeCommand += " ";
  72. makeCommand += projectName;
  73. makeCommand += ".sln ";
  74. bool clean = false;
  75. if ( targetName && strcmp(targetName, "clean") == 0 )
  76. {
  77. clean = true;
  78. targetName = "ALL_BUILD";
  79. }
  80. if(clean)
  81. {
  82. makeCommand += "/clean ";
  83. }
  84. else
  85. {
  86. makeCommand += "/build ";
  87. }
  88. if(config && strlen(config))
  89. {
  90. makeCommand += config;
  91. }
  92. else
  93. {
  94. makeCommand += "Debug";
  95. }
  96. makeCommand += " /project ";
  97. if (targetName && strlen(targetName))
  98. {
  99. makeCommand += targetName;
  100. }
  101. else
  102. {
  103. makeCommand += "ALL_BUILD";
  104. }
  105. if ( additionalOptions )
  106. {
  107. makeCommand += " ";
  108. makeCommand += additionalOptions;
  109. }
  110. return makeCommand;
  111. }
  112. ///! Create a local generator appropriate to this Global Generator
  113. cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator()
  114. {
  115. cmLocalVisualStudio7Generator *lg =
  116. new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS7);
  117. lg->SetExtraFlagTable(this->GetExtraFlagTableVS7());
  118. lg->SetGlobalGenerator(this);
  119. return lg;
  120. }
  121. void cmGlobalVisualStudio7Generator::GenerateConfigurations(cmMakefile* mf)
  122. {
  123. // process the configurations
  124. const char* ct
  125. = this->CMakeInstance->GetCacheDefinition("CMAKE_CONFIGURATION_TYPES");
  126. if ( ct )
  127. {
  128. std::vector<std::string> argsOut;
  129. cmSystemTools::ExpandListArgument(ct, argsOut);
  130. for(std::vector<std::string>::iterator i = argsOut.begin();
  131. i != argsOut.end(); ++i)
  132. {
  133. if(std::find(this->Configurations.begin(),
  134. this->Configurations.end(),
  135. *i) == this->Configurations.end())
  136. {
  137. this->Configurations.push_back(*i);
  138. }
  139. }
  140. }
  141. // default to at least Debug and Release
  142. if(this->Configurations.size() == 0)
  143. {
  144. this->Configurations.push_back("Debug");
  145. this->Configurations.push_back("Release");
  146. }
  147. // Reset the entry to have a semi-colon separated list.
  148. std::string configs = this->Configurations[0];
  149. for(unsigned int i=1; i < this->Configurations.size(); ++i)
  150. {
  151. configs += ";";
  152. configs += this->Configurations[i];
  153. }
  154. mf->AddCacheDefinition(
  155. "CMAKE_CONFIGURATION_TYPES",
  156. configs.c_str(),
  157. "Semicolon separated list of supported configuration types, "
  158. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  159. "anything else will be ignored.",
  160. cmCacheManager::STRING);
  161. }
  162. void cmGlobalVisualStudio7Generator::Generate()
  163. {
  164. // first do the superclass method
  165. this->cmGlobalVisualStudioGenerator::Generate();
  166. // Now write out the DSW
  167. this->OutputSLNFile();
  168. // If any solution or project files changed during the generation,
  169. // tell Visual Studio to reload them...
  170. if(!cmSystemTools::GetErrorOccuredFlag())
  171. {
  172. this->CallVisualStudioMacro(MacroReload);
  173. }
  174. }
  175. void cmGlobalVisualStudio7Generator
  176. ::OutputSLNFile(cmLocalGenerator* root,
  177. std::vector<cmLocalGenerator*>& generators)
  178. {
  179. if(generators.size() == 0)
  180. {
  181. return;
  182. }
  183. this->CurrentProject = root->GetMakefile()->GetProjectName();
  184. std::string fname = root->GetMakefile()->GetStartOutputDirectory();
  185. fname += "/";
  186. fname += root->GetMakefile()->GetProjectName();
  187. fname += ".sln";
  188. cmGeneratedFileStream fout(fname.c_str());
  189. fout.SetCopyIfDifferent(true);
  190. if(!fout)
  191. {
  192. return;
  193. }
  194. this->WriteSLNFile(fout, root, generators);
  195. if (fout.Close())
  196. {
  197. this->FileReplacedDuringGenerate(fname);
  198. }
  199. }
  200. // output the SLN file
  201. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  202. {
  203. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  204. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  205. {
  206. this->OutputSLNFile(it->second[0], it->second);
  207. }
  208. }
  209. void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
  210. std::ostream& fout,
  211. cmLocalGenerator* root,
  212. OrderedTargetDependSet const& projectTargets)
  213. {
  214. // loop over again and write out configurations for each target
  215. // in the solution
  216. for(OrderedTargetDependSet::const_iterator tt =
  217. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  218. {
  219. cmTarget* target = *tt;
  220. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  221. if(expath)
  222. {
  223. this->WriteProjectConfigurations(
  224. fout, target->GetName(),
  225. true, target->GetProperty("VS_PLATFORM_MAPPING"));
  226. }
  227. else
  228. {
  229. bool partOfDefaultBuild = this->IsPartOfDefaultBuild(
  230. root->GetMakefile()->GetProjectName(), target);
  231. const char *vcprojName =
  232. target->GetProperty("GENERATOR_FILE_NAME");
  233. if (vcprojName)
  234. {
  235. this->WriteProjectConfigurations(fout, vcprojName,
  236. partOfDefaultBuild);
  237. }
  238. }
  239. }
  240. }
  241. void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
  242. std::ostream& fout,
  243. cmLocalGenerator* root,
  244. OrderedTargetDependSet const& projectTargets)
  245. {
  246. VisualStudioFolders.clear();
  247. for(OrderedTargetDependSet::const_iterator tt =
  248. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  249. {
  250. cmTarget* target = *tt;
  251. bool written = false;
  252. // handle external vc project files
  253. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  254. if(expath)
  255. {
  256. std::string project = target->GetName();
  257. std::string location = expath;
  258. this->WriteExternalProject(fout,
  259. project.c_str(),
  260. location.c_str(),
  261. target->GetProperty("VS_PROJECT_TYPE"),
  262. target->GetUtilities());
  263. written = true;
  264. }
  265. else
  266. {
  267. const char *vcprojName =
  268. target->GetProperty("GENERATOR_FILE_NAME");
  269. if(vcprojName)
  270. {
  271. cmMakefile* tmf = target->GetMakefile();
  272. std::string dir = tmf->GetStartOutputDirectory();
  273. dir = root->Convert(dir.c_str(),
  274. cmLocalGenerator::START_OUTPUT);
  275. if(dir == ".")
  276. {
  277. dir = ""; // msbuild cannot handle ".\" prefix
  278. }
  279. this->WriteProject(fout, vcprojName, dir.c_str(),
  280. *target);
  281. written = true;
  282. }
  283. }
  284. // Create "solution folder" information from FOLDER target property
  285. //
  286. if (written && this->UseFolderProperty())
  287. {
  288. const char *targetFolder = target->GetProperty("FOLDER");
  289. if (targetFolder)
  290. {
  291. std::vector<cmsys::String> tokens =
  292. cmSystemTools::SplitString(targetFolder, '/', false);
  293. std::string cumulativePath = "";
  294. for(std::vector<cmsys::String>::iterator iter = tokens.begin();
  295. iter != tokens.end(); ++iter)
  296. {
  297. if(!iter->size())
  298. {
  299. continue;
  300. }
  301. if (cumulativePath.empty())
  302. {
  303. cumulativePath = "CMAKE_FOLDER_GUID_" + *iter;
  304. }
  305. else
  306. {
  307. VisualStudioFolders[cumulativePath].insert(
  308. cumulativePath + "/" + *iter);
  309. cumulativePath = cumulativePath + "/" + *iter;
  310. }
  311. this->CreateGUID(cumulativePath.c_str());
  312. }
  313. if (!cumulativePath.empty())
  314. {
  315. VisualStudioFolders[cumulativePath].insert(target->GetName());
  316. }
  317. }
  318. }
  319. }
  320. }
  321. void cmGlobalVisualStudio7Generator::WriteTargetDepends(
  322. std::ostream& fout,
  323. OrderedTargetDependSet const& projectTargets
  324. )
  325. {
  326. for(OrderedTargetDependSet::const_iterator tt =
  327. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  328. {
  329. cmTarget* target = *tt;
  330. cmMakefile* mf = target->GetMakefile();
  331. const char *vcprojName =
  332. target->GetProperty("GENERATOR_FILE_NAME");
  333. if (vcprojName)
  334. {
  335. std::string dir = mf->GetStartDirectory();
  336. this->WriteProjectDepends(fout, vcprojName,
  337. dir.c_str(), *target);
  338. }
  339. }
  340. }
  341. //----------------------------------------------------------------------------
  342. // Write a SLN file to the stream
  343. void cmGlobalVisualStudio7Generator
  344. ::WriteSLNFile(std::ostream& fout,
  345. cmLocalGenerator* root,
  346. std::vector<cmLocalGenerator*>& generators)
  347. {
  348. // Write out the header for a SLN file
  349. this->WriteSLNHeader(fout);
  350. // Collect all targets under this root generator and the transitive
  351. // closure of their dependencies.
  352. TargetDependSet projectTargets;
  353. TargetDependSet originalTargets;
  354. this->GetTargetSets(projectTargets, originalTargets, root, generators);
  355. OrderedTargetDependSet orderedProjectTargets(projectTargets);
  356. this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
  357. bool useFolderProperty = this->UseFolderProperty();
  358. if (useFolderProperty)
  359. {
  360. this->WriteFolders(fout);
  361. }
  362. // Write out the configurations information for the solution
  363. fout << "Global\n"
  364. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  365. int c = 0;
  366. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  367. i != this->Configurations.end(); ++i)
  368. {
  369. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  370. c++;
  371. }
  372. fout << "\tEndGlobalSection\n";
  373. // Write out project(target) depends
  374. fout << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  375. this->WriteTargetDepends(fout, orderedProjectTargets);
  376. fout << "\tEndGlobalSection\n";
  377. if (useFolderProperty)
  378. {
  379. // Write out project folders
  380. fout << "\tGlobalSection(NestedProjects) = preSolution\n";
  381. this->WriteFoldersContent(fout);
  382. fout << "\tEndGlobalSection\n";
  383. }
  384. // Write out the configurations for all the targets in the project
  385. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  386. this->WriteTargetConfigurations(fout, root, orderedProjectTargets);
  387. fout << "\tEndGlobalSection\n";
  388. // Write out global sections
  389. this->WriteSLNGlobalSections(fout, root);
  390. // Write the footer for the SLN file
  391. this->WriteSLNFooter(fout);
  392. }
  393. //----------------------------------------------------------------------------
  394. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  395. {
  396. const char *prefix = "CMAKE_FOLDER_GUID_";
  397. const std::string::size_type skip_prefix = strlen(prefix);
  398. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  399. for(std::map<std::string,std::set<std::string> >::iterator iter =
  400. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  401. {
  402. std::string fullName = iter->first;
  403. std::string guid = this->GetGUID(fullName.c_str());
  404. cmSystemTools::ReplaceString(fullName, "/", "\\");
  405. if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix))
  406. {
  407. fullName = fullName.substr(skip_prefix);
  408. }
  409. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  410. fout << "Project(\"{" <<
  411. guidProjectTypeFolder << "}\") = \"" <<
  412. nameOnly << "\", \"" <<
  413. fullName << "\", \"{" <<
  414. guid <<
  415. "}\"\nEndProject\n";
  416. }
  417. }
  418. //----------------------------------------------------------------------------
  419. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  420. {
  421. for(std::map<std::string,std::set<std::string> >::iterator iter =
  422. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  423. {
  424. std::string key(iter->first);
  425. std::string guidParent(this->GetGUID(key.c_str()));
  426. for(std::set<std::string>::iterator it = iter->second.begin();
  427. it != iter->second.end(); ++it)
  428. {
  429. std::string value(*it);
  430. std::string guid(this->GetGUID(value.c_str()));
  431. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  432. }
  433. }
  434. }
  435. //----------------------------------------------------------------------------
  436. std::string
  437. cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
  438. {
  439. // Convert to backslashes. Do not use ConvertToOutputPath because
  440. // we will add quoting ourselves, and we know these projects always
  441. // use windows slashes.
  442. std::string d = path;
  443. std::string::size_type pos = 0;
  444. while((pos = d.find('/', pos)) != d.npos)
  445. {
  446. d[pos++] = '\\';
  447. }
  448. return d;
  449. }
  450. // Write a dsp file into the SLN file,
  451. // Note, that dependencies from executables to
  452. // the libraries it uses are also done here
  453. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  454. const char* dspname,
  455. const char* dir, cmTarget& target)
  456. {
  457. // check to see if this is a fortran build
  458. const char* ext = ".vcproj";
  459. const char* project =
  460. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  461. if(this->TargetIsFortranOnly(target))
  462. {
  463. ext = ".vfproj";
  464. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  465. }
  466. fout << project
  467. << dspname << "\", \""
  468. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  469. << dspname << ext << "\", \"{"
  470. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  471. UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
  472. if(ui != this->UtilityDepends.end())
  473. {
  474. const char* uname = ui->second.c_str();
  475. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  476. << uname << "\", \""
  477. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  478. << uname << ".vcproj" << "\", \"{"
  479. << this->GetGUID(uname) << "}\"\n"
  480. << "EndProject\n";
  481. }
  482. }
  483. // Write a dsp file into the SLN file,
  484. // Note, that dependencies from executables to
  485. // the libraries it uses are also done here
  486. void
  487. cmGlobalVisualStudio7Generator
  488. ::WriteProjectDepends(std::ostream& fout,
  489. const char* dspname,
  490. const char*, cmTarget& target)
  491. {
  492. int depcount = 0;
  493. std::string dspguid = this->GetGUID(dspname);
  494. VSDependSet const& depends = this->VSTargetDepends[&target];
  495. for(VSDependSet::const_iterator di = depends.begin();
  496. di != depends.end(); ++di)
  497. {
  498. const char* name = di->c_str();
  499. std::string guid = this->GetGUID(name);
  500. if(guid.size() == 0)
  501. {
  502. std::string m = "Target: ";
  503. m += target.GetName();
  504. m += " depends on unknown target: ";
  505. m += name;
  506. cmSystemTools::Error(m.c_str());
  507. }
  508. fout << "\t\t{" << dspguid << "}." << depcount << " = {" << guid << "}\n";
  509. depcount++;
  510. }
  511. UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
  512. if(ui != this->UtilityDepends.end())
  513. {
  514. const char* uname = ui->second.c_str();
  515. fout << "\t\t{" << this->GetGUID(uname) << "}.0 = {" << dspguid << "}\n";
  516. }
  517. }
  518. // Write a dsp file into the SLN file, Note, that dependencies from
  519. // executables to the libraries it uses are also done here
  520. void cmGlobalVisualStudio7Generator
  521. ::WriteProjectConfigurations(std::ostream& fout, const char* name,
  522. bool partOfDefaultBuild,
  523. const char* platformMapping)
  524. {
  525. std::string guid = this->GetGUID(name);
  526. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  527. i != this->Configurations.end(); ++i)
  528. {
  529. fout << "\t\t{" << guid << "}." << *i
  530. << ".ActiveCfg = " << *i << "|"
  531. << (platformMapping ? platformMapping : "Win32") << "\n";
  532. if(partOfDefaultBuild)
  533. {
  534. fout << "\t\t{" << guid << "}." << *i
  535. << ".Build.0 = " << *i << "|"
  536. << (platformMapping ? platformMapping : "Win32") << "\n";
  537. }
  538. }
  539. }
  540. // Write a dsp file into the SLN file,
  541. // Note, that dependencies from executables to
  542. // the libraries it uses are also done here
  543. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  544. const char* name,
  545. const char* location,
  546. const char* typeGuid,
  547. const std::set<cmStdString>&)
  548. {
  549. std::string d = cmSystemTools::ConvertToOutputPath(location);
  550. fout << "Project("
  551. << "\"{"
  552. << (typeGuid ? typeGuid : "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942")
  553. << "}\") = \""
  554. << name << "\", \""
  555. << this->ConvertToSolutionPath(location) << "\", \"{"
  556. << this->GetGUID(name)
  557. << "}\"\n";
  558. fout << "EndProject\n";
  559. }
  560. void cmGlobalVisualStudio7Generator
  561. ::WriteSLNGlobalSections(std::ostream& fout,
  562. cmLocalGenerator* root)
  563. {
  564. bool extensibilityGlobalsOverridden = false;
  565. bool extensibilityAddInsOverridden = false;
  566. const cmPropertyMap& props = root->GetMakefile()->GetProperties();
  567. for(cmPropertyMap::const_iterator itProp = props.begin();
  568. itProp != props.end(); ++itProp)
  569. {
  570. if(itProp->first.find("VS_GLOBAL_SECTION_") == 0)
  571. {
  572. std::string sectionType;
  573. std::string name = itProp->first.substr(18);
  574. if(name.find("PRE_") == 0)
  575. {
  576. name = name.substr(4);
  577. sectionType = "preSolution";
  578. }
  579. else if(name.find("POST_") == 0)
  580. {
  581. name = name.substr(5);
  582. sectionType = "postSolution";
  583. }
  584. else
  585. continue;
  586. if(!name.empty())
  587. {
  588. if(name == "ExtensibilityGlobals" && sectionType == "postSolution")
  589. extensibilityGlobalsOverridden = true;
  590. else if(name == "ExtensibilityAddIns" && sectionType == "postSolution")
  591. extensibilityAddInsOverridden = true;
  592. fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
  593. std::vector<std::string> keyValuePairs;
  594. cmSystemTools::ExpandListArgument(itProp->second.GetValue(),
  595. keyValuePairs);
  596. for(std::vector<std::string>::const_iterator itPair =
  597. keyValuePairs.begin(); itPair != keyValuePairs.end(); ++itPair)
  598. {
  599. const std::string::size_type posEqual = itPair->find('=');
  600. if(posEqual != std::string::npos)
  601. {
  602. const std::string key =
  603. cmSystemTools::TrimWhitespace(itPair->substr(0, posEqual));
  604. const std::string value =
  605. cmSystemTools::TrimWhitespace(itPair->substr(posEqual + 1));
  606. fout << "\t\t" << key << " = " << value << "\n";
  607. }
  608. }
  609. fout << "\tEndGlobalSection\n";
  610. }
  611. }
  612. }
  613. if(!extensibilityGlobalsOverridden)
  614. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  615. << "\tEndGlobalSection\n";
  616. if(!extensibilityAddInsOverridden)
  617. fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  618. << "\tEndGlobalSection\n";
  619. }
  620. // Standard end of dsw file
  621. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  622. {
  623. fout << "EndGlobal\n";
  624. }
  625. // ouput standard header for dsw file
  626. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  627. {
  628. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  629. }
  630. //----------------------------------------------------------------------------
  631. std::string
  632. cmGlobalVisualStudio7Generator::WriteUtilityDepend(cmTarget* target)
  633. {
  634. std::string pname = target->GetName();
  635. pname += "_UTILITY";
  636. std::string fname = target->GetMakefile()->GetStartOutputDirectory();
  637. fname += "/";
  638. fname += pname;
  639. fname += ".vcproj";
  640. cmGeneratedFileStream fout(fname.c_str());
  641. fout.SetCopyIfDifferent(true);
  642. this->CreateGUID(pname.c_str());
  643. std::string guid = this->GetGUID(pname.c_str());
  644. fout <<
  645. "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  646. "<VisualStudioProject\n"
  647. "\tProjectType=\"Visual C++\"\n"
  648. "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
  649. "\tName=\"" << pname << "\"\n"
  650. "\tProjectGUID=\"{" << guid << "}\"\n"
  651. "\tKeyword=\"Win32Proj\">\n"
  652. "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
  653. "\t<Configurations>\n"
  654. ;
  655. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  656. i != this->Configurations.end(); ++i)
  657. {
  658. fout <<
  659. "\t\t<Configuration\n"
  660. "\t\t\tName=\"" << *i << "|Win32\"\n"
  661. "\t\t\tOutputDirectory=\"" << *i << "\"\n"
  662. "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << *i << "\"\n"
  663. "\t\t\tConfigurationType=\"10\"\n"
  664. "\t\t\tUseOfMFC=\"0\"\n"
  665. "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  666. "\t\t\tCharacterSet=\"2\">\n"
  667. "\t\t</Configuration>\n"
  668. ;
  669. }
  670. fout <<
  671. "\t</Configurations>\n"
  672. "\t<Files></Files>\n"
  673. "\t<Globals></Globals>\n"
  674. "</VisualStudioProject>\n"
  675. ;
  676. if(fout.Close())
  677. {
  678. this->FileReplacedDuringGenerate(fname);
  679. }
  680. return pname;
  681. }
  682. std::string cmGlobalVisualStudio7Generator::GetGUID(const char* name)
  683. {
  684. std::string guidStoreName = name;
  685. guidStoreName += "_GUID_CMAKE";
  686. const char* storedGUID =
  687. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  688. if(storedGUID)
  689. {
  690. return std::string(storedGUID);
  691. }
  692. cmSystemTools::Error("Unknown Target referenced : ",
  693. name);
  694. return "";
  695. }
  696. void cmGlobalVisualStudio7Generator::CreateGUID(const char* name)
  697. {
  698. std::string guidStoreName = name;
  699. guidStoreName += "_GUID_CMAKE";
  700. if(this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  701. {
  702. return;
  703. }
  704. std::string ret;
  705. UUID uid;
  706. unsigned char *uidstr;
  707. UuidCreate(&uid);
  708. UuidToString(&uid,&uidstr);
  709. ret = reinterpret_cast<char*>(uidstr);
  710. RpcStringFree(&uidstr);
  711. ret = cmSystemTools::UpperCase(ret);
  712. this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
  713. ret.c_str(), "Stored GUID",
  714. cmCacheManager::INTERNAL);
  715. }
  716. std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
  717. {
  718. return &this->Configurations;
  719. };
  720. //----------------------------------------------------------------------------
  721. void cmGlobalVisualStudio7Generator
  722. ::GetDocumentation(cmDocumentationEntry& entry) const
  723. {
  724. entry.Name = this->GetName();
  725. entry.Brief = "Generates Visual Studio .NET 2002 project files.";
  726. entry.Full = "";
  727. }
  728. //----------------------------------------------------------------------------
  729. void
  730. cmGlobalVisualStudio7Generator
  731. ::AppendDirectoryForConfig(const char* prefix,
  732. const char* config,
  733. const char* suffix,
  734. std::string& dir)
  735. {
  736. if(config)
  737. {
  738. dir += prefix;
  739. dir += config;
  740. dir += suffix;
  741. }
  742. }
  743. bool cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(const char* project,
  744. cmTarget* target)
  745. {
  746. if(target->GetPropertyAsBool("EXCLUDE_FROM_DEFAULT_BUILD"))
  747. {
  748. return false;
  749. }
  750. // if it is a utilitiy target then only make it part of the
  751. // default build if another target depends on it
  752. int type = target->GetType();
  753. if (type == cmTarget::GLOBAL_TARGET)
  754. {
  755. return false;
  756. }
  757. if(type == cmTarget::UTILITY)
  758. {
  759. return this->IsDependedOn(project, target);
  760. }
  761. // default is to be part of the build
  762. return true;
  763. }
  764. //----------------------------------------------------------------------------
  765. static cmVS7FlagTable cmVS7ExtraFlagTable[] =
  766. {
  767. // Precompiled header and related options. Note that the
  768. // UsePrecompiledHeader entries are marked as "Continue" so that the
  769. // corresponding PrecompiledHeaderThrough entry can be found.
  770. {"UsePrecompiledHeader", "YX", "Automatically Generate", "2",
  771. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  772. {"PrecompiledHeaderThrough", "YX", "Precompiled Header Name", "",
  773. cmVS7FlagTable::UserValueRequired},
  774. {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "3",
  775. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  776. {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
  777. cmVS7FlagTable::UserValueRequired},
  778. {"WholeProgramOptimization", "LTCG", "WholeProgramOptimization", "TRUE", 0},
  779. // Exception handling mode. If no entries match, it will be FALSE.
  780. {"ExceptionHandling", "GX", "enable c++ exceptions", "TRUE", 0},
  781. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "TRUE", 0},
  782. // The EHa option does not have an IDE setting. Let it go to false,
  783. // and have EHa passed on the command line by leaving out the table
  784. // entry.
  785. {0,0,0,0,0}
  786. };
  787. cmIDEFlagTable const* cmGlobalVisualStudio7Generator::GetExtraFlagTableVS7()
  788. {
  789. return cmVS7ExtraFlagTable;
  790. }