cmGlobalVisualStudio7Generator.cxx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  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. true);
  503. }
  504. else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  505. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  506. {
  507. bool partOfDefaultBuild = this->IsPartOfDefaultBuild(
  508. root->GetMakefile()->GetProjectName(),
  509. &l->second);
  510. this->WriteProjectConfigurations(fout, si->c_str(),
  511. partOfDefaultBuild);
  512. ++si;
  513. }
  514. }
  515. }
  516. fout << "\tEndGlobalSection\n";
  517. // Write the footer for the SLN file
  518. this->WriteSLNFooter(fout);
  519. }
  520. //----------------------------------------------------------------------------
  521. std::string
  522. cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
  523. {
  524. // Convert to backslashes. Do not use ConvertToOutputPath because
  525. // we will add quoting ourselves, and we know these projects always
  526. // use windows slashes.
  527. std::string d = path;
  528. std::string::size_type pos = 0;
  529. while((pos = d.find('/', pos)) != d.npos)
  530. {
  531. d[pos++] = '\\';
  532. }
  533. return d;
  534. }
  535. // Write a dsp file into the SLN file,
  536. // Note, that dependencies from executables to
  537. // the libraries it uses are also done here
  538. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  539. const char* dspname,
  540. const char* dir, cmTarget&)
  541. {
  542. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  543. << dspname << "\", \""
  544. << this->ConvertToSolutionPath(dir)
  545. << "\\" << dspname << ".vcproj\", \"{"
  546. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  547. }
  548. // Write a dsp file into the SLN file,
  549. // Note, that dependencies from executables to
  550. // the libraries it uses are also done here
  551. void
  552. cmGlobalVisualStudio7Generator
  553. ::WriteProjectDepends(std::ostream& fout,
  554. const char* dspname,
  555. const char*, cmTarget& target)
  556. {
  557. int depcount = 0;
  558. // insert Begin Project Dependency Project_Dep_Name project stuff here
  559. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  560. {
  561. cmTarget::LinkLibraryVectorType::const_iterator j, jend;
  562. j = target.GetLinkLibraries().begin();
  563. jend = target.GetLinkLibraries().end();
  564. for(;j!= jend; ++j)
  565. {
  566. if(j->first != dspname)
  567. {
  568. // is the library part of this SLN ? If so add dependency
  569. if(this->FindTarget(this->CurrentProject.c_str(), j->first.c_str()))
  570. {
  571. std::string guid = this->GetGUID(j->first.c_str());
  572. if(guid.size() == 0)
  573. {
  574. std::string m = "Target: ";
  575. m += dspname;
  576. m += " depends on unknown target: ";
  577. m += j->first.c_str();
  578. cmSystemTools::Error(m.c_str());
  579. }
  580. fout << "\t\t{" << this->GetGUID(dspname) << "}."
  581. << depcount << " = {" << guid << "}\n";
  582. depcount++;
  583. }
  584. }
  585. }
  586. }
  587. std::set<cmStdString>::const_iterator i, end;
  588. // write utility dependencies.
  589. i = target.GetUtilities().begin();
  590. end = target.GetUtilities().end();
  591. for(;i!= end; ++i)
  592. {
  593. if(*i != dspname)
  594. {
  595. std::string name = *i;
  596. if(strncmp(name.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  597. {
  598. // kind of weird removing the first 27 letters. my
  599. // recommendatsions: use cmCustomCommand::GetCommand() to get the
  600. // project name or get rid of the target name starting with
  601. // "INCLUDE_EXTERNAL_MSPROJECT_" and use another indicator/flag
  602. // somewhere. These external project names shouldn't conflict
  603. // with cmake target names anyways.
  604. name.erase(name.begin(), name.begin() + 27);
  605. }
  606. std::string guid = this->GetGUID(name.c_str());
  607. if(guid.size() == 0)
  608. {
  609. std::string m = "Target: ";
  610. m += dspname;
  611. m += " depends on unknown target: ";
  612. m += name.c_str();
  613. cmSystemTools::Error(m.c_str());
  614. }
  615. fout << "\t\t{" << this->GetGUID(dspname) << "}." << depcount << " = {"
  616. << guid << "}\n";
  617. depcount++;
  618. }
  619. }
  620. }
  621. // Write a dsp file into the SLN file, Note, that dependencies from
  622. // executables to the libraries it uses are also done here
  623. void cmGlobalVisualStudio7Generator
  624. ::WriteProjectConfigurations(std::ostream& fout, const char* name,
  625. bool partOfDefaultBuild)
  626. {
  627. std::string guid = this->GetGUID(name);
  628. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  629. i != this->Configurations.end(); ++i)
  630. {
  631. fout << "\t\t{" << guid << "}." << *i
  632. << ".ActiveCfg = " << *i << "|Win32\n";
  633. if(partOfDefaultBuild)
  634. {
  635. fout << "\t\t{" << guid << "}." << *i
  636. << ".Build.0 = " << *i << "|Win32\n";
  637. }
  638. }
  639. }
  640. // Write a dsp file into the SLN file,
  641. // Note, that dependencies from executables to
  642. // the libraries it uses are also done here
  643. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  644. const char* name,
  645. const char* location,
  646. const std::vector<std::string>&)
  647. {
  648. std::string d = cmSystemTools::ConvertToOutputPath(location);
  649. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  650. << name << "\", \""
  651. << this->ConvertToSolutionPath(location) << "\", \"{"
  652. << this->GetGUID(name)
  653. << "}\"\n";
  654. fout << "EndProject\n";
  655. }
  656. // Standard end of dsw file
  657. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  658. {
  659. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  660. << "\tEndGlobalSection\n"
  661. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  662. << "\tEndGlobalSection\n"
  663. << "EndGlobal\n";
  664. }
  665. // ouput standard header for dsw file
  666. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  667. {
  668. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  669. }
  670. std::string cmGlobalVisualStudio7Generator::GetGUID(const char* name)
  671. {
  672. std::string guidStoreName = name;
  673. guidStoreName += "_GUID_CMAKE";
  674. const char* storedGUID =
  675. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  676. if(storedGUID)
  677. {
  678. return std::string(storedGUID);
  679. }
  680. cmSystemTools::Error("Unknown Target referenced : ",
  681. name);
  682. return "";
  683. }
  684. void cmGlobalVisualStudio7Generator::CreateGUID(const char* name)
  685. {
  686. std::string guidStoreName = name;
  687. guidStoreName += "_GUID_CMAKE";
  688. if(this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  689. {
  690. return;
  691. }
  692. std::string ret;
  693. UUID uid;
  694. unsigned char *uidstr;
  695. UuidCreate(&uid);
  696. UuidToString(&uid,&uidstr);
  697. ret = reinterpret_cast<char*>(uidstr);
  698. RpcStringFree(&uidstr);
  699. ret = cmSystemTools::UpperCase(ret);
  700. this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
  701. ret.c_str(), "Stored GUID",
  702. cmCacheManager::INTERNAL);
  703. }
  704. std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
  705. {
  706. return &this->Configurations;
  707. };
  708. //----------------------------------------------------------------------------
  709. void cmGlobalVisualStudio7Generator
  710. ::GetDocumentation(cmDocumentationEntry& entry) const
  711. {
  712. entry.name = this->GetName();
  713. entry.brief = "Generates Visual Studio .NET 2002 project files.";
  714. entry.full = "";
  715. }
  716. // make sure "special" targets have GUID's
  717. void cmGlobalVisualStudio7Generator::Configure()
  718. {
  719. cmGlobalGenerator::Configure();
  720. this->CreateGUID("ALL_BUILD");
  721. this->CreateGUID("INSTALL");
  722. this->CreateGUID("RUN_TESTS");
  723. this->CreateGUID("EDIT_CACHE");
  724. this->CreateGUID("REBUILD_CACHE");
  725. this->CreateGUID("PACKAGE");
  726. }
  727. //----------------------------------------------------------------------------
  728. void
  729. cmGlobalVisualStudio7Generator
  730. ::AppendDirectoryForConfig(const char* prefix,
  731. const char* config,
  732. const char* suffix,
  733. std::string& dir)
  734. {
  735. if(config)
  736. {
  737. dir += prefix;
  738. dir += config;
  739. dir += suffix;
  740. }
  741. }
  742. bool cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(const char* project,
  743. cmTarget* target)
  744. {
  745. if(target->GetPropertyAsBool("EXCLUDE_FROM_DEFAULT_BUILD"))
  746. {
  747. return false;
  748. }
  749. // if it is a utilitiy target then only make it part of the
  750. // default build if another target depends on it
  751. int type = target->GetType();
  752. if (type == cmTarget::GLOBAL_TARGET)
  753. {
  754. return false;
  755. }
  756. if(type == cmTarget::UTILITY)
  757. {
  758. return this->IsDependedOn(project, target);
  759. }
  760. // default is to be part of the build
  761. return true;
  762. }