cmGlobalVisualStudio7Generator.cxx 24 KB

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