cmGlobalVisualStudio7Generator.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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. void cmGlobalVisualStudio7Generator::AddPlatformDefinitions(cmMakefile* mf)
  50. {
  51. mf->AddDefinition("MSVC70", "1");
  52. mf->AddDefinition("MSVC_C_ARCHITECTURE_ID", "X86");
  53. mf->AddDefinition("MSVC_CXX_ARCHITECTURE_ID", "X86");
  54. }
  55. std::string cmGlobalVisualStudio7Generator
  56. ::GenerateBuildCommand(const char* makeProgram,
  57. const char *projectName,
  58. const char* additionalOptions, const char *targetName,
  59. const char* config, bool ignoreErrors, bool)
  60. {
  61. // Ingoring errors is not implemented in visual studio 6
  62. (void) ignoreErrors;
  63. // now build the test
  64. std::string makeCommand =
  65. cmSystemTools::ConvertToOutputPath(makeProgram);
  66. std::string lowerCaseCommand = makeCommand;
  67. cmSystemTools::LowerCase(lowerCaseCommand);
  68. // if there are spaces in the makeCommand, assume a full path
  69. // and convert it to a path with no spaces in it as the
  70. // RunSingleCommand does not like spaces
  71. #if defined(_WIN32) && !defined(__CYGWIN__)
  72. if(makeCommand.find(' ') != std::string::npos)
  73. {
  74. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  75. }
  76. #endif
  77. makeCommand += " ";
  78. makeCommand += projectName;
  79. makeCommand += ".sln ";
  80. bool clean = false;
  81. if ( targetName && strcmp(targetName, "clean") == 0 )
  82. {
  83. clean = true;
  84. targetName = "ALL_BUILD";
  85. }
  86. if(clean)
  87. {
  88. makeCommand += "/clean ";
  89. }
  90. else
  91. {
  92. makeCommand += "/build ";
  93. }
  94. if(config && strlen(config))
  95. {
  96. makeCommand += config;
  97. }
  98. else
  99. {
  100. makeCommand += "Debug";
  101. }
  102. makeCommand += " /project ";
  103. if (targetName && strlen(targetName))
  104. {
  105. makeCommand += targetName;
  106. }
  107. else
  108. {
  109. makeCommand += "ALL_BUILD";
  110. }
  111. if ( additionalOptions )
  112. {
  113. makeCommand += " ";
  114. makeCommand += additionalOptions;
  115. }
  116. return makeCommand;
  117. }
  118. ///! Create a local generator appropriate to this Global Generator
  119. cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator()
  120. {
  121. cmLocalVisualStudio7Generator *lg = new cmLocalVisualStudio7Generator;
  122. lg->SetExtraFlagTable(this->GetExtraFlagTableVS7());
  123. lg->SetGlobalGenerator(this);
  124. return lg;
  125. }
  126. void cmGlobalVisualStudio7Generator::GenerateConfigurations(cmMakefile* mf)
  127. {
  128. // process the configurations
  129. const char* ct
  130. = this->CMakeInstance->GetCacheDefinition("CMAKE_CONFIGURATION_TYPES");
  131. if ( ct )
  132. {
  133. std::vector<std::string> argsOut;
  134. cmSystemTools::ExpandListArgument(ct, argsOut);
  135. for(std::vector<std::string>::iterator i = argsOut.begin();
  136. i != argsOut.end(); ++i)
  137. {
  138. if(std::find(this->Configurations.begin(),
  139. this->Configurations.end(),
  140. *i) == this->Configurations.end())
  141. {
  142. this->Configurations.push_back(*i);
  143. }
  144. }
  145. }
  146. // default to at least Debug and Release
  147. if(this->Configurations.size() == 0)
  148. {
  149. this->Configurations.push_back("Debug");
  150. this->Configurations.push_back("Release");
  151. }
  152. // Reset the entry to have a semi-colon separated list.
  153. std::string configs = this->Configurations[0];
  154. for(unsigned int i=1; i < this->Configurations.size(); ++i)
  155. {
  156. configs += ";";
  157. configs += this->Configurations[i];
  158. }
  159. mf->AddCacheDefinition(
  160. "CMAKE_CONFIGURATION_TYPES",
  161. configs.c_str(),
  162. "Semicolon separated list of supported configuration types, "
  163. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  164. "anything else will be ignored.",
  165. cmCacheManager::STRING);
  166. }
  167. void cmGlobalVisualStudio7Generator::Generate()
  168. {
  169. // first do the superclass method
  170. this->cmGlobalVisualStudioGenerator::Generate();
  171. // Now write out the DSW
  172. this->OutputSLNFile();
  173. // If any solution or project files changed during the generation,
  174. // tell Visual Studio to reload them...
  175. if(!cmSystemTools::GetErrorOccuredFlag())
  176. {
  177. this->CallVisualStudioMacro(MacroReload);
  178. }
  179. }
  180. void cmGlobalVisualStudio7Generator
  181. ::OutputSLNFile(cmLocalGenerator* root,
  182. std::vector<cmLocalGenerator*>& generators)
  183. {
  184. if(generators.size() == 0)
  185. {
  186. return;
  187. }
  188. this->CurrentProject = root->GetMakefile()->GetProjectName();
  189. std::string fname = root->GetMakefile()->GetStartOutputDirectory();
  190. fname += "/";
  191. fname += root->GetMakefile()->GetProjectName();
  192. fname += ".sln";
  193. cmGeneratedFileStream fout(fname.c_str());
  194. fout.SetCopyIfDifferent(true);
  195. if(!fout)
  196. {
  197. return;
  198. }
  199. this->WriteSLNFile(fout, root, generators);
  200. if (fout.Close())
  201. {
  202. this->FileReplacedDuringGenerate(fname);
  203. }
  204. }
  205. // output the SLN file
  206. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  207. {
  208. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  209. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  210. {
  211. this->OutputSLNFile(it->second[0], it->second);
  212. }
  213. }
  214. void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
  215. std::ostream& fout,
  216. cmLocalGenerator* root,
  217. OrderedTargetDependSet const& projectTargets)
  218. {
  219. // loop over again and write out configurations for each target
  220. // in the solution
  221. for(OrderedTargetDependSet::const_iterator tt =
  222. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  223. {
  224. cmTarget* target = *tt;
  225. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  226. if(expath)
  227. {
  228. this->WriteProjectConfigurations(fout, target->GetName(),
  229. true);
  230. }
  231. else
  232. {
  233. bool partOfDefaultBuild = this->IsPartOfDefaultBuild(
  234. root->GetMakefile()->GetProjectName(), target);
  235. const char *vcprojName =
  236. target->GetProperty("GENERATOR_FILE_NAME");
  237. if (vcprojName)
  238. {
  239. this->WriteProjectConfigurations(fout, vcprojName,
  240. partOfDefaultBuild);
  241. }
  242. }
  243. }
  244. }
  245. void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
  246. std::ostream& fout,
  247. cmLocalGenerator* root,
  248. OrderedTargetDependSet const& projectTargets)
  249. {
  250. std::string rootdir = root->GetMakefile()->GetStartOutputDirectory();
  251. rootdir += "/";
  252. for(OrderedTargetDependSet::const_iterator tt =
  253. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  254. {
  255. cmTarget* target = *tt;
  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, project.c_str(),
  263. location.c_str(), target->GetUtilities());
  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. this->WriteProject(fout, vcprojName, dir.c_str(),
  276. *target);
  277. // Create "solution folder" information from FOLDER target property
  278. //
  279. if (this->UseFolderProperty())
  280. {
  281. const char *targetFolder = target->GetProperty("FOLDER");
  282. if (targetFolder)
  283. {
  284. std::vector<cmsys::String> tokens =
  285. cmSystemTools::SplitString(targetFolder, '/', false);
  286. std::string cumulativePath = "";
  287. for(std::vector<cmsys::String>::iterator iter = tokens.begin();
  288. iter != tokens.end(); ++iter)
  289. {
  290. if(!iter->size())
  291. {
  292. continue;
  293. }
  294. if (cumulativePath.empty())
  295. {
  296. cumulativePath = *iter;
  297. }
  298. else
  299. {
  300. VisualStudioFolders[cumulativePath].insert(
  301. cumulativePath + "/" + *iter);
  302. cumulativePath = cumulativePath + "/" + *iter;
  303. }
  304. this->CreateGUID(cumulativePath.c_str());
  305. }
  306. if (!cumulativePath.empty())
  307. {
  308. VisualStudioFolders[cumulativePath].insert(target->GetName());
  309. }
  310. }
  311. }
  312. }
  313. }
  314. }
  315. }
  316. void cmGlobalVisualStudio7Generator::WriteTargetDepends(
  317. std::ostream& fout,
  318. OrderedTargetDependSet const& projectTargets
  319. )
  320. {
  321. for(OrderedTargetDependSet::const_iterator tt =
  322. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  323. {
  324. cmTarget* target = *tt;
  325. cmMakefile* mf = target->GetMakefile();
  326. const char *vcprojName =
  327. target->GetProperty("GENERATOR_FILE_NAME");
  328. if (vcprojName)
  329. {
  330. std::string dir = mf->GetStartDirectory();
  331. this->WriteProjectDepends(fout, vcprojName,
  332. dir.c_str(), *target);
  333. }
  334. }
  335. }
  336. //----------------------------------------------------------------------------
  337. // Write a SLN file to the stream
  338. void cmGlobalVisualStudio7Generator
  339. ::WriteSLNFile(std::ostream& fout,
  340. cmLocalGenerator* root,
  341. std::vector<cmLocalGenerator*>& generators)
  342. {
  343. // Write out the header for a SLN file
  344. this->WriteSLNHeader(fout);
  345. // Collect all targets under this root generator and the transitive
  346. // closure of their dependencies.
  347. TargetDependSet projectTargets;
  348. TargetDependSet originalTargets;
  349. this->GetTargetSets(projectTargets, originalTargets, root, generators);
  350. OrderedTargetDependSet orderedProjectTargets(projectTargets);
  351. this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
  352. bool useFolderProperty = this->UseFolderProperty();
  353. if (useFolderProperty)
  354. {
  355. this->WriteFolders(fout);
  356. }
  357. // Write out the configurations information for the solution
  358. fout << "Global\n"
  359. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  360. int c = 0;
  361. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  362. i != this->Configurations.end(); ++i)
  363. {
  364. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  365. c++;
  366. }
  367. fout << "\tEndGlobalSection\n";
  368. // Write out project(target) depends
  369. fout << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  370. this->WriteTargetDepends(fout, orderedProjectTargets);
  371. fout << "\tEndGlobalSection\n";
  372. if (useFolderProperty)
  373. {
  374. // Write out project folders
  375. fout << "\tGlobalSection(NestedProjects) = preSolution\n";
  376. this->WriteFoldersContent(fout);
  377. fout << "\tEndGlobalSection\n";
  378. }
  379. // Write out the configurations for all the targets in the project
  380. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  381. this->WriteTargetConfigurations(fout, root, orderedProjectTargets);
  382. fout << "\tEndGlobalSection\n";
  383. // Write the footer for the SLN file
  384. this->WriteSLNFooter(fout);
  385. }
  386. //----------------------------------------------------------------------------
  387. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  388. {
  389. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  390. for(std::map<std::string,std::set<std::string> >::iterator iter =
  391. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  392. {
  393. std::string fullName = iter->first;
  394. std::string guid = this->GetGUID(fullName.c_str());
  395. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  396. cmSystemTools::ReplaceString(fullName, "/", "\\");
  397. fout << "Project(\"{" <<
  398. guidProjectTypeFolder << "}\") = \"" <<
  399. nameOnly << "\", \"" <<
  400. fullName << "\", \"{" <<
  401. guid <<
  402. "}\"\nEndProject\n";
  403. }
  404. }
  405. //----------------------------------------------------------------------------
  406. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  407. {
  408. for(std::map<std::string,std::set<std::string> >::iterator iter =
  409. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  410. {
  411. std::string key(iter->first);
  412. std::string guidParent(this->GetGUID(key.c_str()));
  413. for(std::set<std::string>::iterator it = iter->second.begin();
  414. it != iter->second.end(); ++it)
  415. {
  416. std::string value(*it);
  417. std::string guid(this->GetGUID(value.c_str()));
  418. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  419. }
  420. }
  421. }
  422. //----------------------------------------------------------------------------
  423. std::string
  424. cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
  425. {
  426. // Convert to backslashes. Do not use ConvertToOutputPath because
  427. // we will add quoting ourselves, and we know these projects always
  428. // use windows slashes.
  429. std::string d = path;
  430. std::string::size_type pos = 0;
  431. while((pos = d.find('/', pos)) != d.npos)
  432. {
  433. d[pos++] = '\\';
  434. }
  435. return d;
  436. }
  437. // Write a dsp file into the SLN file,
  438. // Note, that dependencies from executables to
  439. // the libraries it uses are also done here
  440. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  441. const char* dspname,
  442. const char* dir, cmTarget& target)
  443. {
  444. // check to see if this is a fortran build
  445. const char* ext = ".vcproj";
  446. const char* project =
  447. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  448. if(this->TargetIsFortranOnly(target))
  449. {
  450. ext = ".vfproj";
  451. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  452. }
  453. fout << project
  454. << dspname << "\", \""
  455. << this->ConvertToSolutionPath(dir)
  456. << "\\" << dspname << ext << "\", \"{"
  457. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  458. }
  459. // Write a dsp file into the SLN file,
  460. // Note, that dependencies from executables to
  461. // the libraries it uses are also done here
  462. void
  463. cmGlobalVisualStudio7Generator
  464. ::WriteProjectDepends(std::ostream& fout,
  465. const char* dspname,
  466. const char*, cmTarget& target)
  467. {
  468. int depcount = 0;
  469. // insert Begin Project Dependency Project_Dep_Name project stuff here
  470. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  471. {
  472. cmTarget::LinkLibraryVectorType::const_iterator j, jend;
  473. j = target.GetLinkLibraries().begin();
  474. jend = target.GetLinkLibraries().end();
  475. for(;j!= jend; ++j)
  476. {
  477. if(j->first != dspname)
  478. {
  479. // is the library part of this SLN ? If so add dependency
  480. if(this->FindTarget(0, j->first.c_str()))
  481. {
  482. std::string guid = this->GetGUID(j->first.c_str());
  483. if(guid.size() == 0)
  484. {
  485. std::string m = "Target: ";
  486. m += dspname;
  487. m += " depends on unknown target: ";
  488. m += j->first.c_str();
  489. cmSystemTools::Error(m.c_str());
  490. }
  491. fout << "\t\t{" << this->GetGUID(dspname) << "}."
  492. << depcount << " = {" << guid << "}\n";
  493. depcount++;
  494. }
  495. }
  496. }
  497. }
  498. std::set<cmStdString>::const_iterator i, end;
  499. // write utility dependencies.
  500. i = target.GetUtilities().begin();
  501. end = target.GetUtilities().end();
  502. for(;i!= end; ++i)
  503. {
  504. if(*i != dspname)
  505. {
  506. std::string name = this->GetUtilityForTarget(target, i->c_str());
  507. std::string guid = this->GetGUID(name.c_str());
  508. if(guid.size() == 0)
  509. {
  510. std::string m = "Target: ";
  511. m += dspname;
  512. m += " depends on unknown target: ";
  513. m += name.c_str();
  514. cmSystemTools::Error(m.c_str());
  515. }
  516. fout << "\t\t{" << this->GetGUID(dspname) << "}." << depcount << " = {"
  517. << guid << "}\n";
  518. depcount++;
  519. }
  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(std::ostream& fout, const char* name,
  526. bool partOfDefaultBuild)
  527. {
  528. std::string guid = this->GetGUID(name);
  529. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  530. i != this->Configurations.end(); ++i)
  531. {
  532. fout << "\t\t{" << guid << "}." << *i
  533. << ".ActiveCfg = " << *i << "|Win32\n";
  534. if(partOfDefaultBuild)
  535. {
  536. fout << "\t\t{" << guid << "}." << *i
  537. << ".Build.0 = " << *i << "|Win32\n";
  538. }
  539. }
  540. }
  541. // Write a dsp file into the SLN file,
  542. // Note, that dependencies from executables to
  543. // the libraries it uses are also done here
  544. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  545. const char* name,
  546. const char* location,
  547. const std::set<cmStdString>&)
  548. {
  549. std::string d = cmSystemTools::ConvertToOutputPath(location);
  550. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  551. << name << "\", \""
  552. << this->ConvertToSolutionPath(location) << "\", \"{"
  553. << this->GetGUID(name)
  554. << "}\"\n";
  555. fout << "EndProject\n";
  556. }
  557. // Standard end of dsw file
  558. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  559. {
  560. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  561. << "\tEndGlobalSection\n"
  562. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  563. << "\tEndGlobalSection\n"
  564. << "EndGlobal\n";
  565. }
  566. // ouput standard header for dsw file
  567. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  568. {
  569. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  570. }
  571. std::string cmGlobalVisualStudio7Generator::GetGUID(const char* name)
  572. {
  573. std::string guidStoreName = name;
  574. guidStoreName += "_GUID_CMAKE";
  575. const char* storedGUID =
  576. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  577. if(storedGUID)
  578. {
  579. return std::string(storedGUID);
  580. }
  581. cmSystemTools::Error("Unknown Target referenced : ",
  582. name);
  583. return "";
  584. }
  585. void cmGlobalVisualStudio7Generator::CreateGUID(const char* name)
  586. {
  587. std::string guidStoreName = name;
  588. guidStoreName += "_GUID_CMAKE";
  589. if(this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  590. {
  591. return;
  592. }
  593. std::string ret;
  594. UUID uid;
  595. unsigned char *uidstr;
  596. UuidCreate(&uid);
  597. UuidToString(&uid,&uidstr);
  598. ret = reinterpret_cast<char*>(uidstr);
  599. RpcStringFree(&uidstr);
  600. ret = cmSystemTools::UpperCase(ret);
  601. this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
  602. ret.c_str(), "Stored GUID",
  603. cmCacheManager::INTERNAL);
  604. }
  605. std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
  606. {
  607. return &this->Configurations;
  608. };
  609. //----------------------------------------------------------------------------
  610. void cmGlobalVisualStudio7Generator
  611. ::GetDocumentation(cmDocumentationEntry& entry) const
  612. {
  613. entry.Name = this->GetName();
  614. entry.Brief = "Generates Visual Studio .NET 2002 project files.";
  615. entry.Full = "";
  616. }
  617. // make sure "special" targets have GUID's
  618. void cmGlobalVisualStudio7Generator::Configure()
  619. {
  620. cmGlobalGenerator::Configure();
  621. this->CreateGUID("ALL_BUILD");
  622. this->CreateGUID("INSTALL");
  623. this->CreateGUID("RUN_TESTS");
  624. this->CreateGUID("EDIT_CACHE");
  625. this->CreateGUID("REBUILD_CACHE");
  626. this->CreateGUID("PACKAGE");
  627. }
  628. //----------------------------------------------------------------------------
  629. void
  630. cmGlobalVisualStudio7Generator
  631. ::AppendDirectoryForConfig(const char* prefix,
  632. const char* config,
  633. const char* suffix,
  634. std::string& dir)
  635. {
  636. if(config)
  637. {
  638. dir += prefix;
  639. dir += config;
  640. dir += suffix;
  641. }
  642. }
  643. bool cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(const char* project,
  644. cmTarget* target)
  645. {
  646. if(target->GetPropertyAsBool("EXCLUDE_FROM_DEFAULT_BUILD"))
  647. {
  648. return false;
  649. }
  650. // if it is a utilitiy target then only make it part of the
  651. // default build if another target depends on it
  652. int type = target->GetType();
  653. if (type == cmTarget::GLOBAL_TARGET)
  654. {
  655. return false;
  656. }
  657. if(type == cmTarget::UTILITY)
  658. {
  659. return this->IsDependedOn(project, target);
  660. }
  661. // default is to be part of the build
  662. return true;
  663. }
  664. //----------------------------------------------------------------------------
  665. static cmVS7FlagTable cmVS7ExtraFlagTable[] =
  666. {
  667. // Precompiled header and related options. Note that the
  668. // UsePrecompiledHeader entries are marked as "Continue" so that the
  669. // corresponding PrecompiledHeaderThrough entry can be found.
  670. {"UsePrecompiledHeader", "YX", "Automatically Generate", "2",
  671. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  672. {"PrecompiledHeaderThrough", "YX", "Precompiled Header Name", "",
  673. cmVS7FlagTable::UserValueRequired},
  674. {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "3",
  675. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  676. {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
  677. cmVS7FlagTable::UserValueRequired},
  678. {"WholeProgramOptimization", "LTCG", "WholeProgramOptimization", "TRUE", 0},
  679. // Exception handling mode. If no entries match, it will be FALSE.
  680. {"ExceptionHandling", "GX", "enable c++ exceptions", "TRUE", 0},
  681. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "TRUE", 0},
  682. // The EHa option does not have an IDE setting. Let it go to false,
  683. // and have EHa passed on the command line by leaving out the table
  684. // entry.
  685. {0,0,0,0,0}
  686. };
  687. cmIDEFlagTable const* cmGlobalVisualStudio7Generator::GetExtraFlagTableVS7()
  688. {
  689. return cmVS7ExtraFlagTable;
  690. }