cmGlobalVisualStudio7Generator.cxx 24 KB

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