cmGlobalVisualStudio7Generator.cxx 28 KB

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