cmLocalVisualStudio6Generator.cxx 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmGlobalGenerator.h"
  14. #include "cmLocalVisualStudio6Generator.h"
  15. #include "cmMakefile.h"
  16. #include "cmSystemTools.h"
  17. #include "cmSourceFile.h"
  18. #include "cmCacheManager.h"
  19. #include "cmake.h"
  20. #include <cmsys/RegularExpression.hxx>
  21. cmLocalVisualStudio6Generator::cmLocalVisualStudio6Generator()
  22. {
  23. }
  24. cmLocalVisualStudio6Generator::~cmLocalVisualStudio6Generator()
  25. {
  26. }
  27. void cmLocalVisualStudio6Generator::Generate()
  28. {
  29. std::set<cmStdString> lang;
  30. lang.insert("C");
  31. lang.insert("CXX");
  32. this->CreateCustomTargetsAndCommands(lang);
  33. this->OutputDSPFile();
  34. }
  35. void cmLocalVisualStudio6Generator::OutputDSPFile()
  36. {
  37. // If not an in source build, then create the output directory
  38. if(strcmp(m_Makefile->GetStartOutputDirectory(),
  39. m_Makefile->GetHomeDirectory()) != 0)
  40. {
  41. if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
  42. {
  43. cmSystemTools::Error("Error creating directory ",
  44. m_Makefile->GetStartOutputDirectory());
  45. }
  46. }
  47. // Setup /I and /LIBPATH options for the resulting DSP file
  48. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  49. std::vector<std::string>::iterator i;
  50. for(i = includes.begin(); i != includes.end(); ++i)
  51. {
  52. m_IncludeOptions += " /I ";
  53. std::string tmp = this->ConvertToOptionallyRelativeOutputPath(i->c_str());
  54. // quote if not already quoted
  55. if (tmp[0] != '"')
  56. {
  57. m_IncludeOptions += "\"";
  58. m_IncludeOptions += tmp;
  59. m_IncludeOptions += "\"";
  60. }
  61. else
  62. {
  63. m_IncludeOptions += tmp;
  64. }
  65. }
  66. // Create the DSP or set of DSP's for libraries and executables
  67. // clear project names
  68. m_CreatedProjectNames.clear();
  69. // Call TraceVSDependencies on all targets
  70. cmTargets &tgts = m_Makefile->GetTargets();
  71. for(cmTargets::iterator l = tgts.begin();
  72. l != tgts.end(); l++)
  73. {
  74. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  75. // so don't build a projectfile for it
  76. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  77. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)
  78. && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0))
  79. {
  80. cmTarget& target = l->second;
  81. target.TraceVSDependencies(target.GetName(), m_Makefile);
  82. }
  83. }
  84. // now for all custom commands that are not used directly in a
  85. // target, add them to all targets in the current directory or
  86. // makefile
  87. std::vector<cmSourceFile*> & classesmf = m_Makefile->GetSourceFiles();
  88. for(std::vector<cmSourceFile*>::const_iterator i = classesmf.begin();
  89. i != classesmf.end(); i++)
  90. {
  91. if(cmCustomCommand* cc = (*i)->GetCustomCommand())
  92. {
  93. if(!cc->IsUsed())
  94. {
  95. for(cmTargets::iterator l = tgts.begin();
  96. l != tgts.end(); l++)
  97. {
  98. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  99. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)
  100. && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0))
  101. {
  102. cmTarget& target = l->second;
  103. bool sameAsTarget = false;
  104. // make sure we don't add a custom command that depends on
  105. // this target
  106. for(unsigned int k =0; k < cc->GetDepends().size(); k++)
  107. {
  108. if(cmSystemTools::GetFilenameName(cc->GetDepends()[k]) == target.GetFullName())
  109. {
  110. sameAsTarget = true;
  111. }
  112. }
  113. if(!sameAsTarget)
  114. {
  115. target.GetSourceFiles().push_back(*i);
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. // build any targets
  123. for(cmTargets::iterator l = tgts.begin();
  124. l != tgts.end(); l++)
  125. {
  126. switch(l->second.GetType())
  127. {
  128. case cmTarget::STATIC_LIBRARY:
  129. this->SetBuildType(STATIC_LIBRARY, l->first.c_str(), l->second);
  130. break;
  131. case cmTarget::SHARED_LIBRARY:
  132. case cmTarget::MODULE_LIBRARY:
  133. this->SetBuildType(DLL, l->first.c_str(), l->second);
  134. break;
  135. case cmTarget::EXECUTABLE:
  136. this->SetBuildType(EXECUTABLE,l->first.c_str(), l->second);
  137. break;
  138. case cmTarget::UTILITY:
  139. this->SetBuildType(UTILITY, l->first.c_str(), l->second);
  140. break;
  141. case cmTarget::INSTALL_FILES:
  142. break;
  143. case cmTarget::INSTALL_PROGRAMS:
  144. break;
  145. default:
  146. cmSystemTools::Error("Bad target type", l->first.c_str());
  147. break;
  148. }
  149. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  150. // so don't build a projectfile for it
  151. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  152. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)
  153. && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0))
  154. {
  155. // check to see if the dsp is going into a sub-directory
  156. std::string::size_type pos = l->first.rfind('/');
  157. if(pos != std::string::npos)
  158. {
  159. std::string dir = m_Makefile->GetStartOutputDirectory();
  160. dir += "/";
  161. dir += l->first.substr(0, pos);
  162. if(!cmSystemTools::MakeDirectory(dir.c_str()))
  163. {
  164. cmSystemTools::Error("Error creating directory ", dir.c_str());
  165. }
  166. }
  167. this->CreateSingleDSP(l->first.c_str(),l->second);
  168. }
  169. }
  170. }
  171. void cmLocalVisualStudio6Generator::CreateSingleDSP(const char *lname, cmTarget &target)
  172. {
  173. // add to the list of projects
  174. std::string pname = lname;
  175. m_CreatedProjectNames.push_back(pname);
  176. // create the dsp.cmake file
  177. std::string fname;
  178. fname = m_Makefile->GetStartOutputDirectory();
  179. fname += "/";
  180. fname += lname;
  181. fname += ".dsp";
  182. // save the name of the real dsp file
  183. std::string realDSP = fname;
  184. fname += ".cmake";
  185. std::ofstream fout(fname.c_str());
  186. if(!fout)
  187. {
  188. cmSystemTools::Error("Error Writing ", fname.c_str());
  189. cmSystemTools::ReportLastSystemError("");
  190. }
  191. this->WriteDSPFile(fout,lname,target);
  192. fout.close();
  193. // if the dsp file has changed, then write it.
  194. cmSystemTools::CopyFileIfDifferent(fname.c_str(), realDSP.c_str());
  195. }
  196. void cmLocalVisualStudio6Generator::AddDSPBuildRule()
  197. {
  198. std::string dspname = *(m_CreatedProjectNames.end()-1);
  199. dspname += ".dsp.cmake";
  200. const char* dsprule = m_Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  201. cmCustomCommandLine commandLine;
  202. commandLine.push_back(dsprule);
  203. std::string makefileIn = m_Makefile->GetStartDirectory();
  204. makefileIn += "/";
  205. makefileIn += "CMakeLists.txt";
  206. std::string args;
  207. args = "-H";
  208. args +=
  209. this->Convert(m_Makefile->GetHomeDirectory(),START_OUTPUT, SHELL, true);
  210. commandLine.push_back(args);
  211. args = "-B";
  212. args +=
  213. this->Convert(m_Makefile->GetHomeOutputDirectory(),
  214. START_OUTPUT, SHELL, true);
  215. commandLine.push_back(args);
  216. std::string configFile =
  217. m_Makefile->GetRequiredDefinition("CMAKE_ROOT");
  218. configFile += "/Templates/CMakeWindowsSystemConfig.cmake";
  219. std::vector<std::string> listFiles = m_Makefile->GetListFiles();
  220. bool found = false;
  221. for(std::vector<std::string>::iterator i = listFiles.begin();
  222. i != listFiles.end(); ++i)
  223. {
  224. if(*i == configFile)
  225. {
  226. found = true;
  227. }
  228. }
  229. if(!found)
  230. {
  231. listFiles.push_back(configFile);
  232. }
  233. cmCustomCommandLines commandLines;
  234. commandLines.push_back(commandLine);
  235. const char* no_comment = 0;
  236. const char* no_working_directory = 0;
  237. m_Makefile->AddCustomCommandToOutput(dspname.c_str(), listFiles, makefileIn.c_str(),
  238. commandLines, no_comment, no_working_directory, true);
  239. }
  240. void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
  241. const char *libName,
  242. cmTarget &target)
  243. {
  244. // if we should add regen rule then...
  245. const char *suppRegenRule =
  246. m_Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  247. if (!cmSystemTools::IsOn(suppRegenRule))
  248. {
  249. this->AddDSPBuildRule();
  250. }
  251. // For utility targets need custom command since pre- and post-
  252. // build does not do anything in Visual Studio 6. In order for the
  253. // rules to run in the correct order as custom commands, we need
  254. // special care for dependencies. The first rule must depend on all
  255. // the dependencies of all the rules. The later rules must each
  256. // depend only on the previous rule.
  257. if (target.GetType() == cmTarget::UTILITY &&
  258. (!target.GetPreBuildCommands().empty() ||
  259. !target.GetPostBuildCommands().empty()))
  260. {
  261. // Accumulate the dependencies of all the commands.
  262. std::vector<std::string> depends;
  263. for (std::vector<cmCustomCommand>::const_iterator cr =
  264. target.GetPreBuildCommands().begin();
  265. cr != target.GetPreBuildCommands().end(); ++cr)
  266. {
  267. depends.insert(depends.end(),
  268. cr->GetDepends().begin(), cr->GetDepends().end());
  269. }
  270. for (std::vector<cmCustomCommand>::const_iterator cr =
  271. target.GetPostBuildCommands().begin();
  272. cr != target.GetPostBuildCommands().end(); ++cr)
  273. {
  274. depends.insert(depends.end(),
  275. cr->GetDepends().begin(), cr->GetDepends().end());
  276. }
  277. // Add the pre- and post-build commands in order.
  278. int count = 1;
  279. for (std::vector<cmCustomCommand>::const_iterator cr =
  280. target.GetPreBuildCommands().begin();
  281. cr != target.GetPreBuildCommands().end(); ++cr)
  282. {
  283. this->AddUtilityCommandHack(target, count++, depends, *cr);
  284. }
  285. for (std::vector<cmCustomCommand>::const_iterator cr =
  286. target.GetPostBuildCommands().begin();
  287. cr != target.GetPostBuildCommands().end(); ++cr)
  288. {
  289. this->AddUtilityCommandHack(target, count++, depends, *cr);
  290. }
  291. }
  292. // trace the visual studio dependencies
  293. std::string name = libName;
  294. name += ".dsp.cmake";
  295. // We may be modifying the source groups temporarily, so make a copy.
  296. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  297. // get the classes from the source lists then add them to the groups
  298. std::vector<cmSourceFile*> & classes = target.GetSourceFiles();
  299. // now all of the source files have been properly assigned to the target
  300. // now stick them into source groups using the reg expressions
  301. for(std::vector<cmSourceFile*>::iterator i = classes.begin();
  302. i != classes.end(); i++)
  303. {
  304. // Add the file to the list of sources.
  305. std::string source = (*i)->GetFullPath();
  306. cmSourceGroup& sourceGroup = m_Makefile->FindSourceGroup(source.c_str(),
  307. sourceGroups);
  308. sourceGroup.AssignSource(*i);
  309. // while we are at it, if it is a .rule file then for visual studio 6 we
  310. // must generate it
  311. if ((*i)->GetSourceExtension() == "rule")
  312. {
  313. if(!cmSystemTools::FileExists(source.c_str()))
  314. {
  315. cmSystemTools::ReplaceString(source, "$(IntDir)/", "");
  316. #if defined(_WIN32) || defined(__CYGWIN__)
  317. std::ofstream fout(source.c_str(),
  318. std::ios::binary | std::ios::out | std::ios::trunc);
  319. #else
  320. std::ofstream fout(source.c_str(),
  321. std::ios::out | std::ios::trunc);
  322. #endif
  323. if(fout)
  324. {
  325. fout.write("# generated from CMake",22);
  326. fout.flush();
  327. fout.close();
  328. }
  329. }
  330. }
  331. }
  332. // Write the DSP file's header.
  333. this->WriteDSPHeader(fout, libName, target, sourceGroups);
  334. // Loop through every source group.
  335. for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
  336. sg != sourceGroups.end(); ++sg)
  337. {
  338. this->WriteGroup(&(*sg), target, fout, libName);
  339. }
  340. // Write the DSP file's footer.
  341. this->WriteDSPFooter(fout);
  342. }
  343. void cmLocalVisualStudio6Generator::WriteGroup(const cmSourceGroup *sg, cmTarget target, std::ostream &fout, const char *libName)
  344. {
  345. const std::vector<const cmSourceFile *> &sourceFiles =
  346. sg->GetSourceFiles();
  347. // If the group is empty, don't write it at all.
  348. if(sourceFiles.empty())
  349. {
  350. return;
  351. }
  352. // If the group has a name, write the header.
  353. std::string name = sg->GetName();
  354. if(name != "")
  355. {
  356. this->WriteDSPBeginGroup(fout, name.c_str(), "");
  357. }
  358. // Loop through each source in the source group.
  359. for(std::vector<const cmSourceFile *>::const_iterator sf =
  360. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  361. {
  362. std::string source = (*sf)->GetFullPath();
  363. const cmCustomCommand *command =
  364. (*sf)->GetCustomCommand();
  365. std::string compileFlags;
  366. std::vector<std::string> depends;
  367. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  368. if(cflags)
  369. {
  370. compileFlags = cflags;
  371. }
  372. if(target.GetProperty("COMPILE_FLAGS"))
  373. {
  374. compileFlags += " ";
  375. compileFlags += target.GetProperty("COMPILE_FLAGS");
  376. }
  377. const char* lang =
  378. m_GlobalGenerator->GetLanguageFromExtension((*sf)->GetSourceExtension().c_str());
  379. if(lang && strcmp(lang, "CXX") == 0)
  380. {
  381. // force a C++ file type
  382. compileFlags += " /TP ";
  383. }
  384. // Check for extra object-file dependencies.
  385. const char* dependsValue = (*sf)->GetProperty("OBJECT_DEPENDS");
  386. if(dependsValue)
  387. {
  388. cmSystemTools::ExpandListArgument(dependsValue, depends);
  389. }
  390. if (source != libName || target.GetType() == cmTarget::UTILITY)
  391. {
  392. fout << "# Begin Source File\n\n";
  393. // Tell MS-Dev what the source is. If the compiler knows how to
  394. // build it, then it will.
  395. fout << "SOURCE=" <<
  396. this->ConvertToOptionallyRelativeOutputPath(source.c_str()) << "\n\n";
  397. if(!depends.empty())
  398. {
  399. // Write out the dependencies for the rule.
  400. fout << "USERDEP__HACK=";
  401. for(std::vector<std::string>::const_iterator d = depends.begin();
  402. d != depends.end(); ++d)
  403. {
  404. fout << "\\\n\t" <<
  405. this->ConvertToOptionallyRelativeOutputPath(d->c_str());
  406. }
  407. fout << "\n";
  408. }
  409. if (command)
  410. {
  411. std::string script =
  412. this->ConstructScript(command->GetCommandLines(),
  413. command->GetWorkingDirectory(),
  414. "\\\n\t");
  415. const char* comment = command->GetComment();
  416. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  417. this->WriteCustomRule(fout, source.c_str(), script.c_str(),
  418. (*comment?comment:"Custom Rule"),
  419. command->GetDepends(),
  420. command->GetOutput(), flags);
  421. }
  422. else if(compileFlags.size())
  423. {
  424. for(std::vector<std::string>::iterator i
  425. = m_Configurations.begin(); i != m_Configurations.end(); ++i)
  426. {
  427. if (i == m_Configurations.begin())
  428. {
  429. fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl;
  430. }
  431. else
  432. {
  433. fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl;
  434. }
  435. fout << "\n# ADD CPP " << compileFlags << "\n\n";
  436. }
  437. fout << "!ENDIF\n\n";
  438. }
  439. fout << "# End Source File\n";
  440. }
  441. }
  442. std::vector<cmSourceGroup> children = sg->GetGroupChildren();
  443. for(unsigned int i=0;i<children.size();++i)
  444. {
  445. this->WriteGroup(&children[i], target, fout, libName);
  446. }
  447. // If the group has a name, write the footer.
  448. if(name != "")
  449. {
  450. this->WriteDSPEndGroup(fout);
  451. }
  452. }
  453. void
  454. cmLocalVisualStudio6Generator
  455. ::AddUtilityCommandHack(cmTarget& target, int count,
  456. std::vector<std::string>& depends,
  457. const cmCustomCommand& origCommand)
  458. {
  459. // Create a fake output that forces the rule to run.
  460. char* output = new char[(strlen(m_Makefile->GetStartOutputDirectory()) +
  461. strlen(target.GetName()) + 30)];
  462. sprintf(output,"%s/%s_force_%i", m_Makefile->GetStartOutputDirectory(),
  463. target.GetName(), count);
  464. // Add the rule with the given dependencies and commands.
  465. const char* no_main_dependency = 0;
  466. const char* no_comment = 0;
  467. const char* no_working_directory = 0;
  468. m_Makefile->AddCustomCommandToOutput(output,
  469. depends,
  470. no_main_dependency,
  471. origCommand.GetCommandLines(),
  472. origCommand.GetComment(),
  473. origCommand.GetWorkingDirectory());
  474. // Replace the dependencies with the output of this rule so that the
  475. // next rule added will run after this one.
  476. depends.clear();
  477. depends.push_back(output);
  478. // Add a source file representing this output to the project.
  479. cmSourceFile* outsf = m_Makefile->GetSourceFileWithOutput(output);
  480. target.GetSourceFiles().push_back(outsf);
  481. // Free the fake output name.
  482. delete [] output;
  483. }
  484. void cmLocalVisualStudio6Generator::WriteCustomRule(std::ostream& fout,
  485. const char* source,
  486. const char* command,
  487. const char* comment,
  488. const std::vector<std::string>& depends,
  489. const char *output,
  490. const char* flags
  491. )
  492. {
  493. std::vector<std::string>::iterator i;
  494. for(i = m_Configurations.begin(); i != m_Configurations.end(); ++i)
  495. {
  496. if (i == m_Configurations.begin())
  497. {
  498. fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl;
  499. }
  500. else
  501. {
  502. fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl;
  503. }
  504. if(flags)
  505. {
  506. fout << "\n# ADD CPP " << flags << "\n\n";
  507. }
  508. // Write out the dependencies for the rule.
  509. fout << "USERDEP__HACK=";
  510. for(std::vector<std::string>::const_iterator d = depends.begin();
  511. d != depends.end(); ++d)
  512. {
  513. // Lookup the real name of the dependency in case it is a CMake target.
  514. std::string dep = this->GetRealDependency(d->c_str(), i->c_str());
  515. fout << "\\\n\t" <<
  516. this->ConvertToOptionallyRelativeOutputPath(dep.c_str());
  517. }
  518. fout << "\n";
  519. fout << "# PROP Ignore_Default_Tool 1\n";
  520. fout << "# Begin Custom Build - Building " << comment
  521. << " $(InputPath)\n\n";
  522. if(output == 0)
  523. {
  524. fout << source << "_force : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
  525. fout << command << "\n\n";
  526. }
  527. // Write a rule for every output generated by this command.
  528. fout << this->ConvertToOptionallyRelativeOutputPath(output)
  529. << " : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
  530. fout << command << "\n\n";
  531. fout << "# End Custom Build\n\n";
  532. }
  533. fout << "!ENDIF\n\n";
  534. }
  535. void cmLocalVisualStudio6Generator::WriteDSPBeginGroup(std::ostream& fout,
  536. const char* group,
  537. const char* filter)
  538. {
  539. fout << "# Begin Group \"" << group << "\"\n"
  540. "# PROP Default_Filter \"" << filter << "\"\n";
  541. }
  542. void cmLocalVisualStudio6Generator::WriteDSPEndGroup(std::ostream& fout)
  543. {
  544. fout << "# End Group\n";
  545. }
  546. void cmLocalVisualStudio6Generator::SetBuildType(BuildType b,
  547. const char* libName,
  548. cmTarget& target)
  549. {
  550. std::string root= m_Makefile->GetRequiredDefinition("CMAKE_ROOT");
  551. const char *def= m_Makefile->GetDefinition( "MSPROJECT_TEMPLATE_DIRECTORY");
  552. if( def)
  553. {
  554. root = def;
  555. }
  556. else
  557. {
  558. root += "/Templates";
  559. }
  560. switch(b)
  561. {
  562. case STATIC_LIBRARY:
  563. m_DSPHeaderTemplate = root;
  564. m_DSPHeaderTemplate += "/staticLibHeader.dsptemplate";
  565. m_DSPFooterTemplate = root;
  566. m_DSPFooterTemplate += "/staticLibFooter.dsptemplate";
  567. break;
  568. case DLL:
  569. m_DSPHeaderTemplate = root;
  570. m_DSPHeaderTemplate += "/DLLHeader.dsptemplate";
  571. m_DSPFooterTemplate = root;
  572. m_DSPFooterTemplate += "/DLLFooter.dsptemplate";
  573. break;
  574. case EXECUTABLE:
  575. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  576. {
  577. m_DSPHeaderTemplate = root;
  578. m_DSPHeaderTemplate += "/EXEWinHeader.dsptemplate";
  579. m_DSPFooterTemplate = root;
  580. m_DSPFooterTemplate += "/EXEFooter.dsptemplate";
  581. }
  582. else
  583. {
  584. m_DSPHeaderTemplate = root;
  585. m_DSPHeaderTemplate += "/EXEHeader.dsptemplate";
  586. m_DSPFooterTemplate = root;
  587. m_DSPFooterTemplate += "/EXEFooter.dsptemplate";
  588. }
  589. break;
  590. case UTILITY:
  591. m_DSPHeaderTemplate = root;
  592. m_DSPHeaderTemplate += "/UtilityHeader.dsptemplate";
  593. m_DSPFooterTemplate = root;
  594. m_DSPFooterTemplate += "/UtilityFooter.dsptemplate";
  595. break;
  596. }
  597. // once the build type is set, determine what configurations are
  598. // possible
  599. std::ifstream fin(m_DSPHeaderTemplate.c_str());
  600. cmsys::RegularExpression reg("# Name ");
  601. if(!fin)
  602. {
  603. cmSystemTools::Error("Error Reading ", m_DSPHeaderTemplate.c_str());
  604. }
  605. // reset m_Configurations
  606. m_Configurations.erase(m_Configurations.begin(), m_Configurations.end());
  607. // now add all the configurations possible
  608. std::string line;
  609. while(cmSystemTools::GetLineFromStream(fin, line))
  610. {
  611. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",libName);
  612. if (reg.find(line))
  613. {
  614. m_Configurations.push_back(line.substr(reg.end()));
  615. }
  616. }
  617. }
  618. // look for custom rules on a target and collect them together
  619. std::string
  620. cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target,
  621. const char * /* libName */)
  622. {
  623. std::string customRuleCode = "";
  624. if (target.GetType() >= cmTarget::UTILITY)
  625. {
  626. return customRuleCode;
  627. }
  628. // are there any rules?
  629. if (target.GetPreBuildCommands().size() +
  630. target.GetPreLinkCommands().size() +
  631. target.GetPostBuildCommands().size() == 0)
  632. {
  633. return customRuleCode;
  634. }
  635. customRuleCode = "# Begin Special Build Tool\n";
  636. // Write the pre-build and pre-link together (VS6 does not support
  637. // both). Make sure no continuation character is put on the last
  638. // line.
  639. int prelink_total = (static_cast<int>(target.GetPreBuildCommands().size())+
  640. static_cast<int>(target.GetPreLinkCommands().size()));
  641. int prelink_count = 0;
  642. if(prelink_total > 0)
  643. {
  644. // header stuff
  645. customRuleCode += "PreLink_Cmds=";
  646. }
  647. const char* prelink_newline = "\\\n\t";
  648. for (std::vector<cmCustomCommand>::const_iterator cr =
  649. target.GetPreBuildCommands().begin();
  650. cr != target.GetPreBuildCommands().end(); ++cr)
  651. {
  652. if(++prelink_count == prelink_total)
  653. {
  654. prelink_newline = "";
  655. }
  656. customRuleCode += this->ConstructScript(cr->GetCommandLines(),
  657. cr->GetWorkingDirectory(),
  658. prelink_newline);
  659. }
  660. for (std::vector<cmCustomCommand>::const_iterator cr =
  661. target.GetPreLinkCommands().begin();
  662. cr != target.GetPreLinkCommands().end(); ++cr)
  663. {
  664. if(++prelink_count == prelink_total)
  665. {
  666. prelink_newline = "";
  667. }
  668. customRuleCode += this->ConstructScript(cr->GetCommandLines(),
  669. cr->GetWorkingDirectory(),
  670. prelink_newline);
  671. }
  672. if(prelink_total > 0)
  673. {
  674. customRuleCode += "\n";
  675. }
  676. // Write the post-build rules. Make sure no continuation character
  677. // is put on the last line.
  678. int postbuild_total = static_cast<int>(target.GetPostBuildCommands().size());
  679. int postbuild_count = 0;
  680. const char* postbuild_newline = "\\\n\t";
  681. if(postbuild_total > 0)
  682. {
  683. customRuleCode += "PostBuild_Cmds=";
  684. }
  685. for (std::vector<cmCustomCommand>::const_iterator cr =
  686. target.GetPostBuildCommands().begin();
  687. cr != target.GetPostBuildCommands().end(); ++cr)
  688. {
  689. if(++postbuild_count == postbuild_total)
  690. {
  691. postbuild_newline = "";
  692. }
  693. customRuleCode += this->ConstructScript(cr->GetCommandLines(),
  694. cr->GetWorkingDirectory(),
  695. postbuild_newline);
  696. }
  697. if(postbuild_total > 0)
  698. {
  699. customRuleCode += "\n";
  700. }
  701. customRuleCode += "# End Special Build Tool\n";
  702. return customRuleCode;
  703. }
  704. inline std::string removeQuotes(const std::string& s)
  705. {
  706. if(s[0] == '\"' && s[s.size()-1] == '\"')
  707. {
  708. return s.substr(1, s.size()-2);
  709. }
  710. return s;
  711. }
  712. void cmLocalVisualStudio6Generator
  713. ::WriteDSPHeader(std::ostream& fout,
  714. const char *libName, cmTarget &target,
  715. std::vector<cmSourceGroup> &)
  716. {
  717. std::set<std::string> pathEmitted;
  718. // determine the link directories
  719. std::string libOptions;
  720. std::string libDebugOptions;
  721. std::string libOptimizedOptions;
  722. std::string libMultiLineOptions;
  723. std::string libMultiLineOptionsForDebug;
  724. std::string libMultiLineDebugOptions;
  725. std::string libMultiLineOptimizedOptions;
  726. // suppoirt override in output directory
  727. std::string libPath = "";
  728. if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  729. {
  730. libPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  731. }
  732. std::string exePath = "";
  733. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  734. {
  735. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  736. }
  737. if(libPath.size())
  738. {
  739. // make sure there is a trailing slash
  740. if(libPath[libPath.size()-1] != '/')
  741. {
  742. libPath += "/";
  743. }
  744. std::string lpath =
  745. this->ConvertToOptionallyRelativeOutputPath(libPath.c_str());
  746. if(lpath.size() == 0)
  747. {
  748. lpath = ".";
  749. }
  750. std::string lpathIntDir = libPath + "$(INTDIR)";
  751. lpathIntDir = this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
  752. if(pathEmitted.insert(lpath).second)
  753. {
  754. libOptions += " /LIBPATH:";
  755. libOptions += lpathIntDir;
  756. libOptions += " ";
  757. libOptions += " /LIBPATH:";
  758. libOptions += lpath;
  759. libOptions += " ";
  760. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  761. libMultiLineOptions += lpathIntDir;
  762. libMultiLineOptions += " ";
  763. libMultiLineOptions += " /LIBPATH:";
  764. libMultiLineOptions += lpath;
  765. libMultiLineOptions += " \n";
  766. libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
  767. libMultiLineOptionsForDebug += lpathIntDir;
  768. libMultiLineOptionsForDebug += " ";
  769. libMultiLineOptionsForDebug += " /LIBPATH:";
  770. libMultiLineOptionsForDebug += lpath;
  771. libMultiLineOptionsForDebug += " \n";
  772. }
  773. }
  774. if(exePath.size())
  775. {
  776. // make sure there is a trailing slash
  777. if(exePath[exePath.size()-1] != '/')
  778. {
  779. exePath += "/";
  780. }
  781. std::string lpath =
  782. this->ConvertToOptionallyRelativeOutputPath(exePath.c_str());
  783. if(lpath.size() == 0)
  784. {
  785. lpath = ".";
  786. }
  787. std::string lpathIntDir = exePath + "$(INTDIR)";
  788. lpathIntDir = this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
  789. if(pathEmitted.insert(lpath).second)
  790. {
  791. libOptions += " /LIBPATH:";
  792. libOptions += lpathIntDir;
  793. libOptions += " ";
  794. libOptions += " /LIBPATH:";
  795. libOptions += lpath;
  796. libOptions += " ";
  797. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  798. libMultiLineOptions += lpathIntDir;
  799. libMultiLineOptions += " ";
  800. libMultiLineOptions += " /LIBPATH:";
  801. libMultiLineOptions += lpath;
  802. libMultiLineOptions += " \n";
  803. libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
  804. libMultiLineOptionsForDebug += lpathIntDir;
  805. libMultiLineOptionsForDebug += " ";
  806. libMultiLineOptionsForDebug += " /LIBPATH:";
  807. libMultiLineOptionsForDebug += lpath;
  808. libMultiLineOptionsForDebug += " \n";
  809. }
  810. }
  811. std::vector<std::string>::const_iterator i;
  812. const std::vector<std::string>& libdirs = target.GetLinkDirectories();
  813. for(i = libdirs.begin(); i != libdirs.end(); ++i)
  814. {
  815. std::string path = *i;
  816. if(path[path.size()-1] != '/')
  817. {
  818. path += "/";
  819. }
  820. std::string lpath =
  821. this->ConvertToOptionallyRelativeOutputPath(path.c_str());
  822. if(lpath.size() == 0)
  823. {
  824. lpath = ".";
  825. }
  826. std::string lpathIntDir = path + "$(INTDIR)";
  827. lpathIntDir = this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
  828. if(pathEmitted.insert(lpath).second)
  829. {
  830. libOptions += " /LIBPATH:";
  831. libOptions += lpathIntDir;
  832. libOptions += " ";
  833. libOptions += " /LIBPATH:";
  834. libOptions += lpath;
  835. libOptions += " ";
  836. libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
  837. libMultiLineOptions += lpathIntDir;
  838. libMultiLineOptions += " ";
  839. libMultiLineOptions += " /LIBPATH:";
  840. libMultiLineOptions += lpath;
  841. libMultiLineOptions += " \n";
  842. libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
  843. libMultiLineOptionsForDebug += lpathIntDir;
  844. libMultiLineOptionsForDebug += " ";
  845. libMultiLineOptionsForDebug += " /LIBPATH:";
  846. libMultiLineOptionsForDebug += lpath;
  847. libMultiLineOptionsForDebug += " \n";
  848. }
  849. }
  850. // find link libraries
  851. const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
  852. cmTarget::LinkLibraries::const_iterator j;
  853. for(j = libs.begin(); j != libs.end(); ++j)
  854. {
  855. // add libraries to executables and dlls (but never include
  856. // a library in a library, bad recursion)
  857. // NEVER LINK STATIC LIBRARIES TO OTHER STATIC LIBRARIES
  858. if ((target.GetType() != cmTarget::SHARED_LIBRARY
  859. && target.GetType() != cmTarget::STATIC_LIBRARY
  860. && target.GetType() != cmTarget::MODULE_LIBRARY) ||
  861. (target.GetType()==cmTarget::SHARED_LIBRARY && libName != j->first) ||
  862. (target.GetType()==cmTarget::MODULE_LIBRARY && libName != j->first))
  863. {
  864. // Compute the proper name to use to link this library.
  865. std::string lib;
  866. std::string libDebug;
  867. cmTarget* tgt = m_GlobalGenerator->FindTarget(0, j->first.c_str());
  868. if(tgt)
  869. {
  870. lib = cmSystemTools::GetFilenameWithoutExtension(tgt->GetFullName().c_str());
  871. libDebug = cmSystemTools::GetFilenameWithoutExtension(tgt->GetFullName("Debug").c_str());
  872. lib += ".lib";
  873. libDebug += ".lib";
  874. }
  875. else
  876. {
  877. lib = j->first.c_str();
  878. libDebug = j->first.c_str();
  879. if(j->first.find(".lib") == std::string::npos)
  880. {
  881. lib += ".lib";
  882. libDebug += ".lib";
  883. }
  884. }
  885. lib = this->ConvertToOptionallyRelativeOutputPath(lib.c_str());
  886. libDebug = this->ConvertToOptionallyRelativeOutputPath(libDebug.c_str());
  887. if (j->second == cmTarget::GENERAL)
  888. {
  889. libOptions += " ";
  890. libOptions += lib;
  891. libMultiLineOptions += "# ADD LINK32 ";
  892. libMultiLineOptions += lib;
  893. libMultiLineOptions += "\n";
  894. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  895. libMultiLineOptionsForDebug += libDebug;
  896. libMultiLineOptionsForDebug += "\n";
  897. }
  898. if (j->second == cmTarget::DEBUG)
  899. {
  900. libDebugOptions += " ";
  901. libDebugOptions += lib;
  902. libMultiLineDebugOptions += "# ADD LINK32 ";
  903. libMultiLineDebugOptions += libDebug;
  904. libMultiLineDebugOptions += "\n";
  905. }
  906. if (j->second == cmTarget::OPTIMIZED)
  907. {
  908. libOptimizedOptions += " ";
  909. libOptimizedOptions += lib;
  910. libMultiLineOptimizedOptions += "# ADD LINK32 ";
  911. libMultiLineOptimizedOptions += lib;
  912. libMultiLineOptimizedOptions += "\n";
  913. }
  914. }
  915. }
  916. std::string outputName = "(OUTPUT_NAME is for executables only)";
  917. std::string extraLinkOptions;
  918. // TODO: Fix construction of library/executable name through
  919. // cmTarget. OUTPUT_LIBNAMEDEBUG_POSTFIX should be replaced by the
  920. // library's debug configuration name. OUTPUT_LIBNAME should be
  921. // replaced by the non-debug configuration name. This generator
  922. // should just be re-written to not use template files and just
  923. // generate the code. Setting up these substitutions is a pain.
  924. if(target.GetType() == cmTarget::EXECUTABLE)
  925. {
  926. extraLinkOptions =
  927. m_Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
  928. // Use the OUTPUT_NAME property if it was set. This is supported
  929. // only for executables.
  930. if(const char* outName = target.GetProperty("OUTPUT_NAME"))
  931. {
  932. outputName = outName;
  933. }
  934. else
  935. {
  936. outputName = target.GetName();
  937. }
  938. outputName += ".exe";
  939. }
  940. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  941. {
  942. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
  943. }
  944. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  945. {
  946. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
  947. }
  948. if(extraLinkOptions.size())
  949. {
  950. libOptions += " ";
  951. libOptions += extraLinkOptions;
  952. libOptions += " ";
  953. libMultiLineOptions += "# ADD LINK32 ";
  954. libMultiLineOptions += extraLinkOptions;
  955. libMultiLineOptions += " \n";
  956. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  957. libMultiLineOptionsForDebug += extraLinkOptions;
  958. libMultiLineOptionsForDebug += " \n";
  959. }
  960. if(const char* stdLibs = m_Makefile->GetDefinition("CMAKE_STANDARD_LIBRARIES"))
  961. {
  962. libOptions += " ";
  963. libOptions += stdLibs;
  964. libOptions += " ";
  965. libMultiLineOptions += "# ADD LINK32 ";
  966. libMultiLineOptions += stdLibs;
  967. libMultiLineOptions += " \n";
  968. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  969. libMultiLineOptionsForDebug += stdLibs;
  970. libMultiLineOptionsForDebug += " \n";
  971. }
  972. if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS"))
  973. {
  974. libOptions += " ";
  975. libOptions += targetLinkFlags;
  976. libOptions += " ";
  977. libMultiLineOptions += "# ADD LINK32 ";
  978. libMultiLineOptions += targetLinkFlags;
  979. libMultiLineOptions += " \n";
  980. libMultiLineOptionsForDebug += "# ADD LINK32 ";
  981. libMultiLineOptionsForDebug += targetLinkFlags;
  982. libMultiLineOptionsForDebug += " \n";
  983. }
  984. // are there any custom rules on the target itself
  985. // only if the target is a lib or exe
  986. std::string customRuleCode = this->CreateTargetRules(target, libName);
  987. std::ifstream fin(m_DSPHeaderTemplate.c_str());
  988. if(!fin)
  989. {
  990. cmSystemTools::Error("Error Reading ", m_DSPHeaderTemplate.c_str());
  991. }
  992. std::string staticLibOptions;
  993. if(target.GetType() == cmTarget::STATIC_LIBRARY )
  994. {
  995. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  996. {
  997. staticLibOptions = libflags;
  998. }
  999. }
  1000. std::string exportSymbol;
  1001. if (const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  1002. {
  1003. exportSymbol = custom_export_name;
  1004. }
  1005. else
  1006. {
  1007. std::string in = libName;
  1008. in += "_EXPORTS";
  1009. exportSymbol = cmSystemTools::MakeCindentifier(in.c_str());
  1010. }
  1011. std::string line;
  1012. while(cmSystemTools::GetLineFromStream(fin, line))
  1013. {
  1014. const char* mfcFlag = m_Makefile->GetDefinition("CMAKE_MFC_FLAG");
  1015. if(!mfcFlag)
  1016. {
  1017. mfcFlag = "0";
  1018. }
  1019. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME_EXPORTS",
  1020. exportSymbol.c_str());
  1021. cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE",
  1022. customRuleCode.c_str());
  1023. cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG",
  1024. mfcFlag);
  1025. if(target.GetType() == cmTarget::STATIC_LIBRARY )
  1026. {
  1027. cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS",
  1028. staticLibOptions.c_str());
  1029. }
  1030. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  1031. {
  1032. cmSystemTools::ReplaceString(line, "/nologo", "");
  1033. }
  1034. cmSystemTools::ReplaceString(line, "CM_LIBRARIES",
  1035. libOptions.c_str());
  1036. cmSystemTools::ReplaceString(line, "CM_DEBUG_LIBRARIES",
  1037. libDebugOptions.c_str());
  1038. cmSystemTools::ReplaceString(line, "CM_OPTIMIZED_LIBRARIES",
  1039. libOptimizedOptions.c_str());
  1040. cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES_FOR_DEBUG",
  1041. libMultiLineOptionsForDebug.c_str());
  1042. cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES",
  1043. libMultiLineOptions.c_str());
  1044. cmSystemTools::ReplaceString(line, "CM_MULTILINE_DEBUG_LIBRARIES",
  1045. libMultiLineDebugOptions.c_str());
  1046. cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIMIZED_LIBRARIES",
  1047. libMultiLineOptimizedOptions.c_str());
  1048. // Replace the template file text OUTPUT_NAME with the real output
  1049. // name that will be used. Only the executable template should
  1050. // have this text.
  1051. cmSystemTools::ReplaceString(line, "OUTPUT_NAME", outputName.c_str());
  1052. cmSystemTools::ReplaceString(line, "BUILD_INCLUDES",
  1053. m_IncludeOptions.c_str());
  1054. cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",libName);
  1055. // because LIBRARY_OUTPUT_PATH and EXECUTABLE_OUTPUT_PATH
  1056. // are already quoted in the template file,
  1057. // we need to remove the quotes here, we still need
  1058. // to convert to output path for unix to win32 conversion
  1059. cmSystemTools::ReplaceString(line, "LIBRARY_OUTPUT_PATH",
  1060. removeQuotes(
  1061. this->ConvertToOptionallyRelativeOutputPath(libPath.c_str())).c_str());
  1062. cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATH",
  1063. removeQuotes(
  1064. this->ConvertToOptionallyRelativeOutputPath(exePath.c_str())).c_str());
  1065. cmSystemTools::ReplaceString(line,
  1066. "EXTRA_DEFINES",
  1067. m_Makefile->GetDefineFlags());
  1068. const char* debugPostfix
  1069. = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  1070. cmSystemTools::ReplaceString(line, "DEBUG_POSTFIX",
  1071. debugPostfix?debugPostfix:"");
  1072. // store flags for each configuration
  1073. std::string flags = " ";
  1074. std::string flagsRelease = " ";
  1075. std::string flagsMinSize = " ";
  1076. std::string flagsDebug = " ";
  1077. std::string flagsDebugRel = " ";
  1078. if(target.GetType() >= cmTarget::EXECUTABLE &&
  1079. target.GetType() <= cmTarget::MODULE_LIBRARY)
  1080. {
  1081. const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator());
  1082. if(!linkLanguage)
  1083. {
  1084. cmSystemTools::Error("CMake can not determine linker language for target:",
  1085. target.GetName());
  1086. return;
  1087. }
  1088. // if CXX is on and the target contains cxx code then add the cxx flags
  1089. std::string baseFlagVar = "CMAKE_";
  1090. baseFlagVar += linkLanguage;
  1091. baseFlagVar += "_FLAGS";
  1092. flags = m_Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  1093. std::string flagVar = baseFlagVar + "_RELEASE";
  1094. flagsRelease = m_Makefile->GetRequiredDefinition(flagVar.c_str());
  1095. flagsRelease += " -DCMAKE_INTDIR=\\\"Release\\\" ";
  1096. flagVar = baseFlagVar + "_MINSIZEREL";
  1097. flagsMinSize = m_Makefile->GetRequiredDefinition(flagVar.c_str());
  1098. flagsMinSize += " -DCMAKE_INTDIR=\\\"MinSizeRel\\\" ";
  1099. flagVar = baseFlagVar + "_DEBUG";
  1100. flagsDebug = m_Makefile->GetRequiredDefinition(flagVar.c_str());
  1101. flagsDebug += " -DCMAKE_INTDIR=\\\"Debug\\\" ";
  1102. flagVar = baseFlagVar + "_RELWITHDEBINFO";
  1103. flagsDebugRel = m_Makefile->GetRequiredDefinition(flagVar.c_str());
  1104. flagsDebugRel += " -DCMAKE_INTDIR=\\\"RelWithDebInfo\\\" ";
  1105. }
  1106. // if unicode is not found, then add -D_MBCS
  1107. std::string defs = m_Makefile->GetDefineFlags();
  1108. if(flags.find("D_UNICODE") == flags.npos &&
  1109. defs.find("D_UNICODE") == flags.npos)
  1110. {
  1111. flags += " /D \"_MBCS\"";
  1112. }
  1113. // The template files have CXX FLAGS in them, that need to be replaced.
  1114. // There are not separate CXX and C template files, so we use the same
  1115. // variable names. The previous code sets up flags* variables to contain
  1116. // the correct C or CXX flags
  1117. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_MINSIZEREL", flagsMinSize.c_str());
  1118. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_DEBUG", flagsDebug.c_str());
  1119. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_RELWITHDEBINFO", flagsDebugRel.c_str());
  1120. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_RELEASE", flagsRelease.c_str());
  1121. cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS", flags.c_str());
  1122. fout << line.c_str() << std::endl;
  1123. }
  1124. }
  1125. void cmLocalVisualStudio6Generator::WriteDSPFooter(std::ostream& fout)
  1126. {
  1127. std::ifstream fin(m_DSPFooterTemplate.c_str());
  1128. if(!fin)
  1129. {
  1130. cmSystemTools::Error("Error Reading ",
  1131. m_DSPFooterTemplate.c_str());
  1132. }
  1133. std::string line;
  1134. while(cmSystemTools::GetLineFromStream(fin, line))
  1135. {
  1136. fout << line << std::endl;
  1137. }
  1138. }