cmMSDotNETGenerator.cxx 42 KB

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