cmGlobalVisualStudio7Generator.cxx 25 KB

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