cmGlobalVisualStudio7Generator.cxx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  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_Fortran", "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::string configTypes = ct;
  135. std::string::size_type start = 0;
  136. std::string::size_type endpos = 0;
  137. while(endpos != std::string::npos)
  138. {
  139. endpos = configTypes.find_first_of(" ;", start);
  140. std::string config;
  141. std::string::size_type len;
  142. if(endpos != std::string::npos)
  143. {
  144. len = endpos - start;
  145. }
  146. else
  147. {
  148. len = configTypes.size() - start;
  149. }
  150. config = configTypes.substr(start, len);
  151. if(config == "Debug" || config == "Release" ||
  152. config == "MinSizeRel" || config == "RelWithDebInfo")
  153. {
  154. // only add unique configurations
  155. if(std::find(this->Configurations.begin(),
  156. this->Configurations.end(),
  157. config) == this->Configurations.end())
  158. {
  159. this->Configurations.push_back(config);
  160. }
  161. }
  162. else
  163. {
  164. cmSystemTools::Error(
  165. "Invalid configuration type in CMAKE_CONFIGURATION_TYPES: ",
  166. config.c_str(),
  167. " (Valid types are Debug,Release,MinSizeRel,RelWithDebInfo)");
  168. }
  169. start = endpos+1;
  170. }
  171. }
  172. if(this->Configurations.size() == 0)
  173. {
  174. this->Configurations.push_back("Debug");
  175. this->Configurations.push_back("Release");
  176. }
  177. // Reset the entry to have a semi-colon separated list.
  178. std::string configs = this->Configurations[0];
  179. for(unsigned int i=1; i < this->Configurations.size(); ++i)
  180. {
  181. configs += ";";
  182. configs += this->Configurations[i];
  183. }
  184. mf->AddCacheDefinition(
  185. "CMAKE_CONFIGURATION_TYPES",
  186. configs.c_str(),
  187. "Semicolon separated list of supported configuration types, "
  188. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  189. "anything else will be ignored.",
  190. cmCacheManager::STRING);
  191. }
  192. void cmGlobalVisualStudio7Generator::Generate()
  193. {
  194. // first do the superclass method
  195. this->cmGlobalVisualStudioGenerator::Generate();
  196. // Now write out the DSW
  197. this->OutputSLNFile();
  198. // If any solution or project files changed during the generation,
  199. // tell Visual Studio to reload them...
  200. if(!cmSystemTools::GetErrorOccuredFlag())
  201. {
  202. this->CallVisualStudioReloadMacro();
  203. }
  204. }
  205. void cmGlobalVisualStudio7Generator
  206. ::OutputSLNFile(cmLocalGenerator* root,
  207. std::vector<cmLocalGenerator*>& generators)
  208. {
  209. if(generators.size() == 0)
  210. {
  211. return;
  212. }
  213. this->CurrentProject = root->GetMakefile()->GetProjectName();
  214. std::string fname = root->GetMakefile()->GetStartOutputDirectory();
  215. fname += "/";
  216. fname += root->GetMakefile()->GetProjectName();
  217. fname += ".sln";
  218. cmGeneratedFileStream fout(fname.c_str());
  219. fout.SetCopyIfDifferent(true);
  220. if(!fout)
  221. {
  222. return;
  223. }
  224. this->WriteSLNFile(fout, root, generators);
  225. if (fout.Close())
  226. {
  227. this->FileReplacedDuringGenerate(fname);
  228. }
  229. }
  230. // output the SLN file
  231. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  232. {
  233. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  234. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  235. {
  236. this->OutputSLNFile(it->second[0], it->second);
  237. }
  238. }
  239. // Write a SLN file to the stream
  240. void cmGlobalVisualStudio7Generator
  241. ::WriteSLNFile(std::ostream& fout,
  242. cmLocalGenerator* root,
  243. std::vector<cmLocalGenerator*>& generators)
  244. {
  245. // Write out the header for a SLN file
  246. this->WriteSLNHeader(fout);
  247. // Get the start directory with the trailing slash
  248. std::string rootdir = root->GetMakefile()->GetStartOutputDirectory();
  249. rootdir += "/";
  250. bool doneAllBuild = false;
  251. bool doneRunTests = false;
  252. bool doneInstall = false;
  253. bool doneEditCache = false;
  254. bool doneRebuildCache = false;
  255. bool donePackage = false;
  256. // For each cmMakefile, create a VCProj for it, and
  257. // add it to this SLN file
  258. unsigned int i;
  259. for(i = 0; i < generators.size(); ++i)
  260. {
  261. if(this->IsExcluded(root, generators[i]))
  262. {
  263. continue;
  264. }
  265. cmMakefile* mf = generators[i]->GetMakefile();
  266. // Get the source directory from the makefile
  267. std::string dir = mf->GetStartOutputDirectory();
  268. // remove the home directory and / from the source directory
  269. // this gives a relative path
  270. cmSystemTools::ReplaceString(dir, rootdir.c_str(), "");
  271. // Get the list of create dsp files names from the cmVCProjWriter, more
  272. // than one dsp could have been created per input CMakeLists.txt file
  273. // for each target
  274. cmTargets &tgts = generators[i]->GetMakefile()->GetTargets();
  275. for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  276. {
  277. // special handling for the current makefile
  278. if(mf == generators[0]->GetMakefile())
  279. {
  280. dir = "."; // no subdirectory for project generated
  281. // if this is the special ALL_BUILD utility, then
  282. // make it depend on every other non UTILITY project.
  283. // This is done by adding the names to the GetUtilities
  284. // vector on the makefile
  285. if(l->first == "ALL_BUILD" && !doneAllBuild)
  286. {
  287. unsigned int j;
  288. for(j = 0; j < generators.size(); ++j)
  289. {
  290. cmTargets &atgts = generators[j]->GetMakefile()->GetTargets();
  291. for(cmTargets::iterator al = atgts.begin();
  292. al != atgts.end(); ++al)
  293. {
  294. if (!al->second.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  295. {
  296. if (al->second.GetType() == cmTarget::UTILITY ||
  297. al->second.GetType() == cmTarget::GLOBAL_TARGET)
  298. {
  299. l->second.AddUtility(al->first.c_str());
  300. }
  301. else
  302. {
  303. l->second.AddLinkLibrary(al->first,cmTarget::GENERAL);
  304. }
  305. }
  306. }
  307. }
  308. }
  309. }
  310. // Write the project into the SLN file
  311. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  312. {
  313. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  314. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  315. std::string project = cmds[0][0];
  316. std::string location = cmds[0][1];
  317. this->WriteExternalProject(fout, project.c_str(),
  318. location.c_str(), cc.GetDepends());
  319. }
  320. else
  321. {
  322. bool skip = false;
  323. if(l->first == "ALL_BUILD" )
  324. {
  325. if(doneAllBuild)
  326. {
  327. skip = true;
  328. }
  329. else
  330. {
  331. doneAllBuild = true;
  332. }
  333. }
  334. if(l->first == "INSTALL")
  335. {
  336. if(doneInstall)
  337. {
  338. skip = true;
  339. }
  340. else
  341. {
  342. doneInstall = true;
  343. }
  344. }
  345. if(l->first == "RUN_TESTS")
  346. {
  347. if(doneRunTests)
  348. {
  349. skip = true;
  350. }
  351. else
  352. {
  353. doneRunTests = true;
  354. }
  355. }
  356. if(l->first == "EDIT_CACHE")
  357. {
  358. if(doneEditCache)
  359. {
  360. skip = true;
  361. }
  362. else
  363. {
  364. doneEditCache = true;
  365. }
  366. }
  367. if(l->first == "REBUILD_CACHE")
  368. {
  369. if(doneRebuildCache)
  370. {
  371. skip = true;
  372. }
  373. else
  374. {
  375. doneRebuildCache = true;
  376. }
  377. }
  378. if(l->first == "PACKAGE")
  379. {
  380. if(donePackage)
  381. {
  382. skip = true;
  383. }
  384. else
  385. {
  386. donePackage = true;
  387. }
  388. }
  389. if(!skip)
  390. {
  391. const char *dspname =
  392. l->second.GetProperty("GENERATOR_FILE_NAME");
  393. if (dspname)
  394. {
  395. this->WriteProject(fout, dspname, dir.c_str(),l->second);
  396. }
  397. }
  398. }
  399. }
  400. }
  401. fout << "Global\n"
  402. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  403. int c = 0;
  404. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  405. i != this->Configurations.end(); ++i)
  406. {
  407. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  408. c++;
  409. }
  410. fout << "\tEndGlobalSection\n"
  411. << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  412. // loop over again and compute the depends
  413. for(i = 0; i < generators.size(); ++i)
  414. {
  415. cmMakefile* mf = generators[i]->GetMakefile();
  416. cmLocalVisualStudio7Generator* pg =
  417. static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
  418. // Get the list of create dsp files names from the cmVCProjWriter, more
  419. // than one dsp could have been created per input CMakeLists.txt file
  420. // for each target
  421. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  422. cmTargets::iterator l = tgts.begin();
  423. std::string dir = mf->GetStartDirectory();
  424. for(; l != tgts.end(); ++l)
  425. {
  426. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  427. {
  428. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  429. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  430. std::string name = cmds[0][0];
  431. std::vector<std::string> depends = cc.GetDepends();
  432. std::vector<std::string>::iterator iter;
  433. int depcount = 0;
  434. for(iter = depends.begin(); iter != depends.end(); ++iter)
  435. {
  436. std::string guid = this->GetGUID(iter->c_str());
  437. if(guid.size() == 0)
  438. {
  439. std::string m = "Target: ";
  440. m += l->first;
  441. m += " depends on unknown target: ";
  442. m += iter->c_str();
  443. cmSystemTools::Error(m.c_str());
  444. }
  445. fout << "\t\t{" << this->GetGUID(name.c_str())
  446. << "}." << depcount << " = {" << guid.c_str() << "}\n";
  447. depcount++;
  448. }
  449. }
  450. else
  451. {
  452. const char *dspname =
  453. l->second.GetProperty("GENERATOR_FILE_NAME");
  454. if (dspname)
  455. {
  456. this->WriteProjectDepends(fout, dspname,
  457. dir.c_str(), l->second);
  458. }
  459. }
  460. }
  461. }
  462. fout << "\tEndGlobalSection\n";
  463. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  464. // loop over again and compute the depends
  465. for(i = 0; i < generators.size(); ++i)
  466. {
  467. cmMakefile* mf = generators[i]->GetMakefile();
  468. cmLocalVisualStudio7Generator* pg =
  469. static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
  470. // Get the list of create dsp files names from the cmVCProjWriter, more
  471. // than one dsp could have been created per input CMakeLists.txt file
  472. // for each target
  473. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  474. cmTargets::iterator l = tgts.begin();
  475. std::string dir = mf->GetStartDirectory();
  476. for(; l != tgts.end(); ++l)
  477. {
  478. if(strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  479. {
  480. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  481. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  482. std::string name = cmds[0][0];
  483. this->WriteProjectConfigurations(fout, name.c_str(),
  484. true);
  485. }
  486. else
  487. {
  488. bool partOfDefaultBuild = this->IsPartOfDefaultBuild(
  489. root->GetMakefile()->GetProjectName(),
  490. &l->second);
  491. const char *dspname =
  492. l->second.GetProperty("GENERATOR_FILE_NAME");
  493. if (dspname)
  494. {
  495. this->WriteProjectConfigurations(fout, dspname,
  496. partOfDefaultBuild);
  497. }
  498. }
  499. }
  500. }
  501. fout << "\tEndGlobalSection\n";
  502. // Write the footer for the SLN file
  503. this->WriteSLNFooter(fout);
  504. }
  505. //----------------------------------------------------------------------------
  506. std::string
  507. cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
  508. {
  509. // Convert to backslashes. Do not use ConvertToOutputPath because
  510. // we will add quoting ourselves, and we know these projects always
  511. // use windows slashes.
  512. std::string d = path;
  513. std::string::size_type pos = 0;
  514. while((pos = d.find('/', pos)) != d.npos)
  515. {
  516. d[pos++] = '\\';
  517. }
  518. return d;
  519. }
  520. // Write a dsp file into the SLN file,
  521. // Note, that dependencies from executables to
  522. // the libraries it uses are also done here
  523. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  524. const char* dspname,
  525. const char* dir, cmTarget&)
  526. {
  527. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  528. << dspname << "\", \""
  529. << this->ConvertToSolutionPath(dir)
  530. << "\\" << dspname << ".vcproj\", \"{"
  531. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  532. }
  533. // Write a dsp file into the SLN file,
  534. // Note, that dependencies from executables to
  535. // the libraries it uses are also done here
  536. void
  537. cmGlobalVisualStudio7Generator
  538. ::WriteProjectDepends(std::ostream& fout,
  539. const char* dspname,
  540. const char*, cmTarget& target)
  541. {
  542. int depcount = 0;
  543. // insert Begin Project Dependency Project_Dep_Name project stuff here
  544. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  545. {
  546. cmTarget::LinkLibraryVectorType::const_iterator j, jend;
  547. j = target.GetLinkLibraries().begin();
  548. jend = target.GetLinkLibraries().end();
  549. for(;j!= jend; ++j)
  550. {
  551. if(j->first != dspname)
  552. {
  553. // is the library part of this SLN ? If so add dependency
  554. if(this->FindTarget(this->CurrentProject.c_str(),
  555. j->first.c_str(), false))
  556. {
  557. std::string guid = this->GetGUID(j->first.c_str());
  558. if(guid.size() == 0)
  559. {
  560. std::string m = "Target: ";
  561. m += dspname;
  562. m += " depends on unknown target: ";
  563. m += j->first.c_str();
  564. cmSystemTools::Error(m.c_str());
  565. }
  566. fout << "\t\t{" << this->GetGUID(dspname) << "}."
  567. << depcount << " = {" << guid << "}\n";
  568. depcount++;
  569. }
  570. }
  571. }
  572. }
  573. std::set<cmStdString>::const_iterator i, end;
  574. // write utility dependencies.
  575. i = target.GetUtilities().begin();
  576. end = target.GetUtilities().end();
  577. for(;i!= end; ++i)
  578. {
  579. if(*i != dspname)
  580. {
  581. std::string name = this->GetUtilityForTarget(target, i->c_str());
  582. std::string guid = this->GetGUID(name.c_str());
  583. if(guid.size() == 0)
  584. {
  585. std::string m = "Target: ";
  586. m += dspname;
  587. m += " depends on unknown target: ";
  588. m += name.c_str();
  589. cmSystemTools::Error(m.c_str());
  590. }
  591. fout << "\t\t{" << this->GetGUID(dspname) << "}." << depcount << " = {"
  592. << guid << "}\n";
  593. depcount++;
  594. }
  595. }
  596. }
  597. // Write a dsp file into the SLN file, Note, that dependencies from
  598. // executables to the libraries it uses are also done here
  599. void cmGlobalVisualStudio7Generator
  600. ::WriteProjectConfigurations(std::ostream& fout, const char* name,
  601. bool partOfDefaultBuild)
  602. {
  603. std::string guid = this->GetGUID(name);
  604. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  605. i != this->Configurations.end(); ++i)
  606. {
  607. fout << "\t\t{" << guid << "}." << *i
  608. << ".ActiveCfg = " << *i << "|Win32\n";
  609. if(partOfDefaultBuild)
  610. {
  611. fout << "\t\t{" << guid << "}." << *i
  612. << ".Build.0 = " << *i << "|Win32\n";
  613. }
  614. }
  615. }
  616. // Write a dsp file into the SLN file,
  617. // Note, that dependencies from executables to
  618. // the libraries it uses are also done here
  619. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  620. const char* name,
  621. const char* location,
  622. const std::vector<std::string>&)
  623. {
  624. std::string d = cmSystemTools::ConvertToOutputPath(location);
  625. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  626. << name << "\", \""
  627. << this->ConvertToSolutionPath(location) << "\", \"{"
  628. << this->GetGUID(name)
  629. << "}\"\n";
  630. fout << "EndProject\n";
  631. }
  632. // Standard end of dsw file
  633. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  634. {
  635. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  636. << "\tEndGlobalSection\n"
  637. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  638. << "\tEndGlobalSection\n"
  639. << "EndGlobal\n";
  640. }
  641. // ouput standard header for dsw file
  642. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  643. {
  644. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  645. }
  646. std::string cmGlobalVisualStudio7Generator::GetGUID(const char* name)
  647. {
  648. std::string guidStoreName = name;
  649. guidStoreName += "_GUID_CMAKE";
  650. const char* storedGUID =
  651. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  652. if(storedGUID)
  653. {
  654. return std::string(storedGUID);
  655. }
  656. cmSystemTools::Error("Unknown Target referenced : ",
  657. name);
  658. return "";
  659. }
  660. void cmGlobalVisualStudio7Generator::CreateGUID(const char* name)
  661. {
  662. std::string guidStoreName = name;
  663. guidStoreName += "_GUID_CMAKE";
  664. if(this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  665. {
  666. return;
  667. }
  668. std::string ret;
  669. UUID uid;
  670. unsigned char *uidstr;
  671. UuidCreate(&uid);
  672. UuidToString(&uid,&uidstr);
  673. ret = reinterpret_cast<char*>(uidstr);
  674. RpcStringFree(&uidstr);
  675. ret = cmSystemTools::UpperCase(ret);
  676. this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
  677. ret.c_str(), "Stored GUID",
  678. cmCacheManager::INTERNAL);
  679. }
  680. std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
  681. {
  682. return &this->Configurations;
  683. };
  684. //----------------------------------------------------------------------------
  685. void cmGlobalVisualStudio7Generator
  686. ::GetDocumentation(cmDocumentationEntry& entry) const
  687. {
  688. entry.Name = this->GetName();
  689. entry.Brief = "Generates Visual Studio .NET 2002 project files.";
  690. entry.Full = "";
  691. }
  692. // make sure "special" targets have GUID's
  693. void cmGlobalVisualStudio7Generator::Configure()
  694. {
  695. cmGlobalGenerator::Configure();
  696. this->CreateGUID("ALL_BUILD");
  697. this->CreateGUID("INSTALL");
  698. this->CreateGUID("RUN_TESTS");
  699. this->CreateGUID("EDIT_CACHE");
  700. this->CreateGUID("REBUILD_CACHE");
  701. this->CreateGUID("PACKAGE");
  702. }
  703. //----------------------------------------------------------------------------
  704. void
  705. cmGlobalVisualStudio7Generator
  706. ::AppendDirectoryForConfig(const char* prefix,
  707. const char* config,
  708. const char* suffix,
  709. std::string& dir)
  710. {
  711. if(config)
  712. {
  713. dir += prefix;
  714. dir += config;
  715. dir += suffix;
  716. }
  717. }
  718. bool cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(const char* project,
  719. cmTarget* target)
  720. {
  721. if(target->GetPropertyAsBool("EXCLUDE_FROM_DEFAULT_BUILD"))
  722. {
  723. return false;
  724. }
  725. // if it is a utilitiy target then only make it part of the
  726. // default build if another target depends on it
  727. int type = target->GetType();
  728. if (type == cmTarget::GLOBAL_TARGET)
  729. {
  730. return false;
  731. }
  732. if(type == cmTarget::UTILITY)
  733. {
  734. return this->IsDependedOn(project, target);
  735. }
  736. // default is to be part of the build
  737. return true;
  738. }
  739. //----------------------------------------------------------------------------
  740. static cmVS7FlagTable cmVS7ExtraFlagTable[] =
  741. {
  742. // Precompiled header and related options. Note that the
  743. // UsePrecompiledHeader entries are marked as "Continue" so that the
  744. // corresponding PrecompiledHeaderThrough entry can be found.
  745. {"UsePrecompiledHeader", "YX", "Automatically Generate", "2",
  746. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  747. {"PrecompiledHeaderThrough", "YX", "Precompiled Header Name", "",
  748. cmVS7FlagTable::UserValueRequired},
  749. {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "3",
  750. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  751. {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
  752. cmVS7FlagTable::UserValueRequired},
  753. // Exception handling mode. If no entries match, it will be FALSE.
  754. {"ExceptionHandling", "GX", "enable c++ exceptions", "TRUE", 0},
  755. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "TRUE", 0},
  756. // The EHa option does not have an IDE setting. Let it go to false,
  757. // and have EHa passed on the command line by leaving out the table
  758. // entry.
  759. {0,0,0,0,0}
  760. };
  761. cmVS7FlagTable const* cmGlobalVisualStudio7Generator::GetExtraFlagTableVS7()
  762. {
  763. return cmVS7ExtraFlagTable;
  764. }