cmGlobalVisualStudio7Generator.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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. fout.SetCopyIfDifferent(true);
  268. if(!fout)
  269. {
  270. return;
  271. }
  272. this->WriteSLNFile(fout, root, generators);
  273. }
  274. // output the SLN file
  275. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  276. {
  277. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  278. for(it = m_SubProjectMap.begin(); it!= m_SubProjectMap.end(); ++it)
  279. {
  280. this->OutputSLNFile(it->second[0], it->second);
  281. }
  282. }
  283. // Write a SLN file to the stream
  284. void cmGlobalVisualStudio7Generator::WriteSLNFile(std::ostream& fout,
  285. cmLocalGenerator* root,
  286. std::vector<cmLocalGenerator*>& generators)
  287. {
  288. // Write out the header for a SLN file
  289. this->WriteSLNHeader(fout);
  290. // Get the home directory with the trailing slash
  291. std::string homedir = root->GetMakefile()->GetCurrentDirectory();
  292. homedir += "/";
  293. bool doneAllBuild = false;
  294. bool doneRunTests = false;
  295. bool doneInstall = false;
  296. // For each cmMakefile, create a VCProj for it, and
  297. // add it to this SLN file
  298. unsigned int i;
  299. for(i = 0; i < generators.size(); ++i)
  300. {
  301. if(this->IsExcluded(root, generators[i]))
  302. {
  303. continue;
  304. }
  305. cmMakefile* mf = generators[i]->GetMakefile();
  306. // Get the source directory from the makefile
  307. std::string dir = mf->GetStartDirectory();
  308. // remove the home directory and / from the source directory
  309. // this gives a relative path
  310. cmSystemTools::ReplaceString(dir, homedir.c_str(), "");
  311. // Get the list of create dsp files names from the cmVCProjWriter, more
  312. // than one dsp could have been created per input CMakeLists.txt file
  313. // for each target
  314. std::vector<std::string> dspnames =
  315. static_cast<cmLocalVisualStudio7Generator *>(generators[i])
  316. ->GetCreatedProjectNames();
  317. cmTargets &tgts = generators[i]->GetMakefile()->GetTargets();
  318. cmTargets::iterator l = tgts.begin();
  319. for(std::vector<std::string>::iterator si = dspnames.begin();
  320. l != tgts.end(); ++l)
  321. {
  322. // special handling for the current makefile
  323. if(mf == generators[0]->GetMakefile())
  324. {
  325. dir = "."; // no subdirectory for project generated
  326. // if this is the special ALL_BUILD utility, then
  327. // make it depend on every other non UTILITY project.
  328. // This is done by adding the names to the GetUtilities
  329. // vector on the makefile
  330. if(l->first == "ALL_BUILD" && !doneAllBuild)
  331. {
  332. unsigned int j;
  333. for(j = 0; j < generators.size(); ++j)
  334. {
  335. const cmTargets &atgts =
  336. generators[j]->GetMakefile()->GetTargets();
  337. for(cmTargets::const_iterator al = atgts.begin();
  338. al != atgts.end(); ++al)
  339. {
  340. if (al->second.IsInAll())
  341. {
  342. if (al->second.GetType() == cmTarget::UTILITY)
  343. {
  344. l->second.AddUtility(al->first.c_str());
  345. }
  346. else
  347. {
  348. l->second.AddLinkLibrary(al->first,cmTarget::GENERAL);
  349. }
  350. }
  351. }
  352. }
  353. }
  354. }
  355. // Write the project into the SLN file
  356. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  357. {
  358. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  359. std::string project_name = cc.GetCommand();
  360. std::string location = cc.GetArguments();
  361. this->WriteExternalProject(fout, project_name.c_str(),
  362. location.c_str(), cc.GetDepends());
  363. }
  364. else
  365. {
  366. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  367. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  368. {
  369. bool skip = false;
  370. if(l->first == "ALL_BUILD" )
  371. {
  372. if(doneAllBuild)
  373. {
  374. skip = true;
  375. }
  376. else
  377. {
  378. doneAllBuild = true;
  379. }
  380. }
  381. if(l->first == "INSTALL")
  382. {
  383. if(doneInstall)
  384. {
  385. skip = true;
  386. }
  387. else
  388. {
  389. doneInstall = true;
  390. }
  391. }
  392. if(l->first == "RUN_TESTS")
  393. {
  394. if(doneRunTests)
  395. {
  396. skip = true;
  397. }
  398. else
  399. {
  400. doneRunTests = true;
  401. }
  402. }
  403. if(!skip)
  404. {
  405. this->WriteProject(fout, si->c_str(), dir.c_str(),l->second);
  406. }
  407. ++si;
  408. }
  409. }
  410. }
  411. }
  412. fout << "Global\n"
  413. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  414. int c = 0;
  415. for(std::vector<std::string>::iterator i = m_Configurations.begin();
  416. i != m_Configurations.end(); ++i)
  417. {
  418. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  419. c++;
  420. }
  421. fout << "\tEndGlobalSection\n"
  422. << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  423. // loop over again and compute the depends
  424. for(i = 0; i < generators.size(); ++i)
  425. {
  426. cmMakefile* mf = generators[i]->GetMakefile();
  427. cmLocalVisualStudio7Generator* pg =
  428. static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
  429. // Get the list of create dsp files names from the cmVCProjWriter, more
  430. // than one dsp could have been created per input CMakeLists.txt file
  431. // for each target
  432. std::vector<std::string> dspnames =
  433. pg->GetCreatedProjectNames();
  434. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  435. cmTargets::iterator l = tgts.begin();
  436. std::string dir = mf->GetStartDirectory();
  437. for(std::vector<std::string>::iterator si = dspnames.begin();
  438. l != tgts.end() && si != dspnames.end(); ++l)
  439. {
  440. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  441. {
  442. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  443. std::string name = cc.GetCommand();
  444. std::vector<std::string> depends = cc.GetDepends();
  445. std::vector<std::string>::iterator iter;
  446. int depcount = 0;
  447. for(iter = depends.begin(); iter != depends.end(); ++iter)
  448. {
  449. fout << "\t\t{" << this->GetGUID(name.c_str()) << "}." << depcount << " = {"
  450. << this->GetGUID(iter->c_str()) << "}\n";
  451. depcount++;
  452. }
  453. }
  454. else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  455. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  456. {
  457. this->WriteProjectDepends(fout, si->c_str(), dir.c_str(),l->second);
  458. ++si;
  459. }
  460. }
  461. }
  462. fout << "\tEndGlobalSection\n";
  463. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  464. // loop over again and compute the depends
  465. for(i = 0; i < generators.size(); ++i)
  466. {
  467. cmMakefile* mf = generators[i]->GetMakefile();
  468. cmLocalVisualStudio7Generator* pg =
  469. static_cast<cmLocalVisualStudio7Generator*>(generators[i]);
  470. // Get the list of create dsp files names from the cmVCProjWriter, more
  471. // than one dsp could have been created per input CMakeLists.txt file
  472. // for each target
  473. std::vector<std::string> dspnames =
  474. pg->GetCreatedProjectNames();
  475. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  476. cmTargets::iterator l = tgts.begin();
  477. std::string dir = mf->GetStartDirectory();
  478. for(std::vector<std::string>::iterator si = dspnames.begin();
  479. l != tgts.end() && si != dspnames.end(); ++l)
  480. {
  481. if(strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  482. {
  483. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  484. std::string name = cc.GetCommand();
  485. this->WriteProjectConfigurations(fout, name.c_str(), l->second.IsInAll());
  486. }
  487. else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  488. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  489. {
  490. this->WriteProjectConfigurations(fout, si->c_str(), l->second.IsInAll());
  491. ++si;
  492. }
  493. }
  494. }
  495. fout << "\tEndGlobalSection\n";
  496. // Write the footer for the SLN file
  497. this->WriteSLNFooter(fout);
  498. }
  499. // Write a dsp file into the SLN file,
  500. // Note, that dependencies from executables to
  501. // the libraries it uses are also done here
  502. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  503. const char* dspname,
  504. const char* dir,
  505. const cmTarget&)
  506. {
  507. std::string d = cmSystemTools::ConvertToOutputPath(dir);
  508. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  509. << dspname << "\", \""
  510. << d << "\\" << dspname << ".vcproj\", \"{"
  511. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  512. }
  513. // Write a dsp file into the SLN file,
  514. // Note, that dependencies from executables to
  515. // the libraries it uses are also done here
  516. void cmGlobalVisualStudio7Generator::WriteProjectDepends(std::ostream& fout,
  517. const char* dspname,
  518. const char* ,
  519. const cmTarget& target
  520. )
  521. {
  522. int depcount = 0;
  523. // insert Begin Project Dependency Project_Dep_Name project stuff here
  524. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  525. {
  526. cmTarget::LinkLibraries::const_iterator j, jend;
  527. j = target.GetLinkLibraries().begin();
  528. jend = target.GetLinkLibraries().end();
  529. for(;j!= jend; ++j)
  530. {
  531. if(j->first != dspname)
  532. {
  533. // is the library part of this SLN ? If so add dependency
  534. std::string libPath = j->first + "_CMAKE_PATH";
  535. const char* cacheValue
  536. = m_CMakeInstance->GetCacheDefinition(libPath.c_str());
  537. if(cacheValue && *cacheValue)
  538. {
  539. fout << "\t\t{" << this->GetGUID(dspname) << "}." << depcount << " = {"
  540. << this->GetGUID(j->first.c_str()) << "}\n";
  541. depcount++;
  542. }
  543. }
  544. }
  545. }
  546. std::set<cmStdString>::const_iterator i, end;
  547. // write utility dependencies.
  548. i = target.GetUtilities().begin();
  549. end = target.GetUtilities().end();
  550. for(;i!= end; ++i)
  551. {
  552. if(*i != dspname)
  553. {
  554. std::string name = *i;
  555. if(strncmp(name.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  556. {
  557. // kind of weird removing the first 27 letters.
  558. // my recommendatsions:
  559. // use cmCustomCommand::GetCommand() to get the project name
  560. // or get rid of the target name starting with "INCLUDE_EXTERNAL_MSPROJECT_" and use another
  561. // indicator/flag somewhere. These external project names shouldn't conflict with cmake
  562. // target names anyways.
  563. name.erase(name.begin(), name.begin() + 27);
  564. }
  565. fout << "\t\t{" << this->GetGUID(dspname) << "}." << depcount << " = {"
  566. << this->GetGUID(name.c_str()) << "}\n";
  567. depcount++;
  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
  575. cmGlobalVisualStudio7Generator::WriteProjectConfigurations(std::ostream& fout,
  576. const char* name,
  577. bool in_all_build)
  578. {
  579. std::string guid = this->GetGUID(name);
  580. for(std::vector<std::string>::iterator i = m_Configurations.begin();
  581. i != m_Configurations.end(); ++i)
  582. {
  583. fout << "\t\t{" << guid << "}." << *i << ".ActiveCfg = " << *i << "|Win32\n";
  584. if (in_all_build)
  585. {
  586. fout << "\t\t{" << guid << "}." << *i << ".Build.0 = " << *i << "|Win32\n";
  587. }
  588. }
  589. }
  590. // Write a dsp file into the SLN file,
  591. // Note, that dependencies from executables to
  592. // the libraries it uses are also done here
  593. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  594. const char* name,
  595. const char* location,
  596. const std::vector<std::string>&)
  597. {
  598. std::string d = cmSystemTools::ConvertToOutputPath(location);
  599. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  600. << name << "\", \""
  601. << d << "\", \"{"
  602. << this->GetGUID(name)
  603. << "}\"\n";
  604. fout << "EndProject\n";
  605. }
  606. // Standard end of dsw file
  607. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  608. {
  609. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  610. << "\tEndGlobalSection\n"
  611. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  612. << "\tEndGlobalSection\n"
  613. << "EndGlobal\n";
  614. }
  615. // ouput standard header for dsw file
  616. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  617. {
  618. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  619. }
  620. std::string cmGlobalVisualStudio7Generator::GetGUID(const char* name)
  621. {
  622. std::string guidStoreName = name;
  623. guidStoreName += "_GUID_CMAKE";
  624. const char* storedGUID = m_CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  625. if(storedGUID)
  626. {
  627. return std::string(storedGUID);
  628. }
  629. cmSystemTools::Error("Internal CMake Error, Could not find GUID for target: ",
  630. name);
  631. return guidStoreName;
  632. }
  633. void cmGlobalVisualStudio7Generator::CreateGUID(const char* name)
  634. {
  635. std::string guidStoreName = name;
  636. guidStoreName += "_GUID_CMAKE";
  637. if(m_CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  638. {
  639. return;
  640. }
  641. std::string ret;
  642. UUID uid;
  643. unsigned char *uidstr;
  644. UuidCreate(&uid);
  645. UuidToString(&uid,&uidstr);
  646. ret = reinterpret_cast<char*>(uidstr);
  647. RpcStringFree(&uidstr);
  648. ret = cmSystemTools::UpperCase(ret);
  649. m_CMakeInstance->AddCacheEntry(guidStoreName.c_str(), ret.c_str(), "Stored GUID",
  650. cmCacheManager::INTERNAL);
  651. }
  652. void cmGlobalVisualStudio7Generator::LocalGenerate()
  653. {
  654. this->cmGlobalGenerator::LocalGenerate();
  655. }
  656. std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
  657. {
  658. return &m_Configurations;
  659. };
  660. //----------------------------------------------------------------------------
  661. void cmGlobalVisualStudio7Generator::GetDocumentation(cmDocumentationEntry& entry) const
  662. {
  663. entry.name = this->GetName();
  664. entry.brief = "Generates Visual Studio .NET 2002 project files.";
  665. entry.full = "";
  666. }
  667. // populate the m_SubProjectMap
  668. void cmGlobalVisualStudio7Generator::CollectSubprojects()
  669. {
  670. unsigned int i;
  671. for(i = 0; i < m_LocalGenerators.size(); ++i)
  672. {
  673. std::string name = m_LocalGenerators[i]->GetMakefile()->GetProjectName();
  674. m_SubProjectMap[name].push_back(m_LocalGenerators[i]);
  675. std::vector<std::string> const& pprojects
  676. = m_LocalGenerators[i]->GetMakefile()->GetParentProjects();
  677. for(unsigned int k =0; k < pprojects.size(); ++k)
  678. {
  679. m_SubProjectMap[pprojects[k]].push_back(m_LocalGenerators[i]);
  680. }
  681. }
  682. }
  683. // make sure "special" targets have GUID's
  684. void cmGlobalVisualStudio7Generator::Configure()
  685. {
  686. cmGlobalGenerator::Configure();
  687. this->CreateGUID("ALL_BUILD");
  688. this->CreateGUID("INSTALL");
  689. this->CreateGUID("RUN_TESTS");
  690. }