cmGlobalVisualStudio7Generator.cxx 24 KB

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