cmMSDotNETGenerator.cxx 39 KB

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