cmMSDotNETGenerator.cxx 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 "cmMSDotNETGenerator.h"
  14. #include "cmStandardIncludes.h"
  15. #include "cmMakefile.h"
  16. #include "cmCacheManager.h"
  17. #include "windows.h"
  18. #include "cmSystemTools.h"
  19. #include "cmRegularExpression.h"
  20. #include "cmSourceGroup.h"
  21. cmMSDotNETGenerator::cmMSDotNETGenerator()
  22. {
  23. // default to building a sln project file
  24. BuildProjOn();
  25. }
  26. void cmMSDotNETGenerator::GenerateMakefile()
  27. {
  28. std::string configTypes = m_Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES");
  29. std::string::size_type start = 0;
  30. std::string::size_type endpos = 0;
  31. while(endpos != std::string::npos)
  32. {
  33. endpos = configTypes.find(' ', start);
  34. std::string config;
  35. std::string::size_type len;
  36. if(endpos != std::string::npos)
  37. {
  38. len = endpos - start;
  39. }
  40. else
  41. {
  42. len = configTypes.size() - start;
  43. }
  44. config = configTypes.substr(start, len);
  45. if(config == "Debug" || config == "Release" ||
  46. config == "MinSizeRel" || config == "RelWithDebInfo")
  47. {
  48. m_Configurations.push_back(config);
  49. }
  50. else
  51. {
  52. cmSystemTools::Error("Invalid configuration type in CMAKE_CONFIGURATION_TYPES: ",
  53. config.c_str(),
  54. " (Valid types are Debug,Release,MinSizeRel,RelWithDebInfo)");
  55. }
  56. start = endpos+1;
  57. }
  58. if(m_Configurations.size() == 0)
  59. {
  60. m_Configurations.push_back("Debug");
  61. m_Configurations.push_back("Release");
  62. }
  63. if(m_BuildSLN)
  64. {
  65. this->OutputSLNFile();
  66. }
  67. else
  68. {
  69. this->OutputVCProjFile();
  70. }
  71. }
  72. cmMSDotNETGenerator::~cmMSDotNETGenerator()
  73. {
  74. }
  75. void cmMSDotNETGenerator::SetLocal(bool local)
  76. {
  77. m_BuildSLN = !local;
  78. }
  79. void cmMSDotNETGenerator::EnableLanguage(const char*)
  80. {
  81. // now load the settings
  82. if(!m_Makefile->GetDefinition("CMAKE_ROOT"))
  83. {
  84. cmSystemTools::Error(
  85. "CMAKE_ROOT has not been defined, bad GUI or driver program");
  86. return;
  87. }
  88. if(!this->GetLanguageEnabled("CXX"))
  89. {
  90. std::string fpath =
  91. m_Makefile->GetDefinition("CMAKE_ROOT");
  92. fpath += "/Templates/CMakeDotNetSystemConfig.cmake";
  93. m_Makefile->ReadListFile(NULL,fpath.c_str());
  94. this->SetLanguageEnabled("CXX");
  95. }
  96. }
  97. // output the SLN file
  98. void cmMSDotNETGenerator::OutputSLNFile()
  99. {
  100. // if this is an out of source build, create the output directory
  101. if(strcmp(m_Makefile->GetStartOutputDirectory(),
  102. m_Makefile->GetHomeDirectory()) != 0)
  103. {
  104. if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
  105. {
  106. cmSystemTools::Error("Error creating output directory for SLN file",
  107. m_Makefile->GetStartOutputDirectory());
  108. }
  109. }
  110. // create the dsw file name
  111. std::string fname;
  112. fname = m_Makefile->GetStartOutputDirectory();
  113. fname += "/";
  114. if(strlen(m_Makefile->GetProjectName()) == 0)
  115. {
  116. m_Makefile->SetProjectName("Project");
  117. }
  118. fname += m_Makefile->GetProjectName();
  119. fname += ".sln";
  120. std::ofstream fout(fname.c_str());
  121. if(!fout)
  122. {
  123. cmSystemTools::Error("Error can not open SLN file for write: "
  124. ,fname.c_str());
  125. return;
  126. }
  127. this->WriteSLNFile(fout);
  128. }
  129. // Write a SLN file to the stream
  130. void cmMSDotNETGenerator::WriteSLNFile(std::ostream& fout)
  131. {
  132. // Write out the header for a SLN file
  133. this->WriteSLNHeader(fout);
  134. // Create a list of cmMakefile created from all the
  135. // CMakeLists.txt files that are in sub directories of
  136. // this one.
  137. std::vector<cmMakefile*> allListFiles;
  138. // add this makefile to the list
  139. allListFiles.push_back(m_Makefile);
  140. // add a special target that depends on ALL projects for easy build
  141. // of Debug only
  142. m_Makefile->AddUtilityCommand("ALL_BUILD", "echo", "\"Build all projects\"",
  143. false);
  144. std::string ctest = m_Makefile->GetDefinition("CMAKE_COMMAND");
  145. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  146. ctest += "/";
  147. ctest += "ctest";
  148. ctest += cmSystemTools::GetExecutableExtension();
  149. if(!cmSystemTools::FileExists(ctest.c_str()))
  150. {
  151. ctest = m_Makefile->GetDefinition("CMAKE_COMMAND");
  152. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  153. ctest += "/Debug/";
  154. ctest += "ctest";
  155. ctest += cmSystemTools::GetExecutableExtension();
  156. }
  157. if(!cmSystemTools::FileExists(ctest.c_str()))
  158. {
  159. ctest = m_Makefile->GetDefinition("CMAKE_COMMAND");
  160. ctest = cmSystemTools::GetFilenamePath(ctest.c_str());
  161. ctest += "/Release/";
  162. ctest += "ctest";
  163. ctest += cmSystemTools::GetExecutableExtension();
  164. }
  165. m_Makefile->AddUtilityCommand("RUN_TESTS", ctest.c_str(), "-D $(IntDir)",
  166. false);
  167. m_Makefile->FindSubDirectoryCMakeListsFiles(allListFiles);
  168. // For each cmMakefile, create a VCProj for it, and
  169. // add it to this SLN file
  170. std::vector<cmMakefile*>::iterator k;
  171. for(k = allListFiles.begin();
  172. k != allListFiles.end(); ++k)
  173. {
  174. cmMakefile* mf = *k;
  175. cmMSDotNETGenerator* pg =
  176. static_cast<cmMSDotNETGenerator*>(mf->GetMakefileGenerator());
  177. // make sure the generator is building dsp files
  178. pg->BuildSLNOff();
  179. mf->GenerateMakefile();
  180. // Get the source directory from the makefile
  181. std::string dir = mf->GetStartDirectory();
  182. // Get the home directory with the trailing slash
  183. std::string homedir = m_Makefile->GetHomeDirectory();
  184. homedir += "/";
  185. // remove the home directory and / from the source directory
  186. // this gives a relative path
  187. cmSystemTools::ReplaceString(dir, homedir.c_str(), "");
  188. // Get the list of create dsp files names from the cmVCProjWriter, more
  189. // than one dsp could have been created per input CMakeLists.txt file
  190. // for each target
  191. std::vector<std::string> dspnames =
  192. pg->GetCreatedProjectNames();
  193. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  194. cmTargets::iterator l = tgts.begin();
  195. for(std::vector<std::string>::iterator si = dspnames.begin();
  196. l != tgts.end(); ++l)
  197. {
  198. // special handling for the current makefile
  199. if(mf == m_Makefile)
  200. {
  201. dir = "."; // no subdirectory for project generated
  202. // if this is the special ALL_BUILD utility, then
  203. // make it depend on every other non UTILITY project.
  204. // This is done by adding the names to the GetUtilities
  205. // vector on the makefile
  206. if(l->first == "ALL_BUILD")
  207. {
  208. for(std::vector<cmMakefile*>::iterator a = allListFiles.begin();
  209. a != allListFiles.end(); ++a)
  210. {
  211. const cmTargets &atgts = (*a)->GetTargets();
  212. for(cmTargets::const_iterator al = atgts.begin();
  213. al != atgts.end(); ++al)
  214. {
  215. if (al->second.IsInAll())
  216. {
  217. if (al->second.GetType() == cmTarget::UTILITY)
  218. {
  219. l->second.AddUtility(al->first.c_str());
  220. }
  221. else
  222. {
  223. l->second.AddLinkLibrary(al->first,cmTarget::GENERAL);
  224. }
  225. }
  226. }
  227. }
  228. }
  229. }
  230. // Write the project into the SLN file
  231. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  232. {
  233. cmCustomCommand cc = l->second.GetCustomCommands()[0];
  234. // dodgy use of the cmCustomCommand's members to store the
  235. // arguments from the INCLUDE_EXTERNAL_MSPROJECT command
  236. std::vector<std::string> stuff = cc.GetDepends();
  237. std::vector<std::string> depends = cc.GetOutputs();
  238. this->WriteExternalProject(fout, stuff[0].c_str(), stuff[1].c_str(), depends);
  239. ++si;
  240. }
  241. else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  242. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  243. {
  244. this->WriteProject(fout, si->c_str(), dir.c_str(),
  245. pg,l->second);
  246. ++si;
  247. }
  248. }
  249. }
  250. fout << "Global\n"
  251. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  252. int c = 0;
  253. for(std::vector<std::string>::iterator i = m_Configurations.begin();
  254. i != m_Configurations.end(); ++i)
  255. {
  256. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  257. c++;
  258. }
  259. fout << "\tEndGlobalSection\n"
  260. << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  261. // loop over again and compute the depends
  262. for(k = allListFiles.begin(); k != allListFiles.end(); ++k)
  263. {
  264. cmMakefile* mf = *k;
  265. cmMSDotNETGenerator* pg =
  266. static_cast<cmMSDotNETGenerator*>(mf->GetMakefileGenerator());
  267. // Get the list of create dsp files names from the cmVCProjWriter, more
  268. // than one dsp could have been created per input CMakeLists.txt file
  269. // for each target
  270. std::vector<std::string> dspnames =
  271. pg->GetCreatedProjectNames();
  272. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  273. cmTargets::iterator l = tgts.begin();
  274. std::string dir = mf->GetStartDirectory();
  275. for(std::vector<std::string>::iterator si = dspnames.begin();
  276. l != tgts.end(); ++l)
  277. {
  278. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  279. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  280. {
  281. this->WriteProjectDepends(fout, si->c_str(), dir.c_str(),
  282. pg,l->second);
  283. ++si;
  284. }
  285. }
  286. }
  287. fout << "\tEndGlobalSection\n";
  288. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  289. // loop over again and compute the depends
  290. for(k = allListFiles.begin(); k != allListFiles.end(); ++k)
  291. {
  292. cmMakefile* mf = *k;
  293. cmMSDotNETGenerator* pg =
  294. static_cast<cmMSDotNETGenerator*>(mf->GetMakefileGenerator());
  295. // Get the list of create dsp files names from the cmVCProjWriter, more
  296. // than one dsp could have been created per input CMakeLists.txt file
  297. // for each target
  298. std::vector<std::string> dspnames =
  299. pg->GetCreatedProjectNames();
  300. cmTargets &tgts = pg->GetMakefile()->GetTargets();
  301. cmTargets::iterator l = tgts.begin();
  302. std::string dir = mf->GetStartDirectory();
  303. for(std::vector<std::string>::iterator si = dspnames.begin();
  304. l != tgts.end(); ++l)
  305. {
  306. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  307. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  308. {
  309. this->WriteProjectConfigurations(fout, si->c_str());
  310. ++si;
  311. }
  312. }
  313. // delete the cmMakefile which also deletes the cmMSProjectGenerator
  314. if(mf != m_Makefile)
  315. {
  316. delete mf;
  317. }
  318. }
  319. fout << "\tEndGlobalSection\n";
  320. // Write the footer for the SLN file
  321. this->WriteSLNFooter(fout);
  322. }
  323. // Write a dsp file into the SLN file,
  324. // Note, that dependencies from executables to
  325. // the libraries it uses are also done here
  326. void cmMSDotNETGenerator::WriteProject(std::ostream& fout,
  327. const char* dspname,
  328. const char* dir,
  329. cmMSDotNETGenerator*,
  330. const cmTarget&
  331. )
  332. {
  333. std::string d = cmSystemTools::ConvertToOutputPath(dir);
  334. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\" = \""
  335. << dspname << "\", \""
  336. << d << "\\" << dspname << ".vcproj\", \"{"
  337. << this->CreateGUID(dspname) << "}\"\nEndProject\n";
  338. }
  339. // Write a dsp file into the SLN file,
  340. // Note, that dependencies from executables to
  341. // the libraries it uses are also done here
  342. void cmMSDotNETGenerator::WriteProjectDepends(std::ostream& fout,
  343. const char* dspname,
  344. const char* ,
  345. cmMSDotNETGenerator*,
  346. const cmTarget& target
  347. )
  348. {
  349. int depcount = 0;
  350. // insert Begin Project Dependency Project_Dep_Name project stuff here
  351. if (target.GetType() != cmTarget::STATIC_LIBRARY)
  352. {
  353. cmTarget::LinkLibraries::const_iterator j, jend;
  354. j = target.GetLinkLibraries().begin();
  355. jend = target.GetLinkLibraries().end();
  356. for(;j!= jend; ++j)
  357. {
  358. if(j->first != dspname)
  359. {
  360. // is the library part of this SLN ? If so add dependency
  361. const char* cacheValue
  362. = m_Makefile->GetDefinition(j->first.c_str());
  363. if(cacheValue)
  364. {
  365. fout << "\t\t{" << this->CreateGUID(dspname) << "}." << depcount << " = {"
  366. << this->CreateGUID(j->first.c_str()) << "}\n";
  367. depcount++;
  368. }
  369. }
  370. }
  371. }
  372. std::set<cmStdString>::const_iterator i, end;
  373. // write utility dependencies.
  374. i = target.GetUtilities().begin();
  375. end = target.GetUtilities().end();
  376. for(;i!= end; ++i)
  377. {
  378. if(*i != dspname)
  379. {
  380. fout << "\t\t{" << this->CreateGUID(dspname) << "}." << depcount << " = {"
  381. << this->CreateGUID(i->c_str()) << "}\n";
  382. depcount++;
  383. }
  384. }
  385. }
  386. // Write a dsp file into the SLN file,
  387. // Note, that dependencies from executables to
  388. // the libraries it uses are also done here
  389. void cmMSDotNETGenerator::WriteProjectConfigurations(std::ostream& fout, const char* name)
  390. {
  391. std::string guid = this->CreateGUID(name);
  392. for(std::vector<std::string>::iterator i = m_Configurations.begin();
  393. i != m_Configurations.end(); ++i)
  394. {
  395. fout << "\t\t{" << guid << "}." << *i << ".ActiveCfg = " << *i << "|Win32\n"
  396. << "\t\t{" << guid << "}." << *i << ".Build.0 = " << *i << "|Win32\n";
  397. }
  398. }
  399. // Write a dsp file into the SLN file,
  400. // Note, that dependencies from executables to
  401. // the libraries it uses are also done here
  402. void cmMSDotNETGenerator::WriteExternalProject(std::ostream& ,
  403. const char* ,
  404. const char* ,
  405. const std::vector<std::string>& )
  406. {
  407. cmSystemTools::Error("WriteExternalProject not implemented");
  408. // fout << "#########################################################"
  409. // "######################\n\n";
  410. // fout << "Project: \"" << name << "\"="
  411. // << location << " - Package Owner=<4>\n\n";
  412. // fout << "Package=<5>\n{{{\n}}}\n\n";
  413. // fout << "Package=<4>\n";
  414. // fout << "{{{\n";
  415. // std::vector<std::string>::const_iterator i, end;
  416. // // write dependencies.
  417. // i = dependencies.begin();
  418. // end = dependencies.end();
  419. // for(;i!= end; ++i)
  420. // {
  421. // fout << "Begin Project Dependency\n";
  422. // fout << "Project_Dep_Name " << *i << "\n";
  423. // fout << "End Project Dependency\n";
  424. // }
  425. // fout << "}}}\n\n";
  426. }
  427. // Standard end of dsw file
  428. void cmMSDotNETGenerator::WriteSLNFooter(std::ostream& fout)
  429. {
  430. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  431. << "\tEndGlobalSection\n"
  432. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  433. << "\tEndGlobalSection\n"
  434. << "EndGlobal\n";
  435. }
  436. // ouput standard header for dsw file
  437. void cmMSDotNETGenerator::WriteSLNHeader(std::ostream& fout)
  438. {
  439. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  440. }
  441. std::string cmMSDotNETGenerator::CreateGUID(const char* name)
  442. {
  443. std::map<cmStdString, cmStdString>::iterator i = m_GUIDMap.find(name);
  444. if(i != m_GUIDMap.end())
  445. {
  446. return i->second;
  447. }
  448. std::string ret;
  449. UUID uid;
  450. unsigned char *uidstr;
  451. UuidCreate(&uid);
  452. UuidToString(&uid,&uidstr);
  453. ret = reinterpret_cast<char*>(uidstr);
  454. RpcStringFree(&uidstr);
  455. ret = cmSystemTools::UpperCase(ret);
  456. m_GUIDMap[name] = ret;
  457. return ret;
  458. }
  459. // TODO
  460. // for CommandLine= need to repleace quotes with &quot
  461. // write out configurations
  462. void cmMSDotNETGenerator::OutputVCProjFile()
  463. {
  464. // If not an in source build, then create the output directory
  465. if(strcmp(m_Makefile->GetStartOutputDirectory(),
  466. m_Makefile->GetHomeDirectory()) != 0)
  467. {
  468. if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
  469. {
  470. cmSystemTools::Error("Error creating directory ",
  471. m_Makefile->GetStartOutputDirectory());
  472. }
  473. }
  474. m_LibraryOutputPath = "";
  475. if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  476. {
  477. m_LibraryOutputPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  478. }
  479. if(m_LibraryOutputPath.size())
  480. {
  481. // make sure there is a trailing slash
  482. if(m_LibraryOutputPath[m_LibraryOutputPath.size()-1] != '/')
  483. {
  484. m_LibraryOutputPath += "/";
  485. }
  486. }
  487. m_ExecutableOutputPath = "";
  488. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  489. {
  490. m_ExecutableOutputPath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  491. }
  492. if(m_ExecutableOutputPath.size())
  493. {
  494. // make sure there is a trailing slash
  495. if(m_ExecutableOutputPath[m_ExecutableOutputPath.size()-1] != '/')
  496. {
  497. m_ExecutableOutputPath += "/";
  498. }
  499. }
  500. // Create the VCProj or set of VCProj's for libraries and executables
  501. // clear project names
  502. m_CreatedProjectNames.clear();
  503. // build any targets
  504. cmTargets &tgts = m_Makefile->GetTargets();
  505. for(cmTargets::iterator l = tgts.begin();
  506. l != tgts.end(); l++)
  507. {
  508. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  509. // so don't build a projectfile for it
  510. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  511. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)
  512. && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0))
  513. {
  514. this->CreateSingleVCProj(l->first.c_str(),l->second);
  515. }
  516. }
  517. }
  518. void cmMSDotNETGenerator::CreateSingleVCProj(const char *lname, cmTarget &target)
  519. {
  520. // add to the list of projects
  521. std::string pname = lname;
  522. m_CreatedProjectNames.push_back(pname);
  523. // create the dsp.cmake file
  524. std::string fname;
  525. fname = m_Makefile->GetStartOutputDirectory();
  526. fname += "/";
  527. fname += lname;
  528. fname += ".vcproj";
  529. // save the name of the real dsp file
  530. std::string realVCProj = fname;
  531. fname += ".cmake";
  532. std::ofstream fout(fname.c_str());
  533. if(!fout)
  534. {
  535. cmSystemTools::Error("Error Writing ", fname.c_str());
  536. }
  537. this->WriteVCProjFile(fout,lname,target);
  538. fout.close();
  539. // if the dsp file has changed, then write it.
  540. cmSystemTools::CopyFileIfDifferent(fname.c_str(), realVCProj.c_str());
  541. }
  542. void cmMSDotNETGenerator::AddVCProjBuildRule(cmSourceGroup& sourceGroup)
  543. {
  544. std::string dspname = *(m_CreatedProjectNames.end()-1);
  545. if(dspname == "ALL_BUILD")
  546. {
  547. return;
  548. }
  549. dspname += ".vcproj.cmake";
  550. std::string makefileIn = m_Makefile->GetStartDirectory();
  551. makefileIn += "/";
  552. makefileIn += "CMakeLists.txt";
  553. makefileIn = cmSystemTools::ConvertToOutputPath(makefileIn.c_str());
  554. std::string dsprule = "${CMAKE_COMMAND}";
  555. m_Makefile->ExpandVariablesInString(dsprule);
  556. dsprule = cmSystemTools::ConvertToOutputPath(dsprule.c_str());
  557. std::string args = makefileIn;
  558. args += " -H\"";
  559. args +=
  560. cmSystemTools::ConvertToOutputPath(m_Makefile->GetHomeDirectory());
  561. args += "\" -S\"";
  562. args +=
  563. cmSystemTools::ConvertToOutputPath(m_Makefile->GetStartDirectory());
  564. args += "\" -O\"";
  565. args +=
  566. cmSystemTools::ConvertToOutputPath(m_Makefile->GetStartOutputDirectory());
  567. args += "\" -B\"";
  568. args +=
  569. cmSystemTools::ConvertToOutputPath(m_Makefile->GetHomeOutputDirectory());
  570. args += "\"";
  571. m_Makefile->ExpandVariablesInString(args);
  572. std::string configFile =
  573. m_Makefile->GetDefinition("CMAKE_ROOT");
  574. configFile += "/Templates/CMakeWindowsSystemConfig.cmake";
  575. std::vector<std::string> listFiles = m_Makefile->GetListFiles();
  576. bool found = false;
  577. for(std::vector<std::string>::iterator i = listFiles.begin();
  578. i != listFiles.end(); ++i)
  579. {
  580. if(*i == configFile)
  581. {
  582. found = true;
  583. }
  584. }
  585. if(!found)
  586. {
  587. listFiles.push_back(configFile);
  588. }
  589. std::vector<std::string> outputs;
  590. outputs.push_back(dspname);
  591. cmCustomCommand cc(makefileIn.c_str(), dsprule.c_str(),
  592. args.c_str(),
  593. listFiles,
  594. outputs);
  595. sourceGroup.AddCustomCommand(cc);
  596. }
  597. void cmMSDotNETGenerator::WriteConfigurations(std::ostream& fout,
  598. const char *libName,
  599. const cmTarget &target)
  600. {
  601. fout << "\t<Configurations>\n";
  602. for( std::vector<std::string>::iterator i = m_Configurations.begin();
  603. i != m_Configurations.end(); ++i)
  604. {
  605. this->WriteConfiguration(fout, i->c_str(), libName, target);
  606. }
  607. fout << "\t</Configurations>\n";
  608. }
  609. void cmMSDotNETGenerator::WriteConfiguration(std::ostream& fout,
  610. const char* configName,
  611. const char *libName,
  612. const cmTarget &target)
  613. {
  614. const char* mfcFlag = m_Makefile->GetDefinition("CMAKE_MFC_FLAG");
  615. if(!mfcFlag)
  616. {
  617. mfcFlag = "0";
  618. }
  619. fout << "\t\t<Configuration\n"
  620. << "\t\t\tName=\"" << configName << "|Win32\"\n"
  621. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  622. // This is an internal type to Visual Studio, it seems that:
  623. // 4 == static library
  624. // 2 == dll
  625. // 1 == executable
  626. // 10 == utility
  627. const char* configType = "10";
  628. switch(target.GetType())
  629. {
  630. case cmTarget::STATIC_LIBRARY:
  631. configType = "4";
  632. break;
  633. case cmTarget::SHARED_LIBRARY:
  634. case cmTarget::MODULE_LIBRARY:
  635. configType = "2";
  636. break;
  637. case cmTarget::EXECUTABLE:
  638. case cmTarget::WIN32_EXECUTABLE:
  639. configType = "1";
  640. break;
  641. case cmTarget::UTILITY:
  642. configType = "10";
  643. default:
  644. break;
  645. }
  646. fout << "\t\t\tIntermediateDirectory=\".\\" << configName << "\"\n"
  647. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  648. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  649. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  650. << "\t\t\tCharacterSet=\"2\">\n";
  651. fout << "\t\t\t<Tool\n"
  652. << "\t\t\t\tName=\"VCCLCompilerTool\"\n"
  653. << "\t\t\t\tAdditionalOptions=\""
  654. << m_Makefile->GetDefinition("CMAKE_CXX_FLAGS")
  655. << " -DCMAKE_INTDIR=\\&quot;" << configName << "\\&quot;"
  656. << "\"\n";
  657. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  658. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  659. std::vector<std::string>::iterator i = includes.begin();
  660. for(;i != includes.end(); ++i)
  661. {
  662. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  663. fout << ipath << ";";
  664. }
  665. fout << "\"\n";
  666. // Optimization = 0 None Debug /O0
  667. // Optimization = 1 MinSize /O1
  668. // Optimization = 2 MaxSpeed /O2
  669. // Optimization = 3 Max Optimization /O3
  670. // RuntimeLibrary = 0 /MT multithread
  671. // RuntimeLibrary = 1 /MTd multithread debug
  672. // RuntimeLibrary = 2 /MD multithread dll
  673. // RuntimeLibrary = 3 /MDd multithread dll debug
  674. // RuntimeLibrary = 4 /ML single thread
  675. // RuntimeLibrary = 5 /MLd single thread debug
  676. // InlineFunctionExpansion = 0 none
  677. // InlineFunctionExpansion = 1 when inline keyword
  678. // InlineFunctionExpansion = 2 any time you can
  679. if(strcmp(configName, "Debug") == 0)
  680. {
  681. fout << "\t\t\t\tOptimization=\"0\"\n"
  682. << "\t\t\t\tRuntimeLibrary=\"3\"\n"
  683. << "\t\t\t\tInlineFunctionExpansion=\"0\"\n"
  684. << "\t\t\t\tPreprocessorDefinitions=\"WIN32,_DEBUG,_WINDOWS";
  685. }
  686. else if(strcmp(configName, "Release") == 0)
  687. {
  688. fout << "\t\t\t\tOptimization=\"2\"\n"
  689. << "\t\t\t\tRuntimeLibrary=\"2\"\n"
  690. << "\t\t\t\tInlineFunctionExpansion=\"1\"\n"
  691. << "\t\t\t\tPreprocessorDefinitions=\"WIN32,NDEBUG,_WINDOWS";
  692. }
  693. else if(strcmp(configName, "MinSizeRel") == 0)
  694. {
  695. fout << "\t\t\t\tOptimization=\"1\"\n"
  696. << "\t\t\t\tRuntimeLibrary=\"2\"\n"
  697. << "\t\t\t\tInlineFunctionExpansion=\"1\"\n"
  698. << "\t\t\t\tPreprocessorDefinitions=\"WIN32,NDEBUG,_WINDOWS";
  699. }
  700. else if(strcmp(configName, "RelWithDebInfo") == 0)
  701. {
  702. fout << "\t\t\t\tOptimization=\"2\"\n"
  703. << "\t\t\t\tRuntimeLibrary=\"2\"\n"
  704. << "\t\t\t\tInlineFunctionExpansion=\"1\"\n"
  705. << "\t\t\t\tPreprocessorDefinitions=\"WIN32,NDEBUG,_WINDOWS";
  706. }
  707. if(target.GetType() == cmTarget::SHARED_LIBRARY
  708. || target.GetType() == cmTarget::MODULE_LIBRARY)
  709. {
  710. fout << "," << libName << "_EXPORTS";
  711. }
  712. this->OutputDefineFlags(fout);
  713. fout << "\"\n";
  714. if(m_Makefile->IsOn("CMAKE_CXX_USE_RTTI"))
  715. {
  716. fout << "\t\t\t\tRuntimeTypeInfo=\"TRUE\"\n";
  717. }
  718. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  719. fout << "\t\t\t\tObjectFile=\"" << configName << "\\\"\n";
  720. fout << "\t\t\t\tWarningLevel=\"" << m_Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL") << "\"\n";
  721. fout << "\t\t\t\tDetect64BitPortabilityProblems=\"TRUE\"\n"
  722. << "\t\t\t\tDebugInformationFormat=\"3\"";
  723. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  724. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
  725. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n";
  726. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"";
  727. this->OutputTargetRules(fout, target, libName);
  728. fout << "/>\n";
  729. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"/>\n";
  730. this->OutputBuildTool(fout, configName, libName, target);
  731. fout << "\t\t</Configuration>\n";
  732. }
  733. void cmMSDotNETGenerator::OutputBuildTool(std::ostream& fout,
  734. const char* configName,
  735. const char *libName,
  736. const cmTarget &target)
  737. {
  738. switch(target.GetType())
  739. {
  740. case cmTarget::STATIC_LIBRARY:
  741. {
  742. std::string libpath = m_LibraryOutputPath +
  743. "$(OutDir)/" + libName + ".lib";
  744. fout << "\t\t\t<Tool\n"
  745. << "\t\t\t\tName=\"VCLibrarianTool\"\n"
  746. << "\t\t\t\t\tOutputFile=\""
  747. << this->ConvertToXMLOutputPath(libpath.c_str()) << ".\"/>\n";
  748. break;
  749. }
  750. case cmTarget::SHARED_LIBRARY:
  751. case cmTarget::MODULE_LIBRARY:
  752. fout << "\t\t\t<Tool\n"
  753. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  754. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386\"\n"
  755. << "\t\t\t\tAdditionalDependencies=\" odbc32.lib odbccp32.lib ";
  756. this->OutputLibraries(fout, configName, libName, target);
  757. fout << "\"\n";
  758. fout << "\t\t\t\tOutputFile=\""
  759. << m_ExecutableOutputPath << configName << "/"
  760. << libName << ".dll\"\n";
  761. fout << "\t\t\t\tLinkIncremental=\"1\"\n";
  762. fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n";
  763. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  764. this->OutputLibraryDirectories(fout, configName, libName, target);
  765. fout << "\"\n";
  766. this->OutputModuleDefinitionFile(fout, target);
  767. fout << "\t\t\t\tProgramDatabaseFile=\"" << m_LibraryOutputPath
  768. << "$(OutDir)\\" << libName << ".pdb\"\n";
  769. if(strcmp(configName, "Debug") == 0
  770. || strcmp(configName, "RelWithDebInfo") == 0)
  771. {
  772. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  773. }
  774. fout << "\t\t\t\tStackReserveSize=\""
  775. << m_Makefile->GetDefinition("CMAKE_CXX_STACK_SIZE") << "\"\n";
  776. fout << "\t\t\t\tImportLibrary=\""
  777. << m_ExecutableOutputPath << configName << "/"
  778. << libName << ".lib\"/>\n";
  779. break;
  780. case cmTarget::EXECUTABLE:
  781. case cmTarget::WIN32_EXECUTABLE:
  782. fout << "\t\t\t<Tool\n"
  783. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  784. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386\"\n"
  785. << "\t\t\t\tAdditionalDependencies=\" odbc32.lib odbccp32.lib ";
  786. this->OutputLibraries(fout, configName, libName, target);
  787. fout << "\"\n";
  788. fout << "\t\t\t\tOutputFile=\""
  789. << m_ExecutableOutputPath << configName << "/" << libName << ".exe\"\n";
  790. fout << "\t\t\t\tLinkIncremental=\"1\"\n";
  791. fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n";
  792. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  793. this->OutputLibraryDirectories(fout, configName, libName, target);
  794. fout << "\"\n";
  795. fout << "\t\t\t\tProgramDatabaseFile=\"" << m_LibraryOutputPath
  796. << "$(OutDir)\\" << libName << ".pdb\"\n";
  797. if(strcmp(configName, "Debug") == 0
  798. || strcmp(configName, "RelWithDebInfo") == 0)
  799. {
  800. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  801. }
  802. if( target.GetType() == cmTarget::EXECUTABLE)
  803. {
  804. fout << "\t\t\t\tSubSystem=\"1\"\n";
  805. }
  806. else
  807. {
  808. fout << "\t\t\t\tSubSystem=\"2\"\n";
  809. }
  810. fout << "\t\t\t\tStackReserveSize=\""
  811. << m_Makefile->GetDefinition("CMAKE_CXX_STACK_SIZE") << "\"/>\n";
  812. break;
  813. case cmTarget::UTILITY:
  814. break;
  815. }
  816. }
  817. void cmMSDotNETGenerator::OutputModuleDefinitionFile(std::ostream& fout,
  818. const cmTarget &target)
  819. {
  820. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  821. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  822. i != classes.end(); i++)
  823. {
  824. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  825. {
  826. fout << "\t\t\t\tModuleDefinitionFile=\""
  827. << this->ConvertToXMLOutputPath((*i)->GetFullPath().c_str())
  828. << "\"\n";
  829. return;
  830. }
  831. }
  832. }
  833. void cmMSDotNETGenerator::OutputLibraryDirectories(std::ostream& fout,
  834. const char*,
  835. const char*,
  836. const cmTarget &tgt)
  837. {
  838. bool hasone = false;
  839. if(m_LibraryOutputPath.size())
  840. {
  841. hasone = true;
  842. fout << m_LibraryOutputPath << "$(INTDIR)," << m_LibraryOutputPath;
  843. }
  844. if(m_ExecutableOutputPath.size())
  845. {
  846. hasone = true;
  847. fout << m_ExecutableOutputPath << "$(INTDIR)," << m_ExecutableOutputPath;
  848. }
  849. std::set<std::string> pathEmitted;
  850. std::vector<std::string>::const_iterator i;
  851. const std::vector<std::string>& libdirs = tgt.GetLinkDirectories();
  852. for(i = libdirs.begin(); i != libdirs.end(); ++i)
  853. {
  854. std::string lpath = *i;
  855. if(lpath[lpath.size()-1] != '/')
  856. {
  857. lpath += "/";
  858. }
  859. if(pathEmitted.insert(lpath).second)
  860. {
  861. if(hasone)
  862. {
  863. fout << ",";
  864. }
  865. std::string lpathi = lpath + "$(INTDIR)";
  866. fout << this->ConvertToXMLOutputPath(lpathi.c_str()) << "," << lpath;
  867. hasone = true;
  868. }
  869. }
  870. }
  871. void cmMSDotNETGenerator::OutputLibraries(std::ostream& fout,
  872. const char* configName,
  873. const char* libName,
  874. const cmTarget &target)
  875. {
  876. const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
  877. cmTarget::LinkLibraries::const_iterator j;
  878. for(j = libs.begin(); j != libs.end(); ++j)
  879. {
  880. if(j->first != libName)
  881. {
  882. std::string lib = j->first;
  883. if(j->first.find(".lib") == std::string::npos)
  884. {
  885. lib += ".lib";
  886. }
  887. lib = this->ConvertToXMLOutputPath(lib.c_str());
  888. if (j->second == cmTarget::GENERAL
  889. || (j->second == cmTarget::DEBUG && strcmp(configName, "DEBUG") == 0)
  890. || (j->second == cmTarget::OPTIMIZED && strcmp(configName, "DEBUG") != 0))
  891. {
  892. fout << lib << " ";
  893. }
  894. }
  895. }
  896. }
  897. void cmMSDotNETGenerator::OutputDefineFlags(std::ostream& fout)
  898. {
  899. std::string defs = m_Makefile->GetDefineFlags();
  900. std::string::size_type pos = defs.find("-D");
  901. bool done = pos == std::string::npos;
  902. if(!done)
  903. {
  904. fout << ",";
  905. }
  906. while(!done)
  907. {
  908. std::string::size_type nextpos = defs.find("-D", pos+2);
  909. std::string define;
  910. if(nextpos != std::string::npos)
  911. {
  912. define = defs.substr(pos+2, nextpos - pos -3);
  913. }
  914. else
  915. {
  916. define = defs.substr(pos+2);
  917. done = true;
  918. }
  919. fout << define << ",";
  920. if(!done)
  921. {
  922. pos = defs.find("-D", nextpos);
  923. }
  924. }
  925. }
  926. void cmMSDotNETGenerator::WriteVCProjFile(std::ostream& fout,
  927. const char *libName,
  928. cmTarget &target)
  929. {
  930. // We may be modifying the source groups temporarily, so make a copy.
  931. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  932. // get the classes from the source lists then add them to the groups
  933. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  934. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  935. i != classes.end(); i++)
  936. {
  937. // Add the file to the list of sources.
  938. std::string source = (*i)->GetFullPath();
  939. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  940. {
  941. m_ModuleDefinitionFile = (*i)->GetFullPath();
  942. }
  943. cmSourceGroup& sourceGroup = m_Makefile->FindSourceGroup(source.c_str(),
  944. sourceGroups);
  945. sourceGroup.AddSource(source.c_str(), *i);
  946. }
  947. // add any custom rules to the source groups
  948. for (std::vector<cmCustomCommand>::const_iterator cr =
  949. target.GetCustomCommands().begin();
  950. cr != target.GetCustomCommands().end(); ++cr)
  951. {
  952. cmSourceGroup& sourceGroup =
  953. m_Makefile->FindSourceGroup(cr->GetSourceName().c_str(),
  954. sourceGroups);
  955. cmCustomCommand cc(*cr);
  956. cc.ExpandVariables(*m_Makefile);
  957. sourceGroup.AddCustomCommand(cc);
  958. }
  959. // open the project
  960. this->WriteProjectStart(fout, libName, target, sourceGroups);
  961. // write the configuration information
  962. this->WriteConfigurations(fout, libName, target);
  963. fout << "\t<Files>\n";
  964. // Find the group in which the CMakeLists.txt source belongs, and add
  965. // the rule to generate this VCProj file.
  966. for(std::vector<cmSourceGroup>::reverse_iterator sg = sourceGroups.rbegin();
  967. sg != sourceGroups.rend(); ++sg)
  968. {
  969. if(sg->Matches("CMakeLists.txt"))
  970. {
  971. this->AddVCProjBuildRule(*sg);
  972. break;
  973. }
  974. }
  975. // Loop through every source group.
  976. for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
  977. sg != sourceGroups.end(); ++sg)
  978. {
  979. const cmSourceGroup::BuildRules& buildRules = sg->GetBuildRules();
  980. // If the group is empty, don't write it at all.
  981. if(buildRules.empty())
  982. { continue; }
  983. // If the group has a name, write the header.
  984. std::string name = sg->GetName();
  985. if(name != "")
  986. {
  987. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  988. }
  989. // Loop through each build rule in the source group.
  990. for(cmSourceGroup::BuildRules::const_iterator cc =
  991. buildRules.begin(); cc != buildRules.end(); ++ cc)
  992. {
  993. std::string source = cc->first;
  994. const cmSourceGroup::Commands& commands = cc->second.m_Commands;
  995. const char* compileFlags = 0;
  996. if(cc->second.m_SourceFile)
  997. {
  998. compileFlags = cc->second.m_SourceFile->GetCompileFlags();
  999. }
  1000. if (source != libName || target.GetType() == cmTarget::UTILITY)
  1001. {
  1002. fout << "\t\t\t<File\n";
  1003. std::string d = this->ConvertToXMLOutputPath(source.c_str());
  1004. // Tell MS-Dev what the source is. If the compiler knows how to
  1005. // build it, then it will.
  1006. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1007. if (!commands.empty())
  1008. {
  1009. cmSourceGroup::CommandFiles totalCommand;
  1010. std::string totalCommandStr;
  1011. totalCommandStr = this->CombineCommands(commands, totalCommand,
  1012. source.c_str());
  1013. this->WriteCustomRule(fout, source.c_str(), totalCommandStr.c_str(),
  1014. totalCommand.m_Depends,
  1015. totalCommand.m_Outputs, compileFlags);
  1016. }
  1017. else if(compileFlags)
  1018. {
  1019. for(std::vector<std::string>::iterator i
  1020. = m_Configurations.begin(); i != m_Configurations.end(); ++i)
  1021. {
  1022. fout << "\t\t\t\t<FileConfiguration\n"
  1023. << "\t\t\t\t\tName=\"" << *i << "|Win32\">\n"
  1024. << "\t\t\t\t\t<Tool\n"
  1025. << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
  1026. << "\t\t\t\t\tAdditionalOptions=\""
  1027. << compileFlags << "\"/>\n"
  1028. << "\t\t\t\t</FileConfiguration>\n";
  1029. }
  1030. }
  1031. fout << "\t\t\t</File>\n";
  1032. }
  1033. }
  1034. // If the group has a name, write the footer.
  1035. if(name != "")
  1036. {
  1037. this->WriteVCProjEndGroup(fout);
  1038. }
  1039. }
  1040. fout << "\t</Files>\n";
  1041. // Write the VCProj file's footer.
  1042. this->WriteVCProjFooter(fout);
  1043. }
  1044. void cmMSDotNETGenerator::WriteCustomRule(std::ostream& fout,
  1045. const char* source,
  1046. const char* command,
  1047. const std::set<std::string>& depends,
  1048. const std::set<std::string>& outputs,
  1049. const char* compileFlags)
  1050. {
  1051. std::string cmd = command;
  1052. cmSystemTools::ReplaceString(cmd, "\"", "&quot;");
  1053. std::vector<std::string>::iterator i;
  1054. for(i = m_Configurations.begin(); i != m_Configurations.end(); ++i)
  1055. {
  1056. fout << "\t\t\t\t<FileConfiguration\n";
  1057. fout << "\t\t\t\t\tName=\"" << *i << "|Win32\">\n";
  1058. if(compileFlags)
  1059. {
  1060. fout << "\t\t\t\t\t<Tool\n"
  1061. << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
  1062. << "\t\t\t\t\tAdditionalOptions=\""
  1063. << compileFlags << "\"/>\n";
  1064. }
  1065. fout << "\t\t\t\t\t<Tool\n"
  1066. << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
  1067. << "\t\t\t\t\tCommandLine=\"" << cmd << "\n\"\n"
  1068. << "\t\t\t\t\tAdditionalDependencies=\"";
  1069. // Write out the dependencies for the rule.
  1070. std::string temp;
  1071. for(std::set<std::string>::const_iterator d = depends.begin();
  1072. d != depends.end(); ++d)
  1073. {
  1074. fout << this->ConvertToXMLOutputPath(d->c_str())
  1075. << ";";
  1076. }
  1077. fout << "\"\n";
  1078. fout << "\t\t\t\t\tOutputs=\"";
  1079. if(outputs.size() == 0)
  1080. {
  1081. fout << source << "_force";
  1082. }
  1083. bool first = true;
  1084. // Write a rule for every output generated by this command.
  1085. for(std::set<std::string>::const_iterator output = outputs.begin();
  1086. output != outputs.end(); ++output)
  1087. {
  1088. if(!first)
  1089. {
  1090. fout << ";";
  1091. }
  1092. else
  1093. {
  1094. first = false;
  1095. }
  1096. fout << output->c_str();
  1097. }
  1098. fout << "\"/>\n";
  1099. fout << "\t\t\t\t</FileConfiguration>\n";
  1100. }
  1101. }
  1102. void cmMSDotNETGenerator::WriteVCProjBeginGroup(std::ostream& fout,
  1103. const char* group,
  1104. const char* )
  1105. {
  1106. fout << "\t\t<Filter\n"
  1107. << "\t\t\tName=\"" << group << "\"\n"
  1108. << "\t\t\tFilter=\"\">\n";
  1109. }
  1110. void cmMSDotNETGenerator::WriteVCProjEndGroup(std::ostream& fout)
  1111. {
  1112. fout << "\t\t</Filter>\n";
  1113. }
  1114. std::string
  1115. cmMSDotNETGenerator::CombineCommands(const cmSourceGroup::Commands &commands,
  1116. cmSourceGroup::CommandFiles &totalCommand,
  1117. const char *source)
  1118. {
  1119. // Loop through every custom command generating code from the
  1120. // current source.
  1121. // build up the depends and outputs and commands
  1122. std::string totalCommandStr = "";
  1123. std::string temp;
  1124. for(cmSourceGroup::Commands::const_iterator c = commands.begin();
  1125. c != commands.end(); ++c)
  1126. {
  1127. temp=
  1128. cmSystemTools::ConvertToOutputPath(c->second.m_Command.c_str());
  1129. totalCommandStr += temp;
  1130. totalCommandStr += " ";
  1131. totalCommandStr += c->second.m_Arguments;
  1132. totalCommand.Merge(c->second);
  1133. }
  1134. // Create a dummy file with the name of the source if it does
  1135. // not exist
  1136. if(totalCommand.m_Outputs.empty())
  1137. {
  1138. std::string dummyFile = m_Makefile->GetStartOutputDirectory();
  1139. dummyFile += "/";
  1140. dummyFile += source;
  1141. if(!cmSystemTools::FileExists(dummyFile.c_str()))
  1142. {
  1143. std::ofstream fout(dummyFile.c_str());
  1144. fout << "Dummy file created by cmake as unused source for utility command.\n";
  1145. }
  1146. }
  1147. return totalCommandStr;
  1148. }
  1149. // look for custom rules on a target and collect them together
  1150. void cmMSDotNETGenerator::OutputTargetRules(std::ostream& fout,
  1151. const cmTarget &target,
  1152. const char *libName)
  1153. {
  1154. if (target.GetType() >= cmTarget::UTILITY)
  1155. {
  1156. return;
  1157. }
  1158. // Find the group in which the lix exe custom rules belong
  1159. bool init = false;
  1160. for (std::vector<cmCustomCommand>::const_iterator cr =
  1161. target.GetCustomCommands().begin();
  1162. cr != target.GetCustomCommands().end(); ++cr)
  1163. {
  1164. cmCustomCommand cc(*cr);
  1165. cc.ExpandVariables(*m_Makefile);
  1166. if (cc.GetSourceName() == libName)
  1167. {
  1168. if(!init)
  1169. {
  1170. fout << "\nCommandLine=\"";
  1171. init = true;
  1172. }
  1173. fout << cc.GetCommand() << " " << cc.GetArguments() << "\n";
  1174. }
  1175. }
  1176. if (init)
  1177. {
  1178. fout << "\"";
  1179. }
  1180. }
  1181. void cmMSDotNETGenerator::WriteProjectStart(std::ostream& fout, const char *libName,
  1182. const cmTarget &,
  1183. std::vector<cmSourceGroup> &)
  1184. {
  1185. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1186. << "<VisualStudioProject\n"
  1187. << "\tProjectType=\"Visual C++\"\n"
  1188. << "\tVersion=\"7.00\"\n"
  1189. << "\tName=\"" << libName << "\"\n"
  1190. << "\tSccProjectName=\"\"\n"
  1191. << "\tSccLocalPath=\"\"\n"
  1192. << "\tKeyword=\"Win32Proj\">\n"
  1193. << "\t<Platforms>\n"
  1194. << "\t\t<Platform\n\t\t\tName=\"Win32\"/>\n"
  1195. << "\t</Platforms>\n";
  1196. }
  1197. void cmMSDotNETGenerator::WriteVCProjFooter(std::ostream& fout)
  1198. {
  1199. fout << "\t<Globals>\n"
  1200. << "\t</Globals>\n"
  1201. << "</VisualStudioProject>\n";
  1202. }
  1203. std::string cmMSDotNETGenerator::ConvertToXMLOutputPath(const char* path)
  1204. {
  1205. std::string ret = cmSystemTools::ConvertToOutputPath(path);
  1206. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1207. return ret;
  1208. }