cmGlobalVisualStudio7Generator.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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 "cmLocalVisualStudio7Generator.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmMakefile.h"
  18. #include "cmake.h"
  19. cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator()
  20. {
  21. this->FindMakeProgramFile = "CMakeVS7FindMake.cmake";
  22. }
  23. void cmGlobalVisualStudio7Generator::EnableLanguage(std::vector<std::string>const & lang,
  24. cmMakefile *mf)
  25. {
  26. mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
  27. mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
  28. mf->AddDefinition("CMAKE_GENERATOR_RC", "rc");
  29. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  30. mf->AddDefinition("CMAKE_GENERATOR_Fortran", "ifort");
  31. // Create list of configurations requested by user's cache, if any.
  32. this->cmGlobalGenerator::EnableLanguage(lang, mf);
  33. this->GenerateConfigurations(mf);
  34. }
  35. std::string cmGlobalVisualStudio7Generator::GenerateBuildCommand(const char* makeProgram,
  36. const char *projectName, const char* additionalOptions, const char *targetName,
  37. const char* config, bool ignoreErrors)
  38. {
  39. // Ingoring errors is not implemented in visual studio 6
  40. (void) ignoreErrors;
  41. // now build the test
  42. std::string makeCommand =
  43. cmSystemTools::ConvertToOutputPath(makeProgram);
  44. std::string lowerCaseCommand = makeCommand;
  45. cmSystemTools::LowerCase(lowerCaseCommand);
  46. // if there are spaces in the makeCommand, assume a full path
  47. // and convert it to a path with no spaces in it as the
  48. // RunSingleCommand does not like spaces
  49. #if defined(_WIN32) && !defined(__CYGWIN__)
  50. if(makeCommand.find(' ') != std::string::npos)
  51. {
  52. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  53. }
  54. #endif
  55. makeCommand += " ";
  56. makeCommand += projectName;
  57. makeCommand += ".sln ";
  58. bool clean = false;
  59. if ( targetName && strcmp(targetName, "clean") == 0 )
  60. {
  61. clean = true;
  62. targetName = "ALL_BUILD";
  63. }
  64. if(clean)
  65. {
  66. makeCommand += "/clean ";
  67. }
  68. else
  69. {
  70. makeCommand += "/build ";
  71. }
  72. if(config && strlen(config))
  73. {
  74. makeCommand += config;
  75. }
  76. else
  77. {
  78. makeCommand += "Debug";
  79. }
  80. makeCommand += " /project ";
  81. if (targetName && strlen(targetName))
  82. {
  83. makeCommand += targetName;
  84. }
  85. else
  86. {
  87. makeCommand += "ALL_BUILD";
  88. }
  89. if ( additionalOptions )
  90. {
  91. makeCommand += " ";
  92. makeCommand += additionalOptions;
  93. }
  94. return makeCommand;
  95. }
  96. ///! Create a local generator appropriate to this Global Generator
  97. cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator()
  98. {
  99. cmLocalGenerator *lg = new cmLocalVisualStudio7Generator;
  100. lg->SetGlobalGenerator(this);
  101. return lg;
  102. }
  103. void cmGlobalVisualStudio7Generator::GenerateConfigurations(cmMakefile* mf)
  104. {
  105. // process the configurations
  106. const char* ct
  107. = this->CMakeInstance->GetCacheDefinition("CMAKE_CONFIGURATION_TYPES");
  108. if ( ct )
  109. {
  110. std::string configTypes = ct;
  111. std::string::size_type start = 0;
  112. std::string::size_type endpos = 0;
  113. while(endpos != std::string::npos)
  114. {
  115. endpos = configTypes.find_first_of(" ;", start);
  116. std::string config;
  117. std::string::size_type len;
  118. if(endpos != std::string::npos)
  119. {
  120. len = endpos - start;
  121. }
  122. else
  123. {
  124. len = configTypes.size() - start;
  125. }
  126. config = configTypes.substr(start, len);
  127. if(config == "Debug" || config == "Release" ||
  128. config == "MinSizeRel" || config == "RelWithDebInfo")
  129. {
  130. // only add unique configurations
  131. if(std::find(this->Configurations.begin(),
  132. this->Configurations.end(), config) == this->Configurations.end())
  133. {
  134. this->Configurations.push_back(config);
  135. }
  136. }
  137. else
  138. {
  139. cmSystemTools::Error(
  140. "Invalid configuration type in CMAKE_CONFIGURATION_TYPES: ",
  141. config.c_str(),
  142. " (Valid types are Debug,Release,MinSizeRel,RelWithDebInfo)");
  143. }
  144. start = endpos+1;
  145. }
  146. }
  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. // add a special target that depends on ALL projects for easy build
  170. // of one configuration only.
  171. const char* no_output = 0;
  172. const char* no_working_dir = 0;
  173. std::vector<std::string> no_depends;
  174. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  175. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  176. {
  177. std::vector<cmLocalGenerator*>& gen = it->second;
  178. // add the ALL_BUILD to the first local generator of each project
  179. if(gen.size())
  180. {
  181. gen[0]->GetMakefile()->
  182. AddUtilityCommand("ALL_BUILD", false, no_output, no_depends,
  183. no_working_dir,
  184. "echo", "Build all projects");
  185. std::string cmake_command =
  186. this->LocalGenerators[0]->GetMakefile()->
  187. GetRequiredDefinition("CMAKE_COMMAND");
  188. }
  189. }
  190. // add the Run Tests command
  191. this->SetupTests();
  192. // first do the superclass method
  193. this->cmGlobalGenerator::Generate();
  194. // Now write out the DSW
  195. this->OutputSLNFile();
  196. }
  197. void cmGlobalVisualStudio7Generator::OutputSLNFile(cmLocalGenerator* root,
  198. std::vector<cmLocalGenerator*>& generators)
  199. {
  200. if(generators.size() == 0)
  201. {
  202. return;
  203. }
  204. this->CurrentProject = root->GetMakefile()->GetProjectName();
  205. std::string fname = root->GetMakefile()->GetStartOutputDirectory();
  206. fname += "/";
  207. fname += root->GetMakefile()->GetProjectName();
  208. fname += ".sln";
  209. cmGeneratedFileStream fout(fname.c_str());
  210. fout.SetCopyIfDifferent(true);
  211. if(!fout)
  212. {
  213. return;
  214. }
  215. this->WriteSLNFile(fout, root, generators);
  216. }
  217. // output the SLN file
  218. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  219. {
  220. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  221. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  222. {
  223. this->OutputSLNFile(it->second[0], it->second);
  224. }
  225. }
  226. // Write a SLN file to the stream
  227. void cmGlobalVisualStudio7Generator::WriteSLNFile(std::ostream& fout,
  228. cmLocalGenerator* root,
  229. std::vector<cmLocalGenerator*>& generators)
  230. {
  231. // Write out the header for a SLN file
  232. this->WriteSLNHeader(fout);
  233. // Get the start directory with the trailing slash
  234. std::string rootdir = root->GetMakefile()->GetStartOutputDirectory();
  235. rootdir += "/";
  236. bool doneAllBuild = false;
  237. bool doneRunTests = false;
  238. bool doneInstall = false;
  239. bool doneEditCache = false;
  240. bool doneRebuildCache = false;
  241. bool donePackage = false;
  242. // For each cmMakefile, create a VCProj for it, and
  243. // add it to this SLN file
  244. unsigned int i;
  245. for(i = 0; i < generators.size(); ++i)
  246. {
  247. if(this->IsExcluded(root, generators[i]))
  248. {
  249. continue;
  250. }
  251. cmMakefile* mf = generators[i]->GetMakefile();
  252. // Get the source directory from the makefile
  253. std::string dir = mf->GetStartOutputDirectory();
  254. // remove the home directory and / from the source directory
  255. // this gives a relative path
  256. cmSystemTools::ReplaceString(dir, rootdir.c_str(), "");
  257. // Get the list of create dsp files names from the cmVCProjWriter, more
  258. // than one dsp could have been created per input CMakeLists.txt file
  259. // for each target
  260. std::vector<std::string> dspnames =
  261. static_cast<cmLocalVisualStudio7Generator *>(generators[i])
  262. ->GetCreatedProjectNames();
  263. cmTargets &tgts = generators[i]->GetMakefile()->GetTargets();
  264. cmTargets::iterator l = tgts.begin();
  265. for(std::vector<std::string>::iterator si = dspnames.begin();
  266. l != tgts.end(); ++l)
  267. {
  268. // special handling for the current makefile
  269. if(mf == generators[0]->GetMakefile())
  270. {
  271. dir = "."; // no subdirectory for project generated
  272. // if this is the special ALL_BUILD utility, then
  273. // make it depend on every other non UTILITY project.
  274. // This is done by adding the names to the GetUtilities
  275. // vector on the makefile
  276. if(l->first == "ALL_BUILD" && !doneAllBuild)
  277. {
  278. unsigned int j;
  279. for(j = 0; j < generators.size(); ++j)
  280. {
  281. cmTargets &atgts = generators[j]->GetMakefile()->GetTargets();
  282. for(cmTargets::iterator al = atgts.begin();
  283. al != atgts.end(); ++al)
  284. {
  285. if (al->second.IsInAll())
  286. {
  287. if (al->second.GetType() == cmTarget::UTILITY ||
  288. al->second.GetType() == cmTarget::GLOBAL_TARGET)
  289. {
  290. l->second.AddUtility(al->first.c_str());
  291. }
  292. else
  293. {
  294. l->second.AddLinkLibrary(al->first,cmTarget::GENERAL);
  295. }
  296. }
  297. }
  298. }
  299. }
  300. }
  301. // Write the project into the SLN file
  302. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  303. {
  304. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  305. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  306. std::string project = cmds[0][0];
  307. std::string location = cmds[0][1];
  308. this->WriteExternalProject(fout, project.c_str(), location.c_str(), cc.GetDepends());
  309. }
  310. else
  311. {
  312. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  313. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  314. {
  315. bool skip = false;
  316. if(l->first == "ALL_BUILD" )
  317. {
  318. if(doneAllBuild)
  319. {
  320. skip = true;
  321. }
  322. else
  323. {
  324. doneAllBuild = true;
  325. }
  326. }
  327. if(l->first == "INSTALL")
  328. {
  329. if(doneInstall)
  330. {
  331. skip = true;
  332. }
  333. else
  334. {
  335. doneInstall = true;
  336. }
  337. }
  338. if(l->first == "RUN_TESTS")
  339. {
  340. if(doneRunTests)
  341. {
  342. skip = true;
  343. }
  344. else
  345. {
  346. doneRunTests = true;
  347. }
  348. }
  349. if(l->first == "EDIT_CACHE")
  350. {
  351. if(doneEditCache)
  352. {
  353. skip = true;
  354. }
  355. else
  356. {
  357. doneEditCache = true;
  358. }
  359. }
  360. if(l->first == "REBUILD_CACHE")
  361. {
  362. if(doneRebuildCache)
  363. {
  364. skip = true;
  365. }
  366. else
  367. {
  368. doneRebuildCache = true;
  369. }
  370. }
  371. if(l->first == "PACKAGE")
  372. {
  373. if(donePackage)
  374. {
  375. skip = true;
  376. }
  377. else
  378. {
  379. donePackage = true;
  380. }
  381. }
  382. if(!skip)
  383. {
  384. this->WriteProject(fout, si->c_str(), dir.c_str(),l->second);
  385. }
  386. ++si;
  387. }
  388. }
  389. }
  390. }
  391. fout << "Global\n"
  392. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  393. int c = 0;
  394. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  395. i != this->Configurations.end(); ++i)
  396. {
  397. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  398. c++;
  399. }
  400. fout << "\tEndGlobalSection\n"
  401. << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  402. // loop over again and compute the depends
  403. for(i = 0; i < generators.size(); ++i)
  404. {
  405. cmMakefile* mf = generators[i]->GetMakefile();
  406. cmLocalVisualStudio7Generator* pg =
  407. static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
  408. // Get the list of create dsp files names from the cmVCProjWriter, more
  409. // than one dsp could have been created per input CMakeLists.txt file
  410. // for each target
  411. std::vector<std::string> dspnames =
  412. pg->GetCreatedProjectNames();
  413. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  414. cmTargets::iterator l = tgts.begin();
  415. std::string dir = mf->GetStartDirectory();
  416. for(std::vector<std::string>::iterator si = dspnames.begin();
  417. l != tgts.end() && si != dspnames.end(); ++l)
  418. {
  419. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  420. {
  421. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  422. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  423. std::string name = cmds[0][0];
  424. std::vector<std::string> depends = cc.GetDepends();
  425. std::vector<std::string>::iterator iter;
  426. int depcount = 0;
  427. for(iter = depends.begin(); iter != depends.end(); ++iter)
  428. {
  429. std::string guid = this->GetGUID(iter->c_str());
  430. if(guid.size() == 0)
  431. {
  432. std::string m = "Target: ";
  433. m += l->first;
  434. m += " depends on unknown target: ";
  435. m += iter->c_str();
  436. cmSystemTools::Error(m.c_str());
  437. }
  438. fout << "\t\t{" << this->GetGUID(name.c_str()) << "}." << depcount << " = {"
  439. << guid.c_str() << "}\n";
  440. depcount++;
  441. }
  442. }
  443. else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  444. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  445. {
  446. this->WriteProjectDepends(fout, si->c_str(), dir.c_str(), l->second);
  447. ++si;
  448. }
  449. }
  450. }
  451. fout << "\tEndGlobalSection\n";
  452. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  453. // loop over again and compute the depends
  454. for(i = 0; i < generators.size(); ++i)
  455. {
  456. cmMakefile* mf = generators[i]->GetMakefile();
  457. cmLocalVisualStudio7Generator* pg =
  458. static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
  459. // Get the list of create dsp files names from the cmVCProjWriter, more
  460. // than one dsp could have been created per input CMakeLists.txt file
  461. // for each target
  462. std::vector<std::string> dspnames =
  463. pg->GetCreatedProjectNames();
  464. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  465. cmTargets::iterator l = tgts.begin();
  466. std::string dir = mf->GetStartDirectory();
  467. for(std::vector<std::string>::iterator si = dspnames.begin();
  468. l != tgts.end() && si != dspnames.end(); ++l)
  469. {
  470. if(strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  471. {
  472. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  473. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  474. std::string name = cmds[0][0];
  475. this->WriteProjectConfigurations(fout, name.c_str(), l->second.IsInAll());
  476. }
  477. else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  478. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  479. {
  480. this->WriteProjectConfigurations(fout, si->c_str(), l->second.IsInAll());
  481. ++si;
  482. }
  483. }
  484. }
  485. fout << "\tEndGlobalSection\n";
  486. // Write the footer for the SLN file
  487. this->WriteSLNFooter(fout);
  488. }
  489. // Write a dsp file into the SLN file,
  490. // Note, that dependencies from executables to
  491. // the libraries it uses are also done here
  492. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  493. const char* dspname,
  494. const char* dir, cmTarget&)
  495. {
  496. std::string d = cmSystemTools::ConvertToOutputPath(dir);
  497. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  498. << dspname << "\", \""
  499. << d << "\\" << dspname << ".vcproj\", \"{"
  500. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  501. }
  502. // Write a dsp file into the SLN file,
  503. // Note, that dependencies from executables to
  504. // the libraries it uses are also done here
  505. void
  506. cmGlobalVisualStudio7Generator
  507. ::WriteProjectDepends(std::ostream& fout,
  508. const char* dspname,
  509. const char*, cmTarget& target)
  510. {
  511. int depcount = 0;
  512. // insert Begin Project Dependency Project_Dep_Name project stuff here
  513. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  514. {
  515. cmTarget::LinkLibraryVectorType::const_iterator j, jend;
  516. j = target.GetLinkLibraries().begin();
  517. jend = target.GetLinkLibraries().end();
  518. for(;j!= jend; ++j)
  519. {
  520. if(j->first != dspname)
  521. {
  522. // is the library part of this SLN ? If so add dependency
  523. if(this->FindTarget(this->CurrentProject.c_str(), j->first.c_str()))
  524. {
  525. std::string guid = this->GetGUID(j->first.c_str());
  526. if(guid.size() == 0)
  527. {
  528. std::string m = "Target: ";
  529. m += dspname;
  530. m += " depends on unknown target: ";
  531. m += j->first.c_str();
  532. cmSystemTools::Error(m.c_str());
  533. }
  534. fout << "\t\t{" << this->GetGUID(dspname) << "}."
  535. << depcount << " = {" << guid << "}\n";
  536. depcount++;
  537. }
  538. }
  539. }
  540. }
  541. std::set<cmStdString>::const_iterator i, end;
  542. // write utility dependencies.
  543. i = target.GetUtilities().begin();
  544. end = target.GetUtilities().end();
  545. for(;i!= end; ++i)
  546. {
  547. if(*i != dspname)
  548. {
  549. std::string name = *i;
  550. if(strncmp(name.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  551. {
  552. // kind of weird removing the first 27 letters.
  553. // my recommendatsions:
  554. // use cmCustomCommand::GetCommand() to get the project name
  555. // or get rid of the target name starting with "INCLUDE_EXTERNAL_MSPROJECT_" and use another
  556. // indicator/flag somewhere. These external project names shouldn't conflict with cmake
  557. // target names anyways.
  558. name.erase(name.begin(), name.begin() + 27);
  559. }
  560. std::string guid = this->GetGUID(name.c_str());
  561. if(guid.size() == 0)
  562. {
  563. std::string m = "Target: ";
  564. m += dspname;
  565. m += " depends on unknown target: ";
  566. m += name.c_str();
  567. cmSystemTools::Error(m.c_str());
  568. }
  569. fout << "\t\t{" << this->GetGUID(dspname) << "}." << depcount << " = {"
  570. << guid << "}\n";
  571. depcount++;
  572. }
  573. }
  574. }
  575. // Write a dsp file into the SLN file,
  576. // Note, that dependencies from executables to
  577. // the libraries it uses are also done here
  578. void
  579. cmGlobalVisualStudio7Generator::WriteProjectConfigurations(std::ostream& fout,
  580. const char* name,
  581. bool in_all_build)
  582. {
  583. std::string guid = this->GetGUID(name);
  584. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  585. i != this->Configurations.end(); ++i)
  586. {
  587. fout << "\t\t{" << guid << "}." << *i << ".ActiveCfg = " << *i << "|Win32\n";
  588. if (in_all_build)
  589. {
  590. fout << "\t\t{" << guid << "}." << *i << ".Build.0 = " << *i << "|Win32\n";
  591. }
  592. }
  593. }
  594. // Write a dsp file into the SLN file,
  595. // Note, that dependencies from executables to
  596. // the libraries it uses are also done here
  597. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  598. const char* name,
  599. const char* location,
  600. const std::vector<std::string>&)
  601. {
  602. std::string d = cmSystemTools::ConvertToOutputPath(location);
  603. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  604. << name << "\", \""
  605. << d << "\", \"{"
  606. << this->GetGUID(name)
  607. << "}\"\n";
  608. fout << "EndProject\n";
  609. }
  610. // Standard end of dsw file
  611. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  612. {
  613. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  614. << "\tEndGlobalSection\n"
  615. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  616. << "\tEndGlobalSection\n"
  617. << "EndGlobal\n";
  618. }
  619. // ouput standard header for dsw file
  620. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  621. {
  622. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  623. }
  624. std::string cmGlobalVisualStudio7Generator::GetGUID(const char* name)
  625. {
  626. std::string guidStoreName = name;
  627. guidStoreName += "_GUID_CMAKE";
  628. const char* storedGUID = this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  629. if(storedGUID)
  630. {
  631. return std::string(storedGUID);
  632. }
  633. cmSystemTools::Error("Unknown Target referenced : ",
  634. name);
  635. return "";
  636. }
  637. void cmGlobalVisualStudio7Generator::CreateGUID(const char* name)
  638. {
  639. std::string guidStoreName = name;
  640. guidStoreName += "_GUID_CMAKE";
  641. if(this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  642. {
  643. return;
  644. }
  645. std::string ret;
  646. UUID uid;
  647. unsigned char *uidstr;
  648. UuidCreate(&uid);
  649. UuidToString(&uid,&uidstr);
  650. ret = reinterpret_cast<char*>(uidstr);
  651. RpcStringFree(&uidstr);
  652. ret = cmSystemTools::UpperCase(ret);
  653. this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(), ret.c_str(), "Stored GUID",
  654. cmCacheManager::INTERNAL);
  655. }
  656. std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
  657. {
  658. return &this->Configurations;
  659. };
  660. //----------------------------------------------------------------------------
  661. void cmGlobalVisualStudio7Generator::GetDocumentation(cmDocumentationEntry& entry) const
  662. {
  663. entry.name = this->GetName();
  664. entry.brief = "Generates Visual Studio .NET 2002 project files.";
  665. entry.full = "";
  666. }
  667. // make sure "special" targets have GUID's
  668. void cmGlobalVisualStudio7Generator::Configure()
  669. {
  670. cmGlobalGenerator::Configure();
  671. this->CreateGUID("ALL_BUILD");
  672. this->CreateGUID("INSTALL");
  673. this->CreateGUID("RUN_TESTS");
  674. this->CreateGUID("EDIT_CACHE");
  675. this->CreateGUID("REBUILD_CACHE");
  676. this->CreateGUID("PACKAGE");
  677. }
  678. //----------------------------------------------------------------------------
  679. void
  680. cmGlobalVisualStudio7Generator
  681. ::AppendDirectoryForConfig(const char* prefix,
  682. const char* config,
  683. const char* suffix,
  684. std::string& dir)
  685. {
  686. if(config)
  687. {
  688. dir += prefix;
  689. dir += config;
  690. dir += suffix;
  691. }
  692. }