cmGlobalVisualStudio7Generator.cxx 24 KB

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