cmGlobalVisualStudio7Generator.cxx 24 KB

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