cmGlobalVisualStudio7Generator.cxx 24 KB

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