cmLocalVisualStudio7Generator.cxx 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmGlobalVisualStudio7Generator.h"
  11. #include "cmLocalVisualStudio7Generator.h"
  12. #include "cmXMLParser.h"
  13. #include <cm_expat.h>
  14. #include "cmMakefile.h"
  15. #include "cmSystemTools.h"
  16. #include "cmSourceFile.h"
  17. #include "cmGeneratorTarget.h"
  18. #include "cmCustomCommandGenerator.h"
  19. #include "cmake.h"
  20. #include "cmComputeLinkInformation.h"
  21. #include "cmGeneratedFileStream.h"
  22. #include <cmsys/System.h>
  23. #include <ctype.h> // for isspace
  24. static bool cmLVS6G_IsFAT(const char* dir);
  25. class cmLocalVisualStudio7GeneratorInternals
  26. {
  27. public:
  28. cmLocalVisualStudio7GeneratorInternals(cmLocalVisualStudio7Generator* e):
  29. LocalGenerator(e) {}
  30. typedef cmComputeLinkInformation::ItemVector ItemVector;
  31. void OutputLibraries(std::ostream& fout, ItemVector const& libs);
  32. void OutputObjects(std::ostream& fout, cmTarget* t, const char* isep = 0);
  33. private:
  34. cmLocalVisualStudio7Generator* LocalGenerator;
  35. };
  36. extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[];
  37. static void cmConvertToWindowsSlash(std::string& s)
  38. {
  39. std::string::size_type pos = 0;
  40. while((pos = s.find('/', pos)) != std::string::npos)
  41. {
  42. s[pos] = '\\';
  43. pos++;
  44. }
  45. }
  46. //----------------------------------------------------------------------------
  47. cmLocalVisualStudio7Generator
  48. ::cmLocalVisualStudio7Generator(VSVersion v, cmGlobalGenerator* gg,
  49. cmLocalGenerator* parent):
  50. cmLocalVisualStudioGenerator(v, gg, parent)
  51. {
  52. this->Internal = new cmLocalVisualStudio7GeneratorInternals(this);
  53. }
  54. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  55. {
  56. delete this->Internal;
  57. }
  58. void cmLocalVisualStudio7Generator::AddHelperCommands()
  59. {
  60. std::set<std::string> lang;
  61. lang.insert("C");
  62. lang.insert("CXX");
  63. lang.insert("RC");
  64. lang.insert("IDL");
  65. lang.insert("DEF");
  66. lang.insert("Fortran");
  67. this->CreateCustomTargetsAndCommands(lang);
  68. // Now create GUIDs for targets
  69. cmTargets &tgts = this->Makefile->GetTargets();
  70. cmGlobalVisualStudio7Generator* gg =
  71. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  72. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  73. {
  74. if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  75. {
  76. continue;
  77. }
  78. const char* path = l->second.GetProperty("EXTERNAL_MSPROJECT");
  79. if(path)
  80. {
  81. this->ReadAndStoreExternalGUID(
  82. l->second.GetName().c_str(), path);
  83. }
  84. else
  85. {
  86. gg->CreateGUID(l->first.c_str());
  87. }
  88. }
  89. this->FixGlobalTargets();
  90. }
  91. void cmLocalVisualStudio7Generator::Generate()
  92. {
  93. this->WriteProjectFiles();
  94. this->WriteStampFiles();
  95. }
  96. void cmLocalVisualStudio7Generator::AddCMakeListsRules()
  97. {
  98. cmTargets &tgts = this->Makefile->GetTargets();
  99. // Create the regeneration custom rule.
  100. if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
  101. {
  102. // Create a rule to regenerate the build system when the target
  103. // specification source changes.
  104. if(cmSourceFile* sf = this->CreateVCProjBuildRule())
  105. {
  106. // Add the rule to targets that need it.
  107. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  108. {
  109. if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
  110. {
  111. l->second.AddSource(sf->GetFullPath());
  112. }
  113. }
  114. }
  115. }
  116. }
  117. void cmLocalVisualStudio7Generator::FixGlobalTargets()
  118. {
  119. // Visual Studio .NET 2003 Service Pack 1 will not run post-build
  120. // commands for targets in which no sources are built. Add dummy
  121. // rules to force these targets to build.
  122. cmTargets &tgts = this->Makefile->GetTargets();
  123. for(cmTargets::iterator l = tgts.begin();
  124. l != tgts.end(); l++)
  125. {
  126. cmTarget& tgt = l->second;
  127. if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
  128. {
  129. std::vector<std::string> no_depends;
  130. cmCustomCommandLine force_command;
  131. force_command.push_back("cd");
  132. force_command.push_back(".");
  133. cmCustomCommandLines force_commands;
  134. force_commands.push_back(force_command);
  135. std::string no_main_dependency = "";
  136. std::string force = this->Makefile->GetCurrentBinaryDirectory();
  137. force += cmake::GetCMakeFilesDirectory();
  138. force += "/";
  139. force += tgt.GetName();
  140. force += "_force";
  141. if(cmSourceFile* file =
  142. this->Makefile->AddCustomCommandToOutput(
  143. force.c_str(), no_depends, no_main_dependency,
  144. force_commands, " ", 0, true))
  145. {
  146. tgt.AddSource(file->GetFullPath());
  147. }
  148. }
  149. }
  150. }
  151. // TODO
  152. // for CommandLine= need to repleace quotes with &quot
  153. // write out configurations
  154. void cmLocalVisualStudio7Generator::WriteProjectFiles()
  155. {
  156. // If not an in source build, then create the output directory
  157. if(strcmp(this->Makefile->GetCurrentBinaryDirectory(),
  158. this->Makefile->GetHomeDirectory()) != 0)
  159. {
  160. if(!cmSystemTools::MakeDirectory
  161. (this->Makefile->GetCurrentBinaryDirectory()))
  162. {
  163. cmSystemTools::Error("Error creating directory ",
  164. this->Makefile->GetCurrentBinaryDirectory());
  165. }
  166. }
  167. // Get the set of targets in this directory.
  168. cmTargets &tgts = this->Makefile->GetTargets();
  169. // Create the project file for each target.
  170. for(cmTargets::iterator l = tgts.begin();
  171. l != tgts.end(); l++)
  172. {
  173. if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  174. {
  175. continue;
  176. }
  177. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  178. // so don't build a projectfile for it
  179. if(!l->second.GetProperty("EXTERNAL_MSPROJECT"))
  180. {
  181. this->CreateSingleVCProj(l->first.c_str(),l->second);
  182. }
  183. }
  184. }
  185. //----------------------------------------------------------------------------
  186. void cmLocalVisualStudio7Generator::WriteStampFiles()
  187. {
  188. // Touch a timestamp file used to determine when the project file is
  189. // out of date.
  190. std::string stampName = this->Makefile->GetCurrentBinaryDirectory();
  191. stampName += cmake::GetCMakeFilesDirectory();
  192. cmSystemTools::MakeDirectory(stampName.c_str());
  193. stampName += "/";
  194. stampName += "generate.stamp";
  195. cmsys::ofstream stamp(stampName.c_str());
  196. stamp << "# CMake generation timestamp file for this directory.\n";
  197. // Create a helper file so CMake can determine when it is run
  198. // through the rule created by CreateVCProjBuildRule whether it
  199. // really needs to regenerate the project. This file lists its own
  200. // dependencies. If any file listed in it is newer than itself then
  201. // CMake must rerun. Otherwise the project files are up to date and
  202. // the stamp file can just be touched.
  203. std::string depName = stampName;
  204. depName += ".depend";
  205. cmsys::ofstream depFile(depName.c_str());
  206. depFile << "# CMake generation dependency list for this directory.\n";
  207. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  208. for(std::vector<std::string>::const_iterator lf = listFiles.begin();
  209. lf != listFiles.end(); ++lf)
  210. {
  211. depFile << *lf << std::endl;
  212. }
  213. }
  214. //----------------------------------------------------------------------------
  215. void cmLocalVisualStudio7Generator
  216. ::CreateSingleVCProj(const std::string& lname, cmTarget &target)
  217. {
  218. this->FortranProject =
  219. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  220. ->TargetIsFortranOnly(target);
  221. this->WindowsCEProject =
  222. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  223. ->TargetsWindowsCE();
  224. // Intel Fortran for VS10 uses VS9 format ".vfproj" files.
  225. VSVersion realVersion = this->Version;
  226. if(this->FortranProject && this->Version >= VS10)
  227. {
  228. this->Version = VS9;
  229. }
  230. // add to the list of projects
  231. target.SetProperty("GENERATOR_FILE_NAME",lname.c_str());
  232. // create the dsp.cmake file
  233. std::string fname;
  234. fname = this->Makefile->GetCurrentBinaryDirectory();
  235. fname += "/";
  236. fname += lname;
  237. if(this->FortranProject)
  238. {
  239. fname += ".vfproj";
  240. }
  241. else
  242. {
  243. fname += ".vcproj";
  244. }
  245. // Generate the project file and replace it atomically with
  246. // copy-if-different. We use a separate timestamp so that the IDE
  247. // does not reload project files unnecessarily.
  248. cmGeneratedFileStream fout(fname.c_str());
  249. fout.SetCopyIfDifferent(true);
  250. this->WriteVCProjFile(fout,lname,target);
  251. if (fout.Close())
  252. {
  253. this->GlobalGenerator->FileReplacedDuringGenerate(fname);
  254. }
  255. this->Version = realVersion;
  256. }
  257. //----------------------------------------------------------------------------
  258. cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
  259. {
  260. std::string stampName = this->Makefile->GetCurrentBinaryDirectory();
  261. stampName += "/";
  262. stampName += cmake::GetCMakeFilesDirectoryPostSlash();
  263. stampName += "generate.stamp";
  264. const char* dsprule =
  265. this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  266. cmCustomCommandLine commandLine;
  267. commandLine.push_back(dsprule);
  268. std::string makefileIn = this->Makefile->GetCurrentSourceDirectory();
  269. makefileIn += "/";
  270. makefileIn += "CMakeLists.txt";
  271. makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
  272. if(!cmSystemTools::FileExists(makefileIn.c_str()))
  273. {
  274. return 0;
  275. }
  276. std::string comment = "Building Custom Rule ";
  277. comment += makefileIn;
  278. std::string args;
  279. args = "-H";
  280. args += this->Convert(this->Makefile->GetHomeDirectory(),
  281. START_OUTPUT, UNCHANGED, true);
  282. commandLine.push_back(args);
  283. args = "-B";
  284. args +=
  285. this->Convert(this->Makefile->GetHomeOutputDirectory(),
  286. START_OUTPUT, UNCHANGED, true);
  287. commandLine.push_back(args);
  288. commandLine.push_back("--check-stamp-file");
  289. std::string stampFilename = this->Convert(stampName.c_str(), FULL,
  290. SHELL);
  291. commandLine.push_back(stampFilename.c_str());
  292. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  293. cmCustomCommandLines commandLines;
  294. commandLines.push_back(commandLine);
  295. const char* no_working_directory = 0;
  296. std::string fullpathStampName = this->Convert(stampName.c_str(), FULL,
  297. UNCHANGED);
  298. this->Makefile->AddCustomCommandToOutput(fullpathStampName.c_str(),
  299. listFiles, makefileIn.c_str(),
  300. commandLines, comment.c_str(),
  301. no_working_directory, true);
  302. if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
  303. {
  304. return file;
  305. }
  306. else
  307. {
  308. cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
  309. return 0;
  310. }
  311. }
  312. void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout,
  313. const std::string& libName,
  314. cmTarget &target)
  315. {
  316. std::vector<std::string> *configs =
  317. static_cast<cmGlobalVisualStudio7Generator *>
  318. (this->GlobalGenerator)->GetConfigurations();
  319. fout << "\t<Configurations>\n";
  320. for( std::vector<std::string>::iterator i = configs->begin();
  321. i != configs->end(); ++i)
  322. {
  323. this->WriteConfiguration(fout, i->c_str(), libName, target);
  324. }
  325. fout << "\t</Configurations>\n";
  326. }
  327. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranFlagTable[] =
  328. {
  329. {"Preprocess", "fpp", "Run Preprocessor on files", "preprocessYes", 0},
  330. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
  331. {"SourceFileFormat", "fixed", "Use Fixed Format", "fileFormatFixed", 0},
  332. {"SourceFileFormat", "free", "Use Free Format", "fileFormatFree", 0},
  333. {"DebugInformationFormat", "Zi", "full debug", "debugEnabled", 0},
  334. {"DebugInformationFormat", "debug:full", "full debug", "debugEnabled", 0},
  335. {"DebugInformationFormat", "Z7", "c7 compat", "debugOldStyleInfo", 0},
  336. {"DebugInformationFormat", "Zd", "line numbers", "debugLineInfoOnly", 0},
  337. {"Optimization", "Od", "disable optimization", "optimizeDisabled", 0},
  338. {"Optimization", "O1", "min space", "optimizeMinSpace", 0},
  339. {"Optimization", "O3", "full optimize", "optimizeFull", 0},
  340. {"GlobalOptimizations", "Og", "global optimize", "true", 0},
  341. {"InlineFunctionExpansion", "Ob0", "", "expandDisable", 0},
  342. {"InlineFunctionExpansion", "Ob1", "", "expandOnlyInline", 0},
  343. {"FavorSizeOrSpeed", "Os", "", "favorSize", 0},
  344. {"OmitFramePointers", "Oy-", "", "false", 0},
  345. {"OptimizeForProcessor", "GB", "", "procOptimizeBlended", 0},
  346. {"OptimizeForProcessor", "G5", "", "procOptimizePentium", 0},
  347. {"OptimizeForProcessor", "G6", "", "procOptimizePentiumProThruIII", 0},
  348. {"UseProcessorExtensions", "QzxK", "", "codeForStreamingSIMD", 0},
  349. {"OptimizeForProcessor", "QaxN", "", "codeForPentium4", 0},
  350. {"OptimizeForProcessor", "QaxB", "", "codeForPentiumM", 0},
  351. {"OptimizeForProcessor", "QaxP", "", "codeForCodeNamedPrescott", 0},
  352. {"OptimizeForProcessor", "QaxT", "", "codeForCore2Duo", 0},
  353. {"OptimizeForProcessor", "QxK", "", "codeExclusivelyStreamingSIMD", 0},
  354. {"OptimizeForProcessor", "QxN", "", "codeExclusivelyPentium4", 0},
  355. {"OptimizeForProcessor", "QxB", "", "codeExclusivelyPentiumM", 0},
  356. {"OptimizeForProcessor", "QxP", "", "codeExclusivelyCodeNamedPrescott", 0},
  357. {"OptimizeForProcessor", "QxT", "", "codeExclusivelyCore2Duo", 0},
  358. {"OptimizeForProcessor", "QxO", "", "codeExclusivelyCore2StreamingSIMD", 0},
  359. {"OptimizeForProcessor", "QxS", "", "codeExclusivelyCore2StreamingSIMD4", 0},
  360. {"OpenMP", "Qopenmp", "", "OpenMPParallelCode", 0},
  361. {"OpenMP", "Qopenmp-stubs", "", "OpenMPSequentialCode", 0},
  362. {"Traceback", "traceback", "", "true", 0},
  363. {"Traceback", "notraceback", "", "false", 0},
  364. {"FloatingPointExceptionHandling", "fpe:0", "", "fpe0", 0},
  365. {"FloatingPointExceptionHandling", "fpe:1", "", "fpe1", 0},
  366. {"FloatingPointExceptionHandling", "fpe:3", "", "fpe3", 0},
  367. {"ModulePath", "module:", "", "",
  368. cmVS7FlagTable::UserValueRequired},
  369. {"LoopUnrolling", "Qunroll:", "", "",
  370. cmVS7FlagTable::UserValueRequired},
  371. {"AutoParallelThreshold", "Qpar-threshold:", "", "",
  372. cmVS7FlagTable::UserValueRequired},
  373. {"HeapArrays", "heap-arrays:", "", "",
  374. cmVS7FlagTable::UserValueRequired},
  375. {"ObjectText", "bintext:", "", "",
  376. cmVS7FlagTable::UserValueRequired},
  377. {"Parallelization", "Qparallel", "", "true", 0},
  378. {"PrefetchInsertion", "Qprefetch-", "", "false", 0},
  379. {"BufferedIO", "assume:buffered_io", "", "true", 0},
  380. {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
  381. {"CallingConvention", "iface:cref", "", "callConventionCRef", 0},
  382. {"CallingConvention", "iface:stdref", "", "callConventionStdRef", 0},
  383. {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
  384. {"CallingConvention", "iface:cvf", "", "callConventionCVF", 0},
  385. {"EnableRecursion", "recursive", "", "true", 0},
  386. {"ReentrantCode", "reentrancy", "", "true", 0},
  387. // done up to Language
  388. {0,0,0,0,0}
  389. };
  390. // fill the table here currently the comment field is not used for
  391. // anything other than documentation NOTE: Make sure the longer
  392. // commandFlag comes FIRST!
  393. cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
  394. {
  395. // option flags (some flags map to the same option)
  396. {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1", 0},
  397. {"BasicRuntimeChecks", "RTCsu",
  398. "Both stack and uninitialized checks", "3", 0},
  399. {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1", 0},
  400. {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2", 0},
  401. {"BasicRuntimeChecks", "RTC1",
  402. "Both stack and uninitialized checks", "3", 0},
  403. {"DebugInformationFormat", "Z7", "debug format", "1", 0},
  404. {"DebugInformationFormat", "Zd", "debug format", "2", 0},
  405. {"DebugInformationFormat", "Zi", "debug format", "3", 0},
  406. {"DebugInformationFormat", "ZI", "debug format", "4", 0},
  407. {"EnableEnhancedInstructionSet", "arch:SSE2",
  408. "Use sse2 instructions", "2", 0},
  409. {"EnableEnhancedInstructionSet", "arch:SSE",
  410. "Use sse instructions", "1", 0},
  411. {"FloatingPointModel", "fp:precise",
  412. "Use precise floating point model", "0", 0},
  413. {"FloatingPointModel", "fp:strict",
  414. "Use strict floating point model", "1", 0},
  415. {"FloatingPointModel", "fp:fast", "Use fast floating point model", "2", 0},
  416. {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0},
  417. {"FavorSizeOrSpeed", "Os", "Favor small code", "2", 0},
  418. {"CompileAs", "TC", "Compile as c code", "1", 0},
  419. {"CompileAs", "TP", "Compile as c++ code", "2", 0},
  420. {"Optimization", "Od", "Non Debug", "0", 0},
  421. {"Optimization", "O1", "Min Size", "1", 0},
  422. {"Optimization", "O2", "Max Speed", "2", 0},
  423. {"Optimization", "Ox", "Max Optimization", "3", 0},
  424. {"OptimizeForProcessor", "GB", "Blended processor mode", "0", 0},
  425. {"OptimizeForProcessor", "G5", "Pentium", "1", 0},
  426. {"OptimizeForProcessor", "G6", "PPro PII PIII", "2", 0},
  427. {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3", 0},
  428. {"InlineFunctionExpansion", "Ob0", "no inlines", "0", 0},
  429. {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1", 0},
  430. {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2", 0},
  431. {"RuntimeLibrary", "MTd", "Multithreaded debug", "1", 0},
  432. {"RuntimeLibrary", "MT", "Multithreaded", "0", 0},
  433. {"RuntimeLibrary", "MDd", "Multithreaded dll debug", "3", 0},
  434. {"RuntimeLibrary", "MD", "Multithreaded dll", "2", 0},
  435. {"RuntimeLibrary", "MLd", "Single Thread debug", "5", 0},
  436. {"RuntimeLibrary", "ML", "Single Thread", "4", 0},
  437. {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5", 0},
  438. {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1", 0},
  439. {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2", 0},
  440. {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3", 0},
  441. {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4", 0},
  442. {"WarningLevel", "W0", "Warning level", "0", 0},
  443. {"WarningLevel", "W1", "Warning level", "1", 0},
  444. {"WarningLevel", "W2", "Warning level", "2", 0},
  445. {"WarningLevel", "W3", "Warning level", "3", 0},
  446. {"WarningLevel", "W4", "Warning level", "4", 0},
  447. {"DisableSpecificWarnings", "wd", "Disable specific warnings", "",
  448. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  449. // Precompiled header and related options. Note that the
  450. // UsePrecompiledHeader entries are marked as "Continue" so that the
  451. // corresponding PrecompiledHeaderThrough entry can be found.
  452. {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
  453. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  454. {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
  455. cmVS7FlagTable::UserValueRequired},
  456. {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
  457. cmVS7FlagTable::UserValue},
  458. // The YX and Yu options are in a per-global-generator table because
  459. // their values differ based on the VS IDE version.
  460. {"ForcedIncludeFiles", "FI", "Forced include files", "",
  461. cmVS7FlagTable::UserValueRequired | cmVS7FlagTable::SemicolonAppendable},
  462. {"AssemblerListingLocation", "Fa", "ASM List Location", "",
  463. cmVS7FlagTable::UserValue},
  464. {"ProgramDataBaseFileName", "Fd", "Program Database File Name", "",
  465. cmVS7FlagTable::UserValue},
  466. // boolean flags
  467. {"BufferSecurityCheck", "GS", "Buffer security check", "true", 0},
  468. {"BufferSecurityCheck", "GS-", "Turn off Buffer security check", "false", 0},
  469. {"Detect64BitPortabilityProblems", "Wp64",
  470. "Detect 64-bit Portability Problems", "true", 0},
  471. {"EnableFiberSafeOptimizations", "GT", "Enable Fiber-safe Optimizations",
  472. "true", 0},
  473. {"EnableFunctionLevelLinking", "Gy",
  474. "EnableFunctionLevelLinking", "true", 0},
  475. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "true", 0},
  476. {"GlobalOptimizations", "Og", "Global Optimize", "true", 0},
  477. {"ImproveFloatingPointConsistency", "Op",
  478. "ImproveFloatingPointConsistency", "true", 0},
  479. {"MinimalRebuild", "Gm", "minimal rebuild", "true", 0},
  480. {"OmitFramePointers", "Oy", "OmitFramePointers", "true", 0},
  481. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "true", 0},
  482. {"RuntimeTypeInfo", "GR",
  483. "Turn on Run time type information for c++", "true", 0},
  484. {"RuntimeTypeInfo", "GR-",
  485. "Turn off Run time type information for c++", "false", 0},
  486. {"SmallerTypeCheck", "RTCc", "smaller type check", "true", 0},
  487. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
  488. {"WholeProgramOptimization", "GL",
  489. "Enables whole program optimization", "true", 0},
  490. {"WholeProgramOptimization", "GL-",
  491. "Disables whole program optimization", "false", 0},
  492. {"WarnAsError", "WX", "Treat warnings as errors", "true", 0},
  493. {"BrowseInformation", "FR", "Generate browse information", "1", 0},
  494. {"StringPooling", "GF", "Enable StringPooling", "true", 0},
  495. {0,0,0,0,0}
  496. };
  497. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
  498. {
  499. // option flags (some flags map to the same option)
  500. {"GenerateManifest", "MANIFEST:NO",
  501. "disable manifest generation", "false", 0},
  502. {"GenerateManifest", "MANIFEST", "enable manifest generation", "true", 0},
  503. {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
  504. {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
  505. {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK:NO", "", "false", 0},
  506. {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK", "", "true", 0},
  507. {"DataExecutionPrevention", "NXCOMPAT:NO",
  508. "Not known to work with Windows Data Execution Prevention", "1", 0},
  509. {"DataExecutionPrevention", "NXCOMPAT",
  510. "Known to work with Windows Data Execution Prevention", "2", 0},
  511. {"DelaySign", "DELAYSIGN:NO", "", "false", 0},
  512. {"DelaySign", "DELAYSIGN", "", "true", 0},
  513. {"EntryPointSymbol", "ENTRY:", "sets the starting address", "",
  514. cmVS7FlagTable::UserValue},
  515. {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
  516. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  517. {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
  518. "true", 0},
  519. {"FixedBaseAddress", "FIXED:NO", "Generate a relocation section", "1", 0},
  520. {"FixedBaseAddress", "FIXED", "Image must be loaded at a fixed address",
  521. "2", 0},
  522. {"EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs",
  523. "1", 0},
  524. {"EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "2", 0},
  525. {"ResourceOnlyDLL", "NOENTRY", "Create DLL with no entry point", "true", 0},
  526. {"OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", "1", 0},
  527. {"OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", "2", 0},
  528. {"Profile", "PROFILE", "", "true", 0},
  529. {"RandomizedBaseAddress", "DYNAMICBASE:NO",
  530. "Image may not be rebased at load-time", "1", 0},
  531. {"RandomizedBaseAddress", "DYNAMICBASE",
  532. "Image may be rebased at load-time", "2", 0},
  533. {"SetChecksum", "RELEASE", "Enable setting checksum in header", "true", 0},
  534. {"SupportUnloadOfDelayLoadedDLL", "DELAY:UNLOAD", "", "true", 0},
  535. {"TargetMachine", "MACHINE:I386", "Machine x86", "1", 0},
  536. {"TargetMachine", "MACHINE:X86", "Machine x86", "1", 0},
  537. {"TargetMachine", "MACHINE:AM33", "Machine AM33", "2", 0},
  538. {"TargetMachine", "MACHINE:ARM", "Machine ARM", "3", 0},
  539. {"TargetMachine", "MACHINE:EBC", "Machine EBC", "4", 0},
  540. {"TargetMachine", "MACHINE:IA64", "Machine IA64", "5", 0},
  541. {"TargetMachine", "MACHINE:M32R", "Machine M32R", "6", 0},
  542. {"TargetMachine", "MACHINE:MIPS", "Machine MIPS", "7", 0},
  543. {"TargetMachine", "MACHINE:MIPS16", "Machine MIPS16", "8", 0},
  544. {"TargetMachine", "MACHINE:MIPSFPU)", "Machine MIPSFPU", "9", 0},
  545. {"TargetMachine", "MACHINE:MIPSFPU16", "Machine MIPSFPU16", "10", 0},
  546. {"TargetMachine", "MACHINE:MIPSR41XX", "Machine MIPSR41XX", "11", 0},
  547. {"TargetMachine", "MACHINE:SH3", "Machine SH3", "12", 0},
  548. {"TargetMachine", "MACHINE:SH3DSP", "Machine SH3DSP", "13", 0},
  549. {"TargetMachine", "MACHINE:SH4", "Machine SH4", "14", 0},
  550. {"TargetMachine", "MACHINE:SH5", "Machine SH5", "15", 0},
  551. {"TargetMachine", "MACHINE:THUMB", "Machine THUMB", "16", 0},
  552. {"TargetMachine", "MACHINE:X64", "Machine x64", "17", 0},
  553. {"TurnOffAssemblyGeneration", "NOASSEMBLY",
  554. "No assembly even if CLR information is present in objects.", "true", 0},
  555. {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
  556. cmVS7FlagTable::UserValue},
  557. {"GenerateMapFile", "MAP", "enable generation of map file", "true", 0},
  558. {0,0,0,0,0}
  559. };
  560. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranLinkFlagTable[] =
  561. {
  562. {"LinkIncremental", "INCREMENTAL:NO", "link incremental",
  563. "linkIncrementalNo", 0},
  564. {"LinkIncremental", "INCREMENTAL:YES", "link incremental",
  565. "linkIncrementalYes", 0},
  566. {0,0,0,0,0}
  567. };
  568. //----------------------------------------------------------------------------
  569. // Helper class to write build event <Tool .../> elements.
  570. class cmLocalVisualStudio7Generator::EventWriter
  571. {
  572. public:
  573. EventWriter(cmLocalVisualStudio7Generator* lg,
  574. const std::string& config, std::ostream& os):
  575. LG(lg), Config(config), Stream(os), First(true) {}
  576. void Start(const char* tool)
  577. {
  578. this->First = true;
  579. this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
  580. }
  581. void Finish()
  582. {
  583. this->Stream << (this->First? "" : "\"") << "/>\n";
  584. }
  585. void Write(std::vector<cmCustomCommand> const& ccs)
  586. {
  587. for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
  588. ci != ccs.end(); ++ci)
  589. {
  590. this->Write(*ci);
  591. }
  592. }
  593. void Write(cmCustomCommand const& cc)
  594. {
  595. cmCustomCommandGenerator ccg(cc, this->Config, this->LG->GetMakefile());
  596. if(this->First)
  597. {
  598. const char* comment = ccg.GetComment();
  599. if(comment && *comment)
  600. {
  601. this->Stream << "\nDescription=\""
  602. << this->LG->EscapeForXML(comment) << "\"";
  603. }
  604. this->Stream << "\nCommandLine=\"";
  605. this->First = false;
  606. }
  607. else
  608. {
  609. this->Stream << this->LG->EscapeForXML("\n");
  610. }
  611. std::string script = this->LG->ConstructScript(ccg);
  612. this->Stream << this->LG->EscapeForXML(script.c_str());
  613. }
  614. private:
  615. cmLocalVisualStudio7Generator* LG;
  616. std::string Config;
  617. std::ostream& Stream;
  618. bool First;
  619. };
  620. //----------------------------------------------------------------------------
  621. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  622. const std::string& configName,
  623. const std::string& libName,
  624. cmTarget &target)
  625. {
  626. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  627. if(!mfcFlag)
  628. {
  629. mfcFlag = "0";
  630. }
  631. cmGlobalVisualStudio7Generator* gg =
  632. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  633. fout << "\t\t<Configuration\n"
  634. << "\t\t\tName=\"" << configName
  635. << "|" << gg->GetPlatformName() << "\"\n";
  636. // This is an internal type to Visual Studio, it seems that:
  637. // 4 == static library
  638. // 2 == dll
  639. // 1 == executable
  640. // 10 == utility
  641. const char* configType = "10";
  642. const char* projectType = 0;
  643. bool targetBuilds = true;
  644. switch(target.GetType())
  645. {
  646. case cmTarget::OBJECT_LIBRARY:
  647. targetBuilds = false; // no manifest tool for object library
  648. case cmTarget::STATIC_LIBRARY:
  649. projectType = "typeStaticLibrary";
  650. configType = "4";
  651. break;
  652. case cmTarget::SHARED_LIBRARY:
  653. case cmTarget::MODULE_LIBRARY:
  654. projectType = "typeDynamicLibrary";
  655. configType = "2";
  656. break;
  657. case cmTarget::EXECUTABLE:
  658. configType = "1";
  659. break;
  660. case cmTarget::UTILITY:
  661. case cmTarget::GLOBAL_TARGET:
  662. configType = "10";
  663. default:
  664. targetBuilds = false;
  665. break;
  666. }
  667. if(this->FortranProject && projectType)
  668. {
  669. configType = projectType;
  670. }
  671. std::string flags;
  672. if(strcmp(configType, "10") != 0)
  673. {
  674. const std::string& linkLanguage = (this->FortranProject?
  675. std::string("Fortran"):
  676. target.GetLinkerLanguage(configName));
  677. if(linkLanguage.empty())
  678. {
  679. cmSystemTools::Error
  680. ("CMake can not determine linker language for target: ",
  681. target.GetName().c_str());
  682. return;
  683. }
  684. if(linkLanguage == "C" || linkLanguage == "CXX"
  685. || linkLanguage == "Fortran")
  686. {
  687. std::string baseFlagVar = "CMAKE_";
  688. baseFlagVar += linkLanguage;
  689. baseFlagVar += "_FLAGS";
  690. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  691. std::string flagVar = baseFlagVar + std::string("_") +
  692. cmSystemTools::UpperCase(configName);
  693. flags += " ";
  694. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  695. }
  696. // set the correct language
  697. if(linkLanguage == "C")
  698. {
  699. flags += " /TC ";
  700. }
  701. if(linkLanguage == "CXX")
  702. {
  703. flags += " /TP ";
  704. }
  705. // Add the target-specific flags.
  706. this->AddCompileOptions(flags, &target, linkLanguage, configName);
  707. }
  708. if(this->FortranProject)
  709. {
  710. switch(this->GetFortranFormat(target.GetProperty("Fortran_FORMAT")))
  711. {
  712. case FortranFormatFixed: flags += " -fixed"; break;
  713. case FortranFormatFree: flags += " -free"; break;
  714. default: break;
  715. }
  716. }
  717. // Get preprocessor definitions for this directory.
  718. std::string defineFlags = this->Makefile->GetDefineFlags();
  719. Options::Tool t = Options::Compiler;
  720. cmVS7FlagTable const* table = cmLocalVisualStudio7GeneratorFlagTable;
  721. if(this->FortranProject)
  722. {
  723. t = Options::FortranCompiler;
  724. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  725. }
  726. Options targetOptions(this, t,
  727. table,
  728. gg->ExtraFlagTable);
  729. targetOptions.FixExceptionHandlingDefault();
  730. std::string asmLocation = configName + "/";
  731. targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  732. targetOptions.Parse(flags.c_str());
  733. targetOptions.Parse(defineFlags.c_str());
  734. targetOptions.ParseFinish();
  735. cmGeneratorTarget* gt =
  736. this->GlobalGenerator->GetGeneratorTarget(&target);
  737. std::vector<std::string> targetDefines;
  738. target.GetCompileDefinitions(targetDefines, configName, "CXX");
  739. targetOptions.AddDefines(targetDefines);
  740. targetOptions.SetVerboseMakefile(
  741. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  742. // Add a definition for the configuration name.
  743. std::string configDefine = "CMAKE_INTDIR=\"";
  744. configDefine += configName;
  745. configDefine += "\"";
  746. targetOptions.AddDefine(configDefine);
  747. // Add the export symbol definition for shared library objects.
  748. if(const char* exportMacro = target.GetExportMacro())
  749. {
  750. targetOptions.AddDefine(exportMacro);
  751. }
  752. // The intermediate directory name consists of a directory for the
  753. // target and a subdirectory for the configuration name.
  754. std::string intermediateDir = this->GetTargetDirectory(target);
  755. intermediateDir += "/";
  756. intermediateDir += configName;
  757. if (target.GetType() < cmTarget::UTILITY)
  758. {
  759. std::string const& outDir =
  760. target.GetType() == cmTarget::OBJECT_LIBRARY?
  761. intermediateDir : target.GetDirectory(configName);
  762. fout << "\t\t\tOutputDirectory=\""
  763. << this->ConvertToXMLOutputPathSingle(outDir.c_str()) << "\"\n";
  764. }
  765. fout << "\t\t\tIntermediateDirectory=\""
  766. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  767. << "\"\n"
  768. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  769. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  770. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"false\"\n";
  771. if (this->FortranProject)
  772. {
  773. // Intel Fortran >= 15.0 uses TargetName property.
  774. std::string targetNameFull = target.GetFullName(configName);
  775. std::string targetName =
  776. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  777. std::string targetExt =
  778. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  779. fout <<
  780. "\t\t\tTargetName=\"" << this->EscapeForXML(targetName) << "\"\n"
  781. "\t\t\tTargetExt=\"" << this->EscapeForXML(targetExt) << "\"\n"
  782. ;
  783. }
  784. // If unicode is enabled change the character set to unicode, if not
  785. // then default to MBCS.
  786. if(targetOptions.UsingUnicode())
  787. {
  788. fout << "\t\t\tCharacterSet=\"1\">\n";
  789. }
  790. else if(targetOptions.UsingSBCS())
  791. {
  792. fout << "\t\t\tCharacterSet=\"0\">\n";
  793. }
  794. else
  795. {
  796. fout << "\t\t\tCharacterSet=\"2\">\n";
  797. }
  798. const char* tool = "VCCLCompilerTool";
  799. if(this->FortranProject)
  800. {
  801. tool = "VFFortranCompilerTool";
  802. }
  803. fout << "\t\t\t<Tool\n"
  804. << "\t\t\t\tName=\"" << tool << "\"\n";
  805. if(this->FortranProject)
  806. {
  807. const char* target_mod_dir =
  808. target.GetProperty("Fortran_MODULE_DIRECTORY");
  809. std::string modDir;
  810. if(target_mod_dir)
  811. {
  812. modDir = this->Convert(target_mod_dir,
  813. cmLocalGenerator::START_OUTPUT,
  814. cmLocalGenerator::UNCHANGED);
  815. }
  816. else
  817. {
  818. modDir = ".";
  819. }
  820. fout << "\t\t\t\tModulePath=\""
  821. << this->ConvertToXMLOutputPath(modDir.c_str())
  822. << "\\$(ConfigurationName)\"\n";
  823. }
  824. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  825. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  826. std::vector<std::string> includes;
  827. this->GetIncludeDirectories(includes, gt, "C", configName);
  828. std::vector<std::string>::iterator i = includes.begin();
  829. for(;i != includes.end(); ++i)
  830. {
  831. // output the include path
  832. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  833. fout << ipath << ";";
  834. // if this is fortran then output the include with
  835. // a ConfigurationName on the end of it.
  836. if(this->FortranProject)
  837. {
  838. ipath = i->c_str();
  839. ipath += "/$(ConfigurationName)";
  840. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  841. fout << ipath << ";";
  842. }
  843. }
  844. fout << "\"\n";
  845. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  846. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
  847. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  848. if(target.GetType() <= cmTarget::OBJECT_LIBRARY)
  849. {
  850. // Specify the compiler program database file if configured.
  851. std::string pdb = target.GetCompilePDBPath(configName);
  852. if(!pdb.empty())
  853. {
  854. fout << "\t\t\t\tProgramDataBaseFileName=\""
  855. << this->ConvertToXMLOutputPathSingle(pdb.c_str())
  856. << "\"\n";
  857. }
  858. }
  859. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  860. if(gg->IsMasmEnabled() && !this->FortranProject)
  861. {
  862. Options masmOptions(this, Options::MasmCompiler, 0, 0);
  863. fout <<
  864. "\t\t\t<Tool\n"
  865. "\t\t\t\tName=\"MASM\"\n"
  866. "\t\t\t\tIncludePaths=\""
  867. ;
  868. const char* sep = "";
  869. for(i = includes.begin(); i != includes.end(); ++i)
  870. {
  871. std::string inc = *i;
  872. cmConvertToWindowsSlash(inc);
  873. fout << sep << this->EscapeForXML(inc);
  874. sep = ";";
  875. }
  876. fout << "\"\n";
  877. // Use same preprocessor definitions as VCCLCompilerTool.
  878. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n",
  879. "ASM_MASM");
  880. masmOptions.OutputFlagMap(fout, "\t\t\t\t");
  881. fout <<
  882. "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
  883. "\t\t\t/>\n";
  884. }
  885. tool = "VCCustomBuildTool";
  886. if(this->FortranProject)
  887. {
  888. tool = "VFCustomBuildTool";
  889. }
  890. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  891. tool = "VCResourceCompilerTool";
  892. if(this->FortranProject)
  893. {
  894. tool = "VFResourceCompilerTool";
  895. }
  896. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  897. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  898. for(i = includes.begin();i != includes.end(); ++i)
  899. {
  900. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  901. fout << ipath << ";";
  902. }
  903. // add the -D flags to the RC tool
  904. fout << "\"";
  905. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
  906. fout << "/>\n";
  907. tool = "VCMIDLTool";
  908. if(this->FortranProject)
  909. {
  910. tool = "VFMIDLTool";
  911. }
  912. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  913. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  914. for(i = includes.begin(); i != includes.end(); ++i)
  915. {
  916. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  917. fout << ipath << ";";
  918. }
  919. fout << "\"\n";
  920. fout << "\t\t\t\tMkTypLibCompatible=\"false\"\n";
  921. if( gg->GetPlatformName() == "x64" )
  922. {
  923. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  924. }
  925. else if( gg->GetPlatformName() == "ia64" )
  926. {
  927. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  928. }
  929. else
  930. {
  931. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  932. }
  933. fout << "\t\t\t\tGenerateStublessProxies=\"true\"\n";
  934. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  935. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  936. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  937. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  938. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  939. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  940. // end of <Tool Name=VCMIDLTool
  941. // Check if we need the FAT32 workaround.
  942. if(targetBuilds && this->Version >= VS8)
  943. {
  944. // Check the filesystem type where the target will be written.
  945. if(cmLVS6G_IsFAT(target.GetDirectory(configName).c_str()))
  946. {
  947. // Add a flag telling the manifest tool to use a workaround
  948. // for FAT32 file systems, which can cause an empty manifest
  949. // to be embedded into the resulting executable. See CMake
  950. // bug #2617.
  951. const char* manifestTool = "VCManifestTool";
  952. if(this->FortranProject)
  953. {
  954. manifestTool = "VFManifestTool";
  955. }
  956. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << manifestTool << "\"\n"
  957. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  958. << "\t\t\t/>\n";
  959. }
  960. }
  961. this->OutputTargetRules(fout, configName, target, libName);
  962. this->OutputBuildTool(fout, configName, target, targetOptions);
  963. fout << "\t\t</Configuration>\n";
  964. }
  965. //----------------------------------------------------------------------------
  966. std::string
  967. cmLocalVisualStudio7Generator
  968. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
  969. const std::string& configName)
  970. {
  971. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  972. std::string extraLinkOptionsBuildTypeDef =
  973. rootLinkerFlags + "_" + configTypeUpper;
  974. std::string extraLinkOptionsBuildType =
  975. this->Makefile->GetRequiredDefinition
  976. (extraLinkOptionsBuildTypeDef.c_str());
  977. return extraLinkOptionsBuildType;
  978. }
  979. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  980. const std::string& configName, cmTarget &target,
  981. const Options& targetOptions)
  982. {
  983. cmGlobalVisualStudio7Generator* gg =
  984. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  985. std::string temp;
  986. std::string extraLinkOptions;
  987. if(target.GetType() == cmTarget::EXECUTABLE)
  988. {
  989. extraLinkOptions =
  990. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  991. + std::string(" ")
  992. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  993. }
  994. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  995. {
  996. extraLinkOptions =
  997. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  998. + std::string(" ")
  999. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  1000. }
  1001. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  1002. {
  1003. extraLinkOptions =
  1004. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  1005. + std::string(" ")
  1006. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  1007. }
  1008. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1009. if(targetLinkFlags)
  1010. {
  1011. extraLinkOptions += " ";
  1012. extraLinkOptions += targetLinkFlags;
  1013. }
  1014. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  1015. std::string linkFlagsConfig = "LINK_FLAGS_";
  1016. linkFlagsConfig += configTypeUpper;
  1017. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  1018. if(targetLinkFlags)
  1019. {
  1020. extraLinkOptions += " ";
  1021. extraLinkOptions += targetLinkFlags;
  1022. }
  1023. Options linkOptions(this, Options::Linker);
  1024. if(this->FortranProject)
  1025. {
  1026. linkOptions.AddTable(cmLocalVisualStudio7GeneratorFortranLinkFlagTable);
  1027. }
  1028. linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
  1029. linkOptions.Parse(extraLinkOptions.c_str());
  1030. if(!this->ModuleDefinitionFile.empty())
  1031. {
  1032. std::string defFile =
  1033. this->ConvertToOptionallyRelativeOutputPath(this->ModuleDefinitionFile);
  1034. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  1035. }
  1036. switch(target.GetType())
  1037. {
  1038. case cmTarget::UNKNOWN_LIBRARY:
  1039. break;
  1040. case cmTarget::OBJECT_LIBRARY:
  1041. {
  1042. std::string libpath = this->GetTargetDirectory(target);
  1043. libpath += "/";
  1044. libpath += configName;
  1045. libpath += "/";
  1046. libpath += target.GetName();
  1047. libpath += ".lib";
  1048. const char* tool =
  1049. this->FortranProject? "VFLibrarianTool":"VCLibrarianTool";
  1050. fout << "\t\t\t<Tool\n"
  1051. << "\t\t\t\tName=\"" << tool << "\"\n";
  1052. fout << "\t\t\t\tOutputFile=\""
  1053. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1054. break;
  1055. }
  1056. case cmTarget::STATIC_LIBRARY:
  1057. {
  1058. std::string targetNameFull = target.GetFullName(configName);
  1059. std::string libpath = target.GetDirectory(configName);
  1060. libpath += "/";
  1061. libpath += targetNameFull;
  1062. const char* tool = "VCLibrarianTool";
  1063. if(this->FortranProject)
  1064. {
  1065. tool = "VFLibrarianTool";
  1066. }
  1067. fout << "\t\t\t<Tool\n"
  1068. << "\t\t\t\tName=\"" << tool << "\"\n";
  1069. if(this->GetVersion() < VS8 || this->FortranProject)
  1070. {
  1071. std::ostringstream libdeps;
  1072. this->Internal->OutputObjects(libdeps, &target);
  1073. if(!libdeps.str().empty())
  1074. {
  1075. fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str() << "\"\n";
  1076. }
  1077. }
  1078. std::string libflags;
  1079. this->GetStaticLibraryFlags(libflags, configTypeUpper, &target);
  1080. if(!libflags.empty())
  1081. {
  1082. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  1083. }
  1084. fout << "\t\t\t\tOutputFile=\""
  1085. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1086. break;
  1087. }
  1088. case cmTarget::SHARED_LIBRARY:
  1089. case cmTarget::MODULE_LIBRARY:
  1090. {
  1091. std::string targetName;
  1092. std::string targetNameSO;
  1093. std::string targetNameFull;
  1094. std::string targetNameImport;
  1095. std::string targetNamePDB;
  1096. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1097. targetNameImport, targetNamePDB, configName);
  1098. // Compute the link library and directory information.
  1099. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1100. if(!pcli)
  1101. {
  1102. return;
  1103. }
  1104. cmComputeLinkInformation& cli = *pcli;
  1105. std::string linkLanguage = cli.GetLinkLanguage();
  1106. // Compute the variable name to lookup standard libraries for this
  1107. // language.
  1108. std::string standardLibsVar = "CMAKE_";
  1109. standardLibsVar += linkLanguage;
  1110. standardLibsVar += "_STANDARD_LIBRARIES";
  1111. const char* tool = "VCLinkerTool";
  1112. if(this->FortranProject)
  1113. {
  1114. tool = "VFLinkerTool";
  1115. }
  1116. fout << "\t\t\t<Tool\n"
  1117. << "\t\t\t\tName=\"" << tool << "\"\n";
  1118. if(!gg->NeedLinkLibraryDependencies(target))
  1119. {
  1120. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1121. }
  1122. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1123. // Use the NOINHERIT macro to avoid getting VS project default
  1124. // libraries which may be set by the user to something bad.
  1125. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1126. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1127. if(this->GetVersion() < VS8 || this->FortranProject)
  1128. {
  1129. this->Internal->OutputObjects(fout, &target, " ");
  1130. }
  1131. fout << " ";
  1132. this->Internal->OutputLibraries(fout, cli.GetItems());
  1133. fout << "\"\n";
  1134. temp = target.GetDirectory(configName);
  1135. temp += "/";
  1136. temp += targetNameFull;
  1137. fout << "\t\t\t\tOutputFile=\""
  1138. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1139. this->WriteTargetVersionAttribute(fout, target);
  1140. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1141. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1142. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1143. fout << "\"\n";
  1144. temp = target.GetPDBDirectory(configName);
  1145. temp += "/";
  1146. temp += targetNamePDB;
  1147. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  1148. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1149. if(targetOptions.IsDebug())
  1150. {
  1151. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1152. }
  1153. if(this->WindowsCEProject)
  1154. {
  1155. if(this->GetVersion() < VS9)
  1156. {
  1157. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1158. }
  1159. else
  1160. {
  1161. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1162. }
  1163. }
  1164. std::string stackVar = "CMAKE_";
  1165. stackVar += linkLanguage;
  1166. stackVar += "_STACK_SIZE";
  1167. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1168. if(stackVal)
  1169. {
  1170. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  1171. }
  1172. temp = target.GetDirectory(configName, true);
  1173. temp += "/";
  1174. temp += targetNameImport;
  1175. fout << "\t\t\t\tImportLibrary=\""
  1176. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
  1177. if(this->FortranProject)
  1178. {
  1179. fout << "\n\t\t\t\tLinkDLL=\"true\"";
  1180. }
  1181. fout << "/>\n";
  1182. }
  1183. break;
  1184. case cmTarget::EXECUTABLE:
  1185. {
  1186. std::string targetName;
  1187. std::string targetNameFull;
  1188. std::string targetNameImport;
  1189. std::string targetNamePDB;
  1190. target.GetExecutableNames(targetName, targetNameFull,
  1191. targetNameImport, targetNamePDB, configName);
  1192. // Compute the link library and directory information.
  1193. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1194. if(!pcli)
  1195. {
  1196. return;
  1197. }
  1198. cmComputeLinkInformation& cli = *pcli;
  1199. std::string linkLanguage = cli.GetLinkLanguage();
  1200. bool isWin32Executable = target.GetPropertyAsBool("WIN32_EXECUTABLE");
  1201. // Compute the variable name to lookup standard libraries for this
  1202. // language.
  1203. std::string standardLibsVar = "CMAKE_";
  1204. standardLibsVar += linkLanguage;
  1205. standardLibsVar += "_STANDARD_LIBRARIES";
  1206. const char* tool = "VCLinkerTool";
  1207. if(this->FortranProject)
  1208. {
  1209. tool = "VFLinkerTool";
  1210. }
  1211. fout << "\t\t\t<Tool\n"
  1212. << "\t\t\t\tName=\"" << tool << "\"\n";
  1213. if(!gg->NeedLinkLibraryDependencies(target))
  1214. {
  1215. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1216. }
  1217. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1218. // Use the NOINHERIT macro to avoid getting VS project default
  1219. // libraries which may be set by the user to something bad.
  1220. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1221. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1222. if(this->GetVersion() < VS8 || this->FortranProject)
  1223. {
  1224. this->Internal->OutputObjects(fout, &target, " ");
  1225. }
  1226. fout << " ";
  1227. this->Internal->OutputLibraries(fout, cli.GetItems());
  1228. fout << "\"\n";
  1229. temp = target.GetDirectory(configName);
  1230. temp += "/";
  1231. temp += targetNameFull;
  1232. fout << "\t\t\t\tOutputFile=\""
  1233. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1234. this->WriteTargetVersionAttribute(fout, target);
  1235. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1236. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1237. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1238. fout << "\"\n";
  1239. std::string path = this->ConvertToXMLOutputPathSingle(
  1240. target.GetPDBDirectory(configName).c_str());
  1241. fout << "\t\t\t\tProgramDatabaseFile=\""
  1242. << path << "/" << targetNamePDB
  1243. << "\"\n";
  1244. if(targetOptions.IsDebug())
  1245. {
  1246. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1247. }
  1248. if ( this->WindowsCEProject )
  1249. {
  1250. if(this->GetVersion() < VS9)
  1251. {
  1252. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1253. }
  1254. else
  1255. {
  1256. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1257. }
  1258. if(!linkOptions.GetFlag("EntryPointSymbol"))
  1259. {
  1260. const char* entryPointSymbol = targetOptions.UsingUnicode() ?
  1261. (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup") :
  1262. (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
  1263. fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
  1264. }
  1265. }
  1266. else if ( this->FortranProject )
  1267. {
  1268. fout << "\t\t\t\tSubSystem=\""
  1269. << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
  1270. << "\"\n";
  1271. }
  1272. else
  1273. {
  1274. fout << "\t\t\t\tSubSystem=\""
  1275. << (isWin32Executable ? "2" : "1")
  1276. << "\"\n";
  1277. }
  1278. std::string stackVar = "CMAKE_";
  1279. stackVar += linkLanguage;
  1280. stackVar += "_STACK_SIZE";
  1281. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1282. if(stackVal)
  1283. {
  1284. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1285. }
  1286. temp = target.GetDirectory(configName, true);
  1287. temp += "/";
  1288. temp += targetNameImport;
  1289. fout << "\t\t\t\tImportLibrary=\""
  1290. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1291. break;
  1292. }
  1293. case cmTarget::UTILITY:
  1294. case cmTarget::GLOBAL_TARGET:
  1295. case cmTarget::INTERFACE_LIBRARY:
  1296. break;
  1297. }
  1298. }
  1299. //----------------------------------------------------------------------------
  1300. void
  1301. cmLocalVisualStudio7Generator
  1302. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  1303. {
  1304. int major;
  1305. int minor;
  1306. target.GetTargetVersion(major, minor);
  1307. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1308. }
  1309. //----------------------------------------------------------------------------
  1310. void
  1311. cmLocalVisualStudio7GeneratorInternals
  1312. ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
  1313. {
  1314. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1315. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1316. {
  1317. if(l->IsPath)
  1318. {
  1319. std::string rel = lg->Convert(l->Value.c_str(),
  1320. cmLocalGenerator::START_OUTPUT,
  1321. cmLocalGenerator::UNCHANGED);
  1322. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1323. }
  1324. else if (!l->Target
  1325. || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  1326. {
  1327. fout << l->Value << " ";
  1328. }
  1329. }
  1330. }
  1331. //----------------------------------------------------------------------------
  1332. void
  1333. cmLocalVisualStudio7GeneratorInternals
  1334. ::OutputObjects(std::ostream& fout, cmTarget* t, const char* isep)
  1335. {
  1336. // VS < 8 does not support per-config source locations so we
  1337. // list object library content on the link line instead.
  1338. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1339. cmGeneratorTarget* gt =
  1340. lg->GetGlobalGenerator()->GetGeneratorTarget(t);
  1341. std::vector<std::string> objs;
  1342. gt->UseObjectLibraries(objs, "");
  1343. const char* sep = isep? isep : "";
  1344. for(std::vector<std::string>::const_iterator
  1345. oi = objs.begin(); oi != objs.end(); ++oi)
  1346. {
  1347. std::string rel = lg->Convert(oi->c_str(),
  1348. cmLocalGenerator::START_OUTPUT,
  1349. cmLocalGenerator::UNCHANGED);
  1350. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1351. sep = " ";
  1352. }
  1353. }
  1354. //----------------------------------------------------------------------------
  1355. void
  1356. cmLocalVisualStudio7Generator
  1357. ::OutputLibraryDirectories(std::ostream& fout,
  1358. std::vector<std::string> const& dirs)
  1359. {
  1360. const char* comma = "";
  1361. for(std::vector<std::string>::const_iterator d = dirs.begin();
  1362. d != dirs.end(); ++d)
  1363. {
  1364. // Remove any trailing slash and skip empty paths.
  1365. std::string dir = *d;
  1366. if(dir[dir.size()-1] == '/')
  1367. {
  1368. dir = dir.substr(0, dir.size()-1);
  1369. }
  1370. if(dir.empty())
  1371. {
  1372. continue;
  1373. }
  1374. // Switch to a relative path specification if it is shorter.
  1375. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  1376. {
  1377. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  1378. if(rel.size() < dir.size())
  1379. {
  1380. dir = rel;
  1381. }
  1382. }
  1383. // First search a configuration-specific subdirectory and then the
  1384. // original directory.
  1385. fout << comma
  1386. << this->ConvertToXMLOutputPath((dir+"/$(ConfigurationName)").c_str())
  1387. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1388. comma = ",";
  1389. }
  1390. }
  1391. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1392. const std::string& libName,
  1393. cmTarget &target)
  1394. {
  1395. // get the configurations
  1396. std::vector<std::string> *configs =
  1397. static_cast<cmGlobalVisualStudio7Generator *>
  1398. (this->GlobalGenerator)->GetConfigurations();
  1399. // We may be modifying the source groups temporarily, so make a copy.
  1400. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1401. // get the classes from the source lists then add them to the groups
  1402. this->ModuleDefinitionFile = "";
  1403. std::vector<cmSourceFile*> classes;
  1404. if (!target.GetConfigCommonSourceFiles(classes))
  1405. {
  1406. return;
  1407. }
  1408. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1409. i != classes.end(); i++)
  1410. {
  1411. if (!(*i)->GetObjectLibrary().empty())
  1412. {
  1413. continue;
  1414. }
  1415. // Add the file to the list of sources.
  1416. std::string source = (*i)->GetFullPath();
  1417. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  1418. {
  1419. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1420. }
  1421. cmSourceGroup* sourceGroup =
  1422. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1423. sourceGroup->AssignSource(*i);
  1424. }
  1425. // open the project
  1426. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1427. // write the configuration information
  1428. this->WriteConfigurations(fout, libName, target);
  1429. fout << "\t<Files>\n";
  1430. // Loop through every source group.
  1431. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1432. {
  1433. cmSourceGroup sg = sourceGroups[i];
  1434. this->WriteGroup(&sg, target, fout, libName, configs);
  1435. }
  1436. if(this->GetVersion() >= VS8 && !this->FortranProject)
  1437. {
  1438. // VS >= 8 support per-config source locations so we
  1439. // list object library content as external objects.
  1440. cmGeneratorTarget* gt =
  1441. this->GlobalGenerator->GetGeneratorTarget(&target);
  1442. std::vector<std::string> objs;
  1443. gt->UseObjectLibraries(objs, "");
  1444. if(!objs.empty())
  1445. {
  1446. // TODO: Separate sub-filter for each object library used?
  1447. fout << "\t\t<Filter Name=\"Object Libraries\">\n";
  1448. for(std::vector<std::string>::const_iterator
  1449. oi = objs.begin(); oi != objs.end(); ++oi)
  1450. {
  1451. std::string o = this->ConvertToXMLOutputPathSingle(oi->c_str());
  1452. fout << "\t\t\t<File RelativePath=\"" << o << "\" />\n";
  1453. }
  1454. fout << "\t\t</Filter>\n";
  1455. }
  1456. }
  1457. fout << "\t</Files>\n";
  1458. // Write the VCProj file's footer.
  1459. this->WriteVCProjFooter(fout, target);
  1460. }
  1461. struct cmLVS7GFileConfig
  1462. {
  1463. std::string ObjectName;
  1464. std::string CompileFlags;
  1465. std::string CompileDefs;
  1466. std::string CompileDefsConfig;
  1467. std::string AdditionalDeps;
  1468. bool ExcludedFromBuild;
  1469. };
  1470. class cmLocalVisualStudio7GeneratorFCInfo
  1471. {
  1472. public:
  1473. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1474. cmTarget& target,
  1475. cmSourceFile const& sf,
  1476. std::vector<std::string>* configs);
  1477. std::map<std::string, cmLVS7GFileConfig> FileConfigMap;
  1478. };
  1479. cmLocalVisualStudio7GeneratorFCInfo
  1480. ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1481. cmTarget& target,
  1482. cmSourceFile const& sf,
  1483. std::vector<std::string>* configs)
  1484. {
  1485. cmGeneratorTarget* gt =
  1486. lg->GetGlobalGenerator()->GetGeneratorTarget(&target);
  1487. std::string objectName;
  1488. if(gt->HasExplicitObjectName(&sf))
  1489. {
  1490. objectName = gt->GetObjectName(&sf);
  1491. }
  1492. // Compute per-source, per-config information.
  1493. for(std::vector<std::string>::iterator i = configs->begin();
  1494. i != configs->end(); ++i)
  1495. {
  1496. std::string configUpper = cmSystemTools::UpperCase(*i);
  1497. cmLVS7GFileConfig fc;
  1498. bool needfc = false;
  1499. if(!objectName.empty())
  1500. {
  1501. fc.ObjectName = objectName;
  1502. needfc = true;
  1503. }
  1504. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1505. {
  1506. fc.CompileFlags = cflags;
  1507. needfc = true;
  1508. }
  1509. if(lg->FortranProject)
  1510. {
  1511. switch(lg->GetFortranFormat(sf.GetProperty("Fortran_FORMAT")))
  1512. {
  1513. case cmLocalGenerator::FortranFormatFixed:
  1514. fc.CompileFlags = "-fixed " + fc.CompileFlags;
  1515. needfc = true;
  1516. break;
  1517. case cmLocalGenerator::FortranFormatFree:
  1518. fc.CompileFlags = "-free " + fc.CompileFlags;
  1519. needfc = true;
  1520. break;
  1521. default: break;
  1522. }
  1523. }
  1524. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1525. {
  1526. fc.CompileDefs = cdefs;
  1527. needfc = true;
  1528. }
  1529. std::string defPropName = "COMPILE_DEFINITIONS_";
  1530. defPropName += configUpper;
  1531. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1532. {
  1533. fc.CompileDefsConfig = ccdefs;
  1534. needfc = true;
  1535. }
  1536. // Check for extra object-file dependencies.
  1537. if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
  1538. {
  1539. std::vector<std::string> depends;
  1540. cmSystemTools::ExpandListArgument(deps, depends);
  1541. const char* sep = "";
  1542. for(std::vector<std::string>::iterator j = depends.begin();
  1543. j != depends.end(); ++j)
  1544. {
  1545. fc.AdditionalDeps += sep;
  1546. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1547. sep = ";";
  1548. needfc = true;
  1549. }
  1550. }
  1551. std::string lang =
  1552. lg->GlobalGenerator->GetLanguageFromExtension
  1553. (sf.GetExtension().c_str());
  1554. const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
  1555. const std::string& linkLanguage = target.GetLinkerLanguage(i->c_str());
  1556. bool needForceLang = false;
  1557. // source file does not match its extension language
  1558. if(lang != sourceLang)
  1559. {
  1560. needForceLang = true;
  1561. lang = sourceLang;
  1562. }
  1563. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1564. // the project file
  1565. fc.ExcludedFromBuild =
  1566. (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1567. if(fc.ExcludedFromBuild)
  1568. {
  1569. needfc = true;
  1570. }
  1571. // if the source file does not match the linker language
  1572. // then force c or c++
  1573. if(needForceLang || (linkLanguage != lang))
  1574. {
  1575. if(lang == "CXX")
  1576. {
  1577. // force a C++ file type
  1578. fc.CompileFlags += " /TP ";
  1579. needfc = true;
  1580. }
  1581. else if(lang == "C")
  1582. {
  1583. // force to c
  1584. fc.CompileFlags += " /TC ";
  1585. needfc = true;
  1586. }
  1587. }
  1588. if(needfc)
  1589. {
  1590. this->FileConfigMap[*i] = fc;
  1591. }
  1592. }
  1593. }
  1594. //----------------------------------------------------------------------------
  1595. std::string
  1596. cmLocalVisualStudio7Generator
  1597. ::ComputeLongestObjectDirectory(cmTarget& target) const
  1598. {
  1599. std::vector<std::string> *configs =
  1600. static_cast<cmGlobalVisualStudio7Generator *>
  1601. (this->GlobalGenerator)->GetConfigurations();
  1602. // Compute the maximum length configuration name.
  1603. std::string config_max;
  1604. for(std::vector<std::string>::iterator i = configs->begin();
  1605. i != configs->end(); ++i)
  1606. {
  1607. if(i->size() > config_max.size())
  1608. {
  1609. config_max = *i;
  1610. }
  1611. }
  1612. // Compute the maximum length full path to the intermediate
  1613. // files directory for any configuration. This is used to construct
  1614. // object file names that do not produce paths that are too long.
  1615. std::string dir_max;
  1616. dir_max += this->Makefile->GetCurrentBinaryDirectory();
  1617. dir_max += "/";
  1618. dir_max += this->GetTargetDirectory(target);
  1619. dir_max += "/";
  1620. dir_max += config_max;
  1621. dir_max += "/";
  1622. return dir_max;
  1623. }
  1624. bool cmLocalVisualStudio7Generator
  1625. ::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
  1626. std::ostream &fout, const std::string& libName,
  1627. std::vector<std::string> *configs)
  1628. {
  1629. cmGlobalVisualStudio7Generator* gg =
  1630. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1631. const std::vector<const cmSourceFile *> &sourceFiles =
  1632. sg->GetSourceFiles();
  1633. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1634. // Write the children to temporary output.
  1635. bool hasChildrenWithSources = false;
  1636. std::ostringstream tmpOut;
  1637. for(unsigned int i=0;i<children.size();++i)
  1638. {
  1639. if(this->WriteGroup(&children[i], target, tmpOut, libName, configs))
  1640. {
  1641. hasChildrenWithSources = true;
  1642. }
  1643. }
  1644. // If the group is empty, don't write it at all.
  1645. if(sourceFiles.empty() && !hasChildrenWithSources)
  1646. {
  1647. return false;
  1648. }
  1649. // If the group has a name, write the header.
  1650. std::string name = sg->GetName();
  1651. if(name != "")
  1652. {
  1653. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1654. }
  1655. // Loop through each source in the source group.
  1656. std::string objectName;
  1657. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1658. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1659. {
  1660. std::string source = (*sf)->GetFullPath();
  1661. FCInfo fcinfo(this, target, *(*sf), configs);
  1662. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1663. target.GetType() == cmTarget::GLOBAL_TARGET )
  1664. {
  1665. fout << "\t\t\t<File\n";
  1666. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1667. // Tell MS-Dev what the source is. If the compiler knows how to
  1668. // build it, then it will.
  1669. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1670. if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
  1671. {
  1672. this->WriteCustomRule(fout, source.c_str(), *command, fcinfo);
  1673. }
  1674. else if(!fcinfo.FileConfigMap.empty())
  1675. {
  1676. const char* aCompilerTool = "VCCLCompilerTool";
  1677. const char* ppLang = "CXX";
  1678. if(this->FortranProject)
  1679. {
  1680. aCompilerTool = "VFFortranCompilerTool";
  1681. }
  1682. std::string const& lang = (*sf)->GetLanguage();
  1683. std::string ext = (*sf)->GetExtension();
  1684. ext = cmSystemTools::LowerCase(ext);
  1685. if(ext == "idl")
  1686. {
  1687. aCompilerTool = "VCMIDLTool";
  1688. if(this->FortranProject)
  1689. {
  1690. aCompilerTool = "VFMIDLTool";
  1691. }
  1692. }
  1693. if(ext == "rc")
  1694. {
  1695. aCompilerTool = "VCResourceCompilerTool";
  1696. ppLang = "RC";
  1697. if(this->FortranProject)
  1698. {
  1699. aCompilerTool = "VFResourceCompilerTool";
  1700. }
  1701. }
  1702. if(ext == "def")
  1703. {
  1704. aCompilerTool = "VCCustomBuildTool";
  1705. if(this->FortranProject)
  1706. {
  1707. aCompilerTool = "VFCustomBuildTool";
  1708. }
  1709. }
  1710. if (gg->IsMasmEnabled() && !this->FortranProject &&
  1711. lang == "ASM_MASM")
  1712. {
  1713. aCompilerTool = "MASM";
  1714. }
  1715. for(std::map<std::string, cmLVS7GFileConfig>::const_iterator
  1716. fci = fcinfo.FileConfigMap.begin();
  1717. fci != fcinfo.FileConfigMap.end(); ++fci)
  1718. {
  1719. cmLVS7GFileConfig const& fc = fci->second;
  1720. fout << "\t\t\t\t<FileConfiguration\n"
  1721. << "\t\t\t\t\tName=\"" << fci->first
  1722. << "|" << gg->GetPlatformName() << "\"";
  1723. if(fc.ExcludedFromBuild)
  1724. {
  1725. fout << " ExcludedFromBuild=\"true\"";
  1726. }
  1727. fout << ">\n";
  1728. fout << "\t\t\t\t\t<Tool\n"
  1729. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1730. if(!fc.CompileFlags.empty() ||
  1731. !fc.CompileDefs.empty() ||
  1732. !fc.CompileDefsConfig.empty())
  1733. {
  1734. Options::Tool tool = Options::Compiler;
  1735. cmVS7FlagTable const* table =
  1736. cmLocalVisualStudio7GeneratorFlagTable;
  1737. if(this->FortranProject)
  1738. {
  1739. tool = Options::FortranCompiler;
  1740. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1741. }
  1742. Options fileOptions(this, tool, table,
  1743. gg->ExtraFlagTable);
  1744. fileOptions.Parse(fc.CompileFlags.c_str());
  1745. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1746. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1747. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1748. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1749. fileOptions.OutputPreprocessorDefinitions(fout,
  1750. "\t\t\t\t\t", "\n",
  1751. ppLang);
  1752. }
  1753. if(!fc.AdditionalDeps.empty())
  1754. {
  1755. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1756. << fc.AdditionalDeps.c_str() << "\"\n";
  1757. }
  1758. if(!fc.ObjectName.empty())
  1759. {
  1760. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1761. << fc.ObjectName.c_str() << "\"\n";
  1762. }
  1763. fout << "\t\t\t\t\t/>\n"
  1764. << "\t\t\t\t</FileConfiguration>\n";
  1765. }
  1766. }
  1767. fout << "\t\t\t</File>\n";
  1768. }
  1769. }
  1770. // If the group has children with source files, write the children.
  1771. if(hasChildrenWithSources)
  1772. {
  1773. fout << tmpOut.str();
  1774. }
  1775. // If the group has a name, write the footer.
  1776. if(name != "")
  1777. {
  1778. this->WriteVCProjEndGroup(fout);
  1779. }
  1780. return true;
  1781. }
  1782. void cmLocalVisualStudio7Generator::
  1783. WriteCustomRule(std::ostream& fout,
  1784. const char* source,
  1785. const cmCustomCommand& command,
  1786. FCInfo& fcinfo)
  1787. {
  1788. cmGlobalVisualStudio7Generator* gg =
  1789. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1790. // Write the rule for each configuration.
  1791. std::vector<std::string>::iterator i;
  1792. std::vector<std::string> *configs =
  1793. static_cast<cmGlobalVisualStudio7Generator *>
  1794. (this->GlobalGenerator)->GetConfigurations();
  1795. const char* compileTool = "VCCLCompilerTool";
  1796. if(this->FortranProject)
  1797. {
  1798. compileTool = "VFCLCompilerTool";
  1799. }
  1800. const char* customTool = "VCCustomBuildTool";
  1801. if(this->FortranProject)
  1802. {
  1803. customTool = "VFCustomBuildTool";
  1804. }
  1805. for(i = configs->begin(); i != configs->end(); ++i)
  1806. {
  1807. cmCustomCommandGenerator ccg(command, *i, this->Makefile);
  1808. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1809. fout << "\t\t\t\t<FileConfiguration\n";
  1810. fout << "\t\t\t\t\tName=\"" << *i << "|"
  1811. << gg->GetPlatformName() << "\">\n";
  1812. if(!fc.CompileFlags.empty())
  1813. {
  1814. fout << "\t\t\t\t\t<Tool\n"
  1815. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1816. << "\t\t\t\t\tAdditionalOptions=\""
  1817. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1818. }
  1819. std::string comment = this->ConstructComment(ccg);
  1820. std::string script = this->ConstructScript(ccg);
  1821. if(this->FortranProject)
  1822. {
  1823. cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
  1824. }
  1825. fout << "\t\t\t\t\t<Tool\n"
  1826. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1827. << "\t\t\t\t\tDescription=\""
  1828. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1829. << "\t\t\t\t\tCommandLine=\""
  1830. << this->EscapeForXML(script.c_str()) << "\"\n"
  1831. << "\t\t\t\t\tAdditionalDependencies=\"";
  1832. if(ccg.GetDepends().empty())
  1833. {
  1834. // There are no real dependencies. Produce an artificial one to
  1835. // make sure the rule runs reliably.
  1836. if(!cmSystemTools::FileExists(source))
  1837. {
  1838. cmsys::ofstream depout(source);
  1839. depout << "Artificial dependency for a custom command.\n";
  1840. }
  1841. fout << this->ConvertToXMLOutputPath(source);
  1842. }
  1843. else
  1844. {
  1845. // Write out the dependencies for the rule.
  1846. for(std::vector<std::string>::const_iterator d =
  1847. ccg.GetDepends().begin();
  1848. d != ccg.GetDepends().end();
  1849. ++d)
  1850. {
  1851. // Get the real name of the dependency in case it is a CMake target.
  1852. std::string dep;
  1853. if(this->GetRealDependency(d->c_str(), i->c_str(), dep))
  1854. {
  1855. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1856. << ";";
  1857. }
  1858. }
  1859. }
  1860. fout << "\"\n";
  1861. fout << "\t\t\t\t\tOutputs=\"";
  1862. if(ccg.GetOutputs().empty())
  1863. {
  1864. fout << source << "_force";
  1865. }
  1866. else
  1867. {
  1868. // Write a rule for the output generated by this command.
  1869. const char* sep = "";
  1870. for(std::vector<std::string>::const_iterator o =
  1871. ccg.GetOutputs().begin();
  1872. o != ccg.GetOutputs().end();
  1873. ++o)
  1874. {
  1875. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1876. sep = ";";
  1877. }
  1878. }
  1879. fout << "\"/>\n";
  1880. fout << "\t\t\t\t</FileConfiguration>\n";
  1881. }
  1882. }
  1883. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1884. const char* group,
  1885. const char* )
  1886. {
  1887. fout << "\t\t<Filter\n"
  1888. << "\t\t\tName=\"" << group << "\"\n"
  1889. << "\t\t\tFilter=\"\">\n";
  1890. }
  1891. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1892. {
  1893. fout << "\t\t</Filter>\n";
  1894. }
  1895. // look for custom rules on a target and collect them together
  1896. void cmLocalVisualStudio7Generator
  1897. ::OutputTargetRules(std::ostream& fout,
  1898. const std::string& configName,
  1899. cmTarget &target,
  1900. const std::string& /*libName*/)
  1901. {
  1902. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1903. {
  1904. return;
  1905. }
  1906. EventWriter event(this, configName, fout);
  1907. // Add pre-build event.
  1908. const char* tool =
  1909. this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
  1910. event.Start(tool);
  1911. event.Write(target.GetPreBuildCommands());
  1912. event.Finish();
  1913. // Add pre-link event.
  1914. tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
  1915. event.Start(tool);
  1916. event.Write(target.GetPreLinkCommands());
  1917. cmsys::auto_ptr<cmCustomCommand> pcc(
  1918. this->MaybeCreateImplibDir(target, configName, this->FortranProject));
  1919. if(pcc.get())
  1920. {
  1921. event.Write(*pcc);
  1922. }
  1923. event.Finish();
  1924. // Add post-build event.
  1925. tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
  1926. event.Start(tool);
  1927. event.Write(target.GetPostBuildCommands());
  1928. event.Finish();
  1929. }
  1930. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1931. cmTarget& target)
  1932. {
  1933. // if we have all the required Source code control tags
  1934. // then add that to the project
  1935. const char* vsProjectname = target.GetProperty("VS_SCC_PROJECTNAME");
  1936. const char* vsLocalpath = target.GetProperty("VS_SCC_LOCALPATH");
  1937. const char* vsProvider = target.GetProperty("VS_SCC_PROVIDER");
  1938. if(vsProvider && vsLocalpath && vsProjectname)
  1939. {
  1940. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1941. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1942. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1943. const char* vsAuxPath = target.GetProperty("VS_SCC_AUXPATH");
  1944. if(vsAuxPath)
  1945. {
  1946. fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
  1947. }
  1948. }
  1949. }
  1950. void
  1951. cmLocalVisualStudio7Generator
  1952. ::WriteProjectStartFortran(std::ostream& fout,
  1953. const std::string& libName,
  1954. cmTarget & target)
  1955. {
  1956. cmGlobalVisualStudio7Generator* gg =
  1957. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1958. fout << "<?xml version=\"1.0\" encoding = \""
  1959. << gg->Encoding() << "\"?>\n"
  1960. << "<VisualStudioProject\n"
  1961. << "\tProjectCreator=\"Intel Fortran\"\n"
  1962. << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
  1963. const char* keyword = target.GetProperty("VS_KEYWORD");
  1964. if(!keyword)
  1965. {
  1966. keyword = "Console Application";
  1967. }
  1968. const char* projectType = 0;
  1969. switch(target.GetType())
  1970. {
  1971. case cmTarget::STATIC_LIBRARY:
  1972. projectType = "typeStaticLibrary";
  1973. if(keyword)
  1974. {
  1975. keyword = "Static Library";
  1976. }
  1977. break;
  1978. case cmTarget::SHARED_LIBRARY:
  1979. case cmTarget::MODULE_LIBRARY:
  1980. projectType = "typeDynamicLibrary";
  1981. if(!keyword)
  1982. {
  1983. keyword = "Dll";
  1984. }
  1985. break;
  1986. case cmTarget::EXECUTABLE:
  1987. if(!keyword)
  1988. {
  1989. keyword = "Console Application";
  1990. }
  1991. projectType = 0;
  1992. break;
  1993. case cmTarget::UTILITY:
  1994. case cmTarget::GLOBAL_TARGET:
  1995. default:
  1996. break;
  1997. }
  1998. if(projectType)
  1999. {
  2000. fout << "\tProjectType=\"" << projectType << "\"\n";
  2001. }
  2002. this->WriteProjectSCC(fout, target);
  2003. fout<< "\tKeyword=\"" << keyword << "\">\n"
  2004. << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n"
  2005. << "\t<Platforms>\n"
  2006. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  2007. << "\t</Platforms>\n";
  2008. }
  2009. void
  2010. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  2011. const std::string& libName,
  2012. cmTarget & target,
  2013. std::vector<cmSourceGroup> &)
  2014. {
  2015. if(this->FortranProject)
  2016. {
  2017. this->WriteProjectStartFortran(fout, libName, target);
  2018. return;
  2019. }
  2020. cmGlobalVisualStudio7Generator* gg =
  2021. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  2022. fout << "<?xml version=\"1.0\" encoding = \""
  2023. << gg->Encoding() << "\"?>\n"
  2024. << "<VisualStudioProject\n"
  2025. << "\tProjectType=\"Visual C++\"\n";
  2026. if(this->Version == VS71)
  2027. {
  2028. fout << "\tVersion=\"7.10\"\n";
  2029. }
  2030. else
  2031. {
  2032. fout << "\tVersion=\"" << (this->Version/10) << ".00\"\n";
  2033. }
  2034. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  2035. if(!projLabel)
  2036. {
  2037. projLabel = libName.c_str();
  2038. }
  2039. const char* keyword = target.GetProperty("VS_KEYWORD");
  2040. if(!keyword)
  2041. {
  2042. keyword = "Win32Proj";
  2043. }
  2044. fout << "\tName=\"" << projLabel << "\"\n";
  2045. if(this->Version >= VS8)
  2046. {
  2047. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n";
  2048. }
  2049. this->WriteProjectSCC(fout, target);
  2050. if(const char* targetFrameworkVersion =
  2051. target.GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
  2052. {
  2053. fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
  2054. }
  2055. fout << "\tKeyword=\"" << keyword << "\">\n"
  2056. << "\t<Platforms>\n"
  2057. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  2058. << "\t</Platforms>\n";
  2059. if(gg->IsMasmEnabled())
  2060. {
  2061. fout <<
  2062. "\t<ToolFiles>\n"
  2063. "\t\t<DefaultToolFile\n"
  2064. "\t\t\tFileName=\"masm.rules\"\n"
  2065. "\t\t/>\n"
  2066. "\t</ToolFiles>\n"
  2067. ;
  2068. }
  2069. }
  2070. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout,
  2071. cmTarget &target)
  2072. {
  2073. fout << "\t<Globals>\n";
  2074. cmPropertyMap const& props = target.GetProperties();
  2075. for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
  2076. {
  2077. if(i->first.find("VS_GLOBAL_") == 0)
  2078. {
  2079. std::string name = i->first.substr(10);
  2080. if(name != "")
  2081. {
  2082. fout << "\t\t<Global\n"
  2083. << "\t\t\tName=\"" << name << "\"\n"
  2084. << "\t\t\tValue=\"" << i->second.GetValue() << "\"\n"
  2085. << "\t\t/>\n";
  2086. }
  2087. }
  2088. }
  2089. fout << "\t</Globals>\n"
  2090. << "</VisualStudioProject>\n";
  2091. }
  2092. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s)
  2093. {
  2094. std::string ret = s;
  2095. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2096. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  2097. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2098. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2099. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  2100. return ret;
  2101. }
  2102. std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
  2103. {
  2104. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  2105. }
  2106. std::string cmLocalVisualStudio7Generator
  2107. ::ConvertToXMLOutputPath(const char* path)
  2108. {
  2109. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  2110. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2111. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  2112. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2113. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2114. return ret;
  2115. }
  2116. std::string cmLocalVisualStudio7Generator
  2117. ::ConvertToXMLOutputPathSingle(const char* path)
  2118. {
  2119. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  2120. cmSystemTools::ReplaceString(ret, "\"", "");
  2121. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2122. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2123. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2124. return ret;
  2125. }
  2126. // This class is used to parse an existing vs 7 project
  2127. // and extract the GUID
  2128. class cmVS7XMLParser : public cmXMLParser
  2129. {
  2130. public:
  2131. virtual void EndElement(const std::string& /* name */)
  2132. {
  2133. }
  2134. virtual void StartElement(const std::string& name, const char** atts)
  2135. {
  2136. // once the GUID is found do nothing
  2137. if(this->GUID.size())
  2138. {
  2139. return;
  2140. }
  2141. int i =0;
  2142. if("VisualStudioProject" == name)
  2143. {
  2144. while(atts[i])
  2145. {
  2146. if(strcmp(atts[i], "ProjectGUID") == 0)
  2147. {
  2148. if(atts[i+1])
  2149. {
  2150. this->GUID = atts[i+1];
  2151. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  2152. }
  2153. else
  2154. {
  2155. this->GUID = "";
  2156. }
  2157. return;
  2158. }
  2159. ++i;
  2160. }
  2161. }
  2162. }
  2163. int InitializeParser()
  2164. {
  2165. int ret = cmXMLParser::InitializeParser();
  2166. if(ret == 0)
  2167. {
  2168. return ret;
  2169. }
  2170. // visual studio projects have a strange encoding, but it is
  2171. // really utf-8
  2172. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  2173. return 1;
  2174. }
  2175. std::string GUID;
  2176. };
  2177. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  2178. const std::string& name,
  2179. const char* path)
  2180. {
  2181. cmVS7XMLParser parser;
  2182. parser.ParseFile(path);
  2183. // if we can not find a GUID then create one
  2184. if(parser.GUID.size() == 0)
  2185. {
  2186. cmGlobalVisualStudio7Generator* gg =
  2187. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  2188. gg->CreateGUID(name);
  2189. return;
  2190. }
  2191. std::string guidStoreName = name;
  2192. guidStoreName += "_GUID_CMAKE";
  2193. // save the GUID in the cache
  2194. this->GlobalGenerator->GetCMakeInstance()->
  2195. AddCacheEntry(guidStoreName.c_str(),
  2196. parser.GUID.c_str(),
  2197. "Stored GUID",
  2198. cmState::INTERNAL);
  2199. }
  2200. //----------------------------------------------------------------------------
  2201. std::string cmLocalVisualStudio7Generator
  2202. ::GetTargetDirectory(cmTarget const& target) const
  2203. {
  2204. std::string dir;
  2205. dir += target.GetName();
  2206. dir += ".dir";
  2207. return dir;
  2208. }
  2209. //----------------------------------------------------------------------------
  2210. #include <windows.h>
  2211. static bool cmLVS6G_IsFAT(const char* dir)
  2212. {
  2213. if(dir[0] && dir[1] == ':')
  2214. {
  2215. char volRoot[4] = "_:/";
  2216. volRoot[0] = dir[0];
  2217. char fsName[16];
  2218. if(GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  2219. strstr(fsName, "FAT") != 0)
  2220. {
  2221. return true;
  2222. }
  2223. }
  2224. return false;
  2225. }