cmGlobalVisualStudio7Generator.cxx 25 KB

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