cmGlobalVisualStudio7Generator.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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_ProjectMap.begin(); it!= m_ProjectMap.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. // add a special target that depends on ALL projects for easy build
  228. // of Debug only
  229. std::vector<std::string> srcs;
  230. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  231. for(it = m_ProjectMap.begin(); it!= m_ProjectMap.end(); ++it)
  232. {
  233. std::vector<cmLocalGenerator*>& gen = it->second;
  234. // add the ALL_BUILD to the first local generator of each project
  235. if(gen.size())
  236. {
  237. gen[0]->GetMakefile()->
  238. AddUtilityCommand("ALL_BUILD", "echo","\"Build all projects\"",false,srcs);
  239. std::string cmake_command =
  240. m_LocalGenerators[0]->GetMakefile()->GetRequiredDefinition("CMAKE_COMMAND");
  241. gen[0]->GetMakefile()->
  242. AddUtilityCommand("INSTALL", cmake_command.c_str(),
  243. "-DBUILD_TYPE=$(IntDir) -P cmake_install.cmake",false,srcs);
  244. }
  245. }
  246. // add the Run Tests command
  247. this->SetupTests();
  248. // first do the superclass method
  249. this->cmGlobalGenerator::Generate();
  250. // Now write out the DSW
  251. this->OutputSLNFile();
  252. }
  253. void cmGlobalVisualStudio7Generator::OutputSLNFile(cmLocalGenerator* root,
  254. std::vector<cmLocalGenerator*>& generators)
  255. {
  256. if(generators.size() == 0)
  257. {
  258. return;
  259. }
  260. std::string fname = root->GetMakefile()->GetStartOutputDirectory();
  261. fname += "/";
  262. fname += root->GetMakefile()->GetProjectName();
  263. fname += ".sln";
  264. cmGeneratedFileStream fout(fname.c_str());
  265. fout.SetCopyIfDifferent(true);
  266. if(!fout)
  267. {
  268. return;
  269. }
  270. this->WriteSLNFile(fout, root, generators);
  271. }
  272. // output the SLN file
  273. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  274. {
  275. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  276. for(it = m_ProjectMap.begin(); it!= m_ProjectMap.end(); ++it)
  277. {
  278. this->OutputSLNFile(it->second[0], it->second);
  279. }
  280. }
  281. // Write a SLN file to the stream
  282. void cmGlobalVisualStudio7Generator::WriteSLNFile(std::ostream& fout,
  283. cmLocalGenerator* root,
  284. std::vector<cmLocalGenerator*>& generators)
  285. {
  286. // Write out the header for a SLN file
  287. this->WriteSLNHeader(fout);
  288. // Get the home directory with the trailing slash
  289. std::string homedir = root->GetMakefile()->GetCurrentDirectory();
  290. homedir += "/";
  291. bool doneAllBuild = false;
  292. bool doneRunTests = false;
  293. bool doneInstall = false;
  294. // For each cmMakefile, create a VCProj for it, and
  295. // add it to this SLN file
  296. unsigned int i;
  297. for(i = 0; i < generators.size(); ++i)
  298. {
  299. if(this->IsExcluded(root, generators[i]))
  300. {
  301. continue;
  302. }
  303. cmMakefile* mf = generators[i]->GetMakefile();
  304. // Get the source directory from the makefile
  305. std::string dir = mf->GetStartDirectory();
  306. // remove the home directory and / from the source directory
  307. // this gives a relative path
  308. cmSystemTools::ReplaceString(dir, homedir.c_str(), "");
  309. // Get the list of create dsp files names from the cmVCProjWriter, more
  310. // than one dsp could have been created per input CMakeLists.txt file
  311. // for each target
  312. std::vector<std::string> dspnames =
  313. static_cast<cmLocalVisualStudio7Generator *>(generators[i])
  314. ->GetCreatedProjectNames();
  315. cmTargets &tgts = generators[i]->GetMakefile()->GetTargets();
  316. cmTargets::iterator l = tgts.begin();
  317. for(std::vector<std::string>::iterator si = dspnames.begin();
  318. l != tgts.end(); ++l)
  319. {
  320. // special handling for the current makefile
  321. if(mf == generators[0]->GetMakefile())
  322. {
  323. dir = "."; // no subdirectory for project generated
  324. // if this is the special ALL_BUILD utility, then
  325. // make it depend on every other non UTILITY project.
  326. // This is done by adding the names to the GetUtilities
  327. // vector on the makefile
  328. if(l->first == "ALL_BUILD" && !doneAllBuild)
  329. {
  330. unsigned int j;
  331. for(j = 0; j < generators.size(); ++j)
  332. {
  333. const cmTargets &atgts =
  334. generators[j]->GetMakefile()->GetTargets();
  335. for(cmTargets::const_iterator al = atgts.begin();
  336. al != atgts.end(); ++al)
  337. {
  338. if (al->second.IsInAll())
  339. {
  340. if (al->second.GetType() == cmTarget::UTILITY)
  341. {
  342. l->second.AddUtility(al->first.c_str());
  343. }
  344. else
  345. {
  346. l->second.AddLinkLibrary(al->first,cmTarget::GENERAL);
  347. }
  348. }
  349. }
  350. }
  351. }
  352. }
  353. // Write the project into the SLN file
  354. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  355. {
  356. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  357. std::string project_name = cc.GetCommand();
  358. std::string location = cc.GetArguments();
  359. this->WriteExternalProject(fout, project_name.c_str(),
  360. location.c_str(), cc.GetDepends());
  361. }
  362. else
  363. {
  364. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  365. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  366. {
  367. bool skip = false;
  368. if(l->first == "ALL_BUILD" )
  369. {
  370. if(doneAllBuild)
  371. {
  372. skip = true;
  373. }
  374. else
  375. {
  376. doneAllBuild = true;
  377. }
  378. }
  379. if(l->first == "INSTALL")
  380. {
  381. if(doneInstall)
  382. {
  383. skip = true;
  384. }
  385. else
  386. {
  387. doneInstall = true;
  388. }
  389. }
  390. if(l->first == "RUN_TESTS")
  391. {
  392. if(doneRunTests)
  393. {
  394. skip = true;
  395. }
  396. else
  397. {
  398. doneRunTests = 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 = m_Configurations.begin();
  414. i != m_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. std::string name = cc.GetCommand();
  442. std::vector<std::string> depends = cc.GetDepends();
  443. std::vector<std::string>::iterator iter;
  444. int depcount = 0;
  445. for(iter = depends.begin(); iter != depends.end(); ++iter)
  446. {
  447. fout << "\t\t{" << this->GetGUID(name.c_str()) << "}." << depcount << " = {"
  448. << this->GetGUID(iter->c_str()) << "}\n";
  449. depcount++;
  450. }
  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(strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  480. {
  481. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  482. std::string name = cc.GetCommand();
  483. this->WriteProjectConfigurations(fout, name.c_str(), l->second.IsInAll());
  484. }
  485. else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  486. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  487. {
  488. this->WriteProjectConfigurations(fout, si->c_str(), l->second.IsInAll());
  489. ++si;
  490. }
  491. }
  492. }
  493. fout << "\tEndGlobalSection\n";
  494. // Write the footer for the SLN file
  495. this->WriteSLNFooter(fout);
  496. }
  497. // Write a dsp file into the SLN file,
  498. // Note, that dependencies from executables to
  499. // the libraries it uses are also done here
  500. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  501. const char* dspname,
  502. const char* dir,
  503. const cmTarget&)
  504. {
  505. std::string d = cmSystemTools::ConvertToOutputPath(dir);
  506. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  507. << dspname << "\", \""
  508. << d << "\\" << dspname << ".vcproj\", \"{"
  509. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  510. }
  511. // Write a dsp file into the SLN file,
  512. // Note, that dependencies from executables to
  513. // the libraries it uses are also done here
  514. void cmGlobalVisualStudio7Generator::WriteProjectDepends(std::ostream& fout,
  515. const char* dspname,
  516. const char* ,
  517. const cmTarget& target
  518. )
  519. {
  520. int depcount = 0;
  521. // insert Begin Project Dependency Project_Dep_Name project stuff here
  522. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  523. {
  524. cmTarget::LinkLibraries::const_iterator j, jend;
  525. j = target.GetLinkLibraries().begin();
  526. jend = target.GetLinkLibraries().end();
  527. for(;j!= jend; ++j)
  528. {
  529. if(j->first != dspname)
  530. {
  531. // is the library part of this SLN ? If so add dependency
  532. std::string libPath = j->first + "_CMAKE_PATH";
  533. const char* cacheValue
  534. = m_CMakeInstance->GetCacheDefinition(libPath.c_str());
  535. if(cacheValue && *cacheValue)
  536. {
  537. fout << "\t\t{" << this->GetGUID(dspname) << "}." << depcount << " = {"
  538. << this->GetGUID(j->first.c_str()) << "}\n";
  539. depcount++;
  540. }
  541. }
  542. }
  543. }
  544. std::set<cmStdString>::const_iterator i, end;
  545. // write utility dependencies.
  546. i = target.GetUtilities().begin();
  547. end = target.GetUtilities().end();
  548. for(;i!= end; ++i)
  549. {
  550. if(*i != dspname)
  551. {
  552. std::string name = *i;
  553. if(strncmp(name.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  554. {
  555. // kind of weird removing the first 27 letters.
  556. // my recommendatsions:
  557. // use cmCustomCommand::GetCommand() to get the project name
  558. // or get rid of the target name starting with "INCLUDE_EXTERNAL_MSPROJECT_" and use another
  559. // indicator/flag somewhere. These external project names shouldn't conflict with cmake
  560. // target names anyways.
  561. name.erase(name.begin(), name.begin() + 27);
  562. }
  563. fout << "\t\t{" << this->GetGUID(dspname) << "}." << depcount << " = {"
  564. << this->GetGUID(name.c_str()) << "}\n";
  565. depcount++;
  566. }
  567. }
  568. }
  569. // Write a dsp file into the SLN file,
  570. // Note, that dependencies from executables to
  571. // the libraries it uses are also done here
  572. void
  573. cmGlobalVisualStudio7Generator::WriteProjectConfigurations(std::ostream& fout,
  574. const char* name,
  575. bool in_all_build)
  576. {
  577. std::string guid = this->GetGUID(name);
  578. for(std::vector<std::string>::iterator i = m_Configurations.begin();
  579. i != m_Configurations.end(); ++i)
  580. {
  581. fout << "\t\t{" << guid << "}." << *i << ".ActiveCfg = " << *i << "|Win32\n";
  582. if (in_all_build)
  583. {
  584. fout << "\t\t{" << guid << "}." << *i << ".Build.0 = " << *i << "|Win32\n";
  585. }
  586. }
  587. }
  588. // Write a dsp file into the SLN file,
  589. // Note, that dependencies from executables to
  590. // the libraries it uses are also done here
  591. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  592. const char* name,
  593. const char* location,
  594. const std::vector<std::string>&)
  595. {
  596. std::string d = cmSystemTools::ConvertToOutputPath(location);
  597. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  598. << name << "\", \""
  599. << d << "\", \"{"
  600. << this->GetGUID(name)
  601. << "}\"\n";
  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. // make sure "special" targets have GUID's
  666. void cmGlobalVisualStudio7Generator::Configure()
  667. {
  668. cmGlobalGenerator::Configure();
  669. this->CreateGUID("ALL_BUILD");
  670. this->CreateGUID("INSTALL");
  671. this->CreateGUID("RUN_TESTS");
  672. }