cmGlobalVisualStudio7Generator.cxx 24 KB

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