cmLocalVisualStudio7Generator.cxx 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmGlobalVisualStudio7Generator.h"
  14. #include "cmLocalVisualStudio7Generator.h"
  15. #include "cmMakefile.h"
  16. #include "cmSystemTools.h"
  17. #include "cmSourceFile.h"
  18. #include "cmCacheManager.h"
  19. #include "cmake.h"
  20. cmLocalVisualStudio7Generator::cmLocalVisualStudio7Generator()
  21. {
  22. m_Version = 7;
  23. }
  24. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  25. {
  26. }
  27. void cmLocalVisualStudio7Generator::Generate(bool /* fromTheTop */)
  28. {
  29. this->OutputVCProjFile();
  30. }
  31. // TODO
  32. // for CommandLine= need to repleace quotes with &quot
  33. // write out configurations
  34. void cmLocalVisualStudio7Generator::OutputVCProjFile()
  35. {
  36. // If not an in source build, then create the output directory
  37. if(strcmp(m_Makefile->GetStartOutputDirectory(),
  38. m_Makefile->GetHomeDirectory()) != 0)
  39. {
  40. if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
  41. {
  42. cmSystemTools::Error("Error creating directory ",
  43. m_Makefile->GetStartOutputDirectory());
  44. }
  45. }
  46. m_LibraryOutputPath = "";
  47. if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  48. {
  49. m_LibraryOutputPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  50. }
  51. if(m_LibraryOutputPath.size())
  52. {
  53. // make sure there is a trailing slash
  54. if(m_LibraryOutputPath[m_LibraryOutputPath.size()-1] != '/')
  55. {
  56. m_LibraryOutputPath += "/";
  57. }
  58. }
  59. m_ExecutableOutputPath = "";
  60. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  61. {
  62. m_ExecutableOutputPath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  63. }
  64. if(m_ExecutableOutputPath.size())
  65. {
  66. // make sure there is a trailing slash
  67. if(m_ExecutableOutputPath[m_ExecutableOutputPath.size()-1] != '/')
  68. {
  69. m_ExecutableOutputPath += "/";
  70. }
  71. }
  72. // Create the VCProj or set of VCProj's for libraries and executables
  73. // clear project names
  74. m_CreatedProjectNames.clear();
  75. // expand vars for custom commands
  76. m_Makefile->ExpandVariablesInCustomCommands();
  77. // build any targets
  78. cmTargets &tgts = m_Makefile->GetTargets();
  79. for(cmTargets::iterator l = tgts.begin();
  80. l != tgts.end(); l++)
  81. {
  82. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  83. // so don't build a projectfile for it
  84. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  85. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)
  86. && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0))
  87. {
  88. this->CreateSingleVCProj(l->first.c_str(),l->second);
  89. }
  90. }
  91. }
  92. void cmLocalVisualStudio7Generator::CreateSingleVCProj(const char *lname, cmTarget &target)
  93. {
  94. // add to the list of projects
  95. std::string pname = lname;
  96. m_CreatedProjectNames.push_back(pname);
  97. // create the dsp.cmake file
  98. std::string fname;
  99. fname = m_Makefile->GetStartOutputDirectory();
  100. fname += "/";
  101. fname += lname;
  102. fname += ".vcproj";
  103. // save the name of the real dsp file
  104. std::string realVCProj = fname;
  105. fname += ".cmake";
  106. std::ofstream fout(fname.c_str());
  107. if(!fout)
  108. {
  109. cmSystemTools::Error("Error Writing ", fname.c_str());
  110. }
  111. this->WriteVCProjFile(fout,lname,target);
  112. fout.close();
  113. // if the dsp file has changed, then write it.
  114. cmSystemTools::CopyFileIfDifferent(fname.c_str(), realVCProj.c_str());
  115. }
  116. void cmLocalVisualStudio7Generator::AddVCProjBuildRule()
  117. {
  118. std::string dspname = *(m_CreatedProjectNames.end()-1);
  119. dspname += ".vcproj.cmake";
  120. std::string makefileIn = m_Makefile->GetStartDirectory();
  121. makefileIn += "/";
  122. makefileIn += "CMakeLists.txt";
  123. makefileIn = this->ConvertToRelativeOutputPath(makefileIn.c_str());
  124. std::string dsprule = "${CMAKE_COMMAND}";
  125. m_Makefile->ExpandVariablesInString(dsprule);
  126. dsprule = this->ConvertToRelativeOutputPath(dsprule.c_str());
  127. std::vector<std::string> argv;
  128. argv.push_back(makefileIn);
  129. makefileIn = m_Makefile->GetStartDirectory();
  130. makefileIn += "/";
  131. makefileIn += "CMakeLists.txt";
  132. std::string args;
  133. args = "-H";
  134. args +=
  135. this->ConvertToRelativeOutputPath(m_Makefile->GetHomeDirectory());
  136. argv.push_back(args);
  137. args = "-B";
  138. args +=
  139. this->ConvertToRelativeOutputPath(m_Makefile->GetHomeOutputDirectory());
  140. argv.push_back(args);
  141. std::string configFile =
  142. m_Makefile->GetRequiredDefinition("CMAKE_ROOT");
  143. configFile += "/Templates/CMakeWindowsSystemConfig.cmake";
  144. std::vector<std::string> listFiles = m_Makefile->GetListFiles();
  145. bool found = false;
  146. for(std::vector<std::string>::iterator i = listFiles.begin();
  147. i != listFiles.end(); ++i)
  148. {
  149. if(*i == configFile)
  150. {
  151. found = true;
  152. }
  153. }
  154. if(!found)
  155. {
  156. listFiles.push_back(configFile);
  157. }
  158. m_Makefile->AddCustomCommandToOutput(dspname.c_str(), dsprule.c_str(),
  159. argv, makefileIn.c_str(), listFiles,
  160. NULL, true);
  161. }
  162. void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout,
  163. const char *libName,
  164. const cmTarget &target)
  165. {
  166. std::vector<std::string> *configs =
  167. static_cast<cmGlobalVisualStudio7Generator *>(m_GlobalGenerator)->GetConfigurations();
  168. fout << "\t<Configurations>\n";
  169. for( std::vector<std::string>::iterator i = configs->begin();
  170. i != configs->end(); ++i)
  171. {
  172. this->WriteConfiguration(fout, i->c_str(), libName, target);
  173. }
  174. fout << "\t</Configurations>\n";
  175. }
  176. // This is a table mapping XML tag IDE names to command line options
  177. struct cmVS7FlagTable
  178. {
  179. const char* IDEName; // name used in the IDE xml file
  180. const char* commandFlag; // command line flag
  181. const char* comment; // comment
  182. const char* value; // string value
  183. };
  184. // fill the table here
  185. // currently the comment field is not used for anything other than documentation
  186. // NOTE: Make sure the longer commandFlag comes FIRST!
  187. cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
  188. {
  189. // option flags (some flags map to the same option)
  190. {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1"},
  191. {"BasicRuntimeChecks", "RTCsu", "Both stack and uninitialized checks ", "3"},
  192. {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1"},
  193. {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2"},
  194. {"BasicRuntimeChecks", "RTC1", "Both stack and uninitialized checks ", "3"},
  195. {"DebugInformationFormat", "Z7", "debug format", "1"},
  196. {"DebugInformationFormat", "Zd", "debug format", "2"},
  197. {"DebugInformationFormat", "Zi", "debug format", "3"},
  198. {"DebugInformationFormat", "ZI", "debug format", "4"},
  199. {"EnableEnhancedInstructionSet", "arch:SSE2", "Use sse2 instructions", "2"},
  200. {"EnableEnhancedInstructionSet", "arch:SSE", "Use sse instructions", "1"},
  201. {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1"},
  202. {"FavorSizeOrSpeed", "Os", "Favor small code", "2"},
  203. {"Optimization", "Od", "Non Debug", "0"},
  204. {"Optimization", "O1", "Min Size", "1"},
  205. {"Optimization", "O2", "Max Speed", "2"},
  206. {"Optimization", "Ox", "Max Optimization", "3"},
  207. {"OptimizeForProcessor", "GB", "Blended processor mode", "0"},
  208. {"OptimizeForProcessor", "G5", "Pentium", "1"},
  209. {"OptimizeForProcessor", "G6", "PPro PII PIII", "2"},
  210. {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3"},
  211. {"InlineFunctionExpansion", "Ob0", "no inlines", "0"},
  212. {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1"},
  213. {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2"},
  214. {"RuntimeLibrary", "MTd", "Multithreded debug", "1"},
  215. {"RuntimeLibrary", "MT", "Multithreded", "0"},
  216. {"RuntimeLibrary", "MDd", "Multithreded dll debug", "3"},
  217. {"RuntimeLibrary", "MD", "Multithreded dll", "2"},
  218. {"RuntimeLibrary", "MLd", "Sinble Thread debug", "5"},
  219. {"RuntimeLibrary", "ML", "Sinble Thread", "4"},
  220. {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5"},
  221. {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1"},
  222. {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2"},
  223. {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3"},
  224. {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4"},
  225. {"WarningLevel", "W1", "Warning level", "1"},
  226. {"WarningLevel", "W2", "Warning level", "2"},
  227. {"WarningLevel", "W3", "Warning level", "3"},
  228. {"WarningLevel", "W4", "Warning level", "4"},
  229. // boolean flags
  230. {"BufferSecurityCheck", "GS", "Buffer security check", "TRUE"},
  231. {"EnableFibreSafeOptimization", "GT", "OmitFramePointers", "TRUE"},
  232. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "TRUE"},
  233. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "TRUE"},
  234. {"ExceptionHandling", "GX", "enable c++ exceptions", "TRUE"},
  235. {"GlobalOptimizations", "Og", "Global Optimize", "TRUE"},
  236. {"ImproveFloatingPointConsistency", "Op", "ImproveFloatingPointConsistency", "TRUE"},
  237. {"MinimalRebuild", "Gm", "minimal rebuild", "TRUE"},
  238. {"OmitFramePointers", "Oy", "OmitFramePointers", "TRUE"},
  239. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "TRUE"},
  240. {"RuntimeTypeInfo", "GR", "Turn on Run time type information for c++", "TRUE"},
  241. {"SmallerTypeCheck", "RTCc", "smaller type check", "TRUE"},
  242. {"WarnAsError", "WX", "Treat warnings as errors", "TRUE"},
  243. {0,0,0,0 }
  244. };
  245. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  246. const char* configName,
  247. const char *libName,
  248. const cmTarget &target)
  249. {
  250. // create a map of xml tags to the values they should have in the output
  251. // for example, "BufferSecurityCheck" = "TRUE"
  252. // first fill this table with the values for the configuration Debug, Release, etc,
  253. // Then parse the command line flags specified in CMAKE_CXX_FLAGS and CMAKE_C_FLAGS
  254. // and overwrite or add new values to this map
  255. std::map<cmStdString, cmStdString> flagMap;
  256. const char* mfcFlag = m_Makefile->GetDefinition("CMAKE_MFC_FLAG");
  257. if(!mfcFlag)
  258. {
  259. mfcFlag = "0";
  260. }
  261. fout << "\t\t<Configuration\n"
  262. << "\t\t\tName=\"" << configName << "|Win32\"\n"
  263. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  264. // This is an internal type to Visual Studio, it seems that:
  265. // 4 == static library
  266. // 2 == dll
  267. // 1 == executable
  268. // 10 == utility
  269. const char* configType = "10";
  270. switch(target.GetType())
  271. {
  272. case cmTarget::STATIC_LIBRARY:
  273. configType = "4";
  274. break;
  275. case cmTarget::SHARED_LIBRARY:
  276. case cmTarget::MODULE_LIBRARY:
  277. configType = "2";
  278. break;
  279. case cmTarget::EXECUTABLE:
  280. configType = "1";
  281. break;
  282. case cmTarget::UTILITY:
  283. configType = "10";
  284. default:
  285. break;
  286. }
  287. std::string flags;
  288. std::string flagsRelease = " ";
  289. std::string flagsMinSize = " ";
  290. std::string flagsDebug = " ";
  291. std::string flagsDebugRel = " ";
  292. if(target.HasCxx())
  293. {
  294. flags = m_Makefile->GetRequiredDefinition("CMAKE_CXX_FLAGS");
  295. flagsRelease += m_Makefile->GetRequiredDefinition("CMAKE_CXX_FLAGS_RELEASE");
  296. flagsMinSize += m_Makefile->GetRequiredDefinition("CMAKE_CXX_FLAGS_MINSIZEREL");
  297. flagsDebug += m_Makefile->GetRequiredDefinition("CMAKE_CXX_FLAGS_DEBUG");
  298. flagsDebugRel += m_Makefile->GetRequiredDefinition("CMAKE_CXX_FLAGS_RELWITHDEBINFO");
  299. }
  300. else
  301. {
  302. flags = m_Makefile->GetRequiredDefinition("CMAKE_C_FLAGS");
  303. flagsRelease += m_Makefile->GetRequiredDefinition("CMAKE_C_FLAGS_RELEASE");
  304. flagsMinSize += m_Makefile->GetRequiredDefinition("CMAKE_C_FLAGS_MINSIZEREL");
  305. flagsDebug += m_Makefile->GetRequiredDefinition("CMAKE_C_FLAGS_DEBUG");
  306. flagsDebugRel += m_Makefile->GetRequiredDefinition("CMAKE_C_FLAGS_RELWITHDEBINFO");
  307. }
  308. std::string programDatabase;
  309. const char* pre = "WIN32,_DEBUG,_WINDOWS";
  310. std::string debugPostfix = "";
  311. bool debug = !strcmp(configName,"Debug");
  312. if (debug && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX"))
  313. {
  314. debugPostfix = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  315. }
  316. // fill the flagMap for Debug, Release, MinSizeRel, and RelWithDebInfo
  317. // also set the flags, and pre-defined macros
  318. if(strcmp(configName, "Debug") == 0)
  319. {
  320. flagMap["InlineFunctionExpansion"] = "0";
  321. flagMap["Optimization"] = "0";
  322. flagMap["RuntimeLibrary"] = "3";
  323. flags += flagsDebug;
  324. pre = "WIN32,_DEBUG,_WINDOWS";
  325. std::string libpath = m_LibraryOutputPath +
  326. "$(OutDir)/" + libName + debugPostfix + ".pdb";
  327. programDatabase = "\t\t\t\tProgramDatabaseFileName=\"";
  328. programDatabase += libpath;
  329. programDatabase += "\"";
  330. }
  331. else if (strcmp(configName, "Release") == 0)
  332. {
  333. flagMap["InlineFunctionExpansion"] = "1";
  334. flagMap["Optimization"] = "2";
  335. flagMap["RuntimeLibrary"] = "2";
  336. flags += flagsRelease;
  337. pre = "WIN32,_WINDOWS";
  338. flags += flagsRelease;
  339. }
  340. else if(strcmp(configName, "MinSizeRel") == 0)
  341. {
  342. flagMap["InlineFunctionExpansion"] = "1";
  343. flagMap["Optimization"] = "1";
  344. flagMap["RuntimeLibrary"] = "2";
  345. pre = "WIN32,_WINDOWS";
  346. flags += flagsMinSize;
  347. }
  348. else if(strcmp(configName, "RelWithDebInfo") == 0)
  349. {
  350. flagMap["InlineFunctionExpansion"] = "1";
  351. flagMap["Optimization"] = "2";
  352. flagMap["RuntimeLibrary"] = "2";
  353. pre = "WIN32,_WINDOWS";
  354. flags += flagsDebugRel;
  355. std::string libpath = m_LibraryOutputPath +
  356. "$(OutDir)/" + libName + debugPostfix + ".pdb";
  357. programDatabase = "\t\t\t\tProgramDatabaseFileName=\"";
  358. programDatabase += libpath;
  359. programDatabase += "\"";
  360. }
  361. fout << "\t\t\tIntermediateDirectory=\".\\" << configName << "\"\n"
  362. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  363. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  364. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  365. // if -D_UNICODE or /D_UNICODE is found in the flags
  366. // change the character set to unicode, if not then
  367. // default to MBCS
  368. std::string defs = m_Makefile->GetDefineFlags();
  369. if(flags.find("D_UNICODE") != flags.npos ||
  370. defs.find("D_UNICODE") != flags.npos)
  371. {
  372. fout << "\t\t\tCharacterSet=\"1\">\n";
  373. }
  374. else
  375. {
  376. fout << "\t\t\tCharacterSet=\"2\">\n";
  377. }
  378. fout << "\t\t\t<Tool\n"
  379. << "\t\t\t\tName=\"VCCLCompilerTool\"\n"
  380. << "\t\t\t\tAdditionalOptions=\"";
  381. // now fill the flagMap from the command line flags, and
  382. // if a flag is used, it will be removed from the flags string by
  383. // this function call
  384. this->FillFlagMapFromCommandFlags(flagMap, &cmLocalVisualStudio7GeneratorFlagTable[0], flags);
  385. // output remaining flags that were not mapped to anything
  386. fout << this->EscapeForXML(flags.c_str()).c_str();
  387. fout << " -DCMAKE_INTDIR=\\&quot;" << configName << "\\&quot;"
  388. << "\"\n";
  389. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  390. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  391. std::vector<std::string>::iterator i = includes.begin();
  392. for(;i != includes.end(); ++i)
  393. {
  394. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  395. fout << ipath << ";";
  396. }
  397. fout << "\"\n";
  398. // set a few cmake specific flags
  399. if(m_Makefile->IsOn("CMAKE_CXX_USE_RTTI"))
  400. {
  401. flagMap["RuntimeTypeInfo"] = "TRUE";
  402. }
  403. if ( m_Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL") )
  404. {
  405. flagMap["WarningLevel"] = m_Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL");
  406. }
  407. // Now copy the flag map into the xml for the file
  408. for(std::map<cmStdString, cmStdString>::iterator m = flagMap.begin();
  409. m != flagMap.end(); ++m)
  410. {
  411. fout << "\t\t\t\t" << m->first << "=\"" << m->second << "\"\n";
  412. }
  413. fout << "\t\t\t\tPreprocessorDefinitions=\"" << pre;
  414. if(target.GetType() == cmTarget::SHARED_LIBRARY
  415. || target.GetType() == cmTarget::MODULE_LIBRARY)
  416. {
  417. std::string exportSymbol;
  418. if (const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
  419. {
  420. exportSymbol = custom_export_name;
  421. }
  422. else
  423. {
  424. std::string id = libName;
  425. id += "_EXPORTS";
  426. exportSymbol = cmSystemTools::MakeCindentifier(id.c_str());
  427. }
  428. fout << "," << exportSymbol;
  429. }
  430. this->OutputDefineFlags(fout);
  431. fout << "\"\n";
  432. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  433. fout << "\t\t\t\tObjectFile=\"" << configName << "\\\"\n";
  434. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  435. {
  436. fout << "\t\t\t\tSuppressStartupBanner=\"FALSE\"\n";
  437. }
  438. if(programDatabase.size())
  439. {
  440. fout << programDatabase << "\n";
  441. }
  442. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  443. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
  444. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n"
  445. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  446. for(i = includes.begin();i != includes.end(); ++i)
  447. {
  448. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  449. fout << ipath << ";";
  450. }
  451. fout << "\"\n"
  452. << "\t\t\t\tPreprocessorDefinitions=\"" << pre;
  453. this->OutputDefineFlags(fout);
  454. fout << "\" />\n";
  455. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n";
  456. this->OutputTargetRules(fout, target, libName);
  457. this->OutputBuildTool(fout, configName, libName, target);
  458. fout << "\t\t</Configuration>\n";
  459. }
  460. void cmLocalVisualStudio7Generator::FillFlagMapFromCommandFlags(
  461. std::map<cmStdString, cmStdString>& flagMap,
  462. cmVS7FlagTable* flagTable,
  463. std::string& flags)
  464. {
  465. std::string replace;
  466. while(flagTable->IDEName)
  467. {
  468. if(flags.find(flagTable->commandFlag) != flags.npos)
  469. {
  470. // replace -flag
  471. replace = "-";
  472. replace += flagTable->commandFlag;
  473. cmSystemTools::ReplaceString(flags, replace.c_str(), "");
  474. // now replace /flag
  475. replace[0] = '/';
  476. cmSystemTools::ReplaceString(flags, replace.c_str(), "");
  477. // now put value into flag map
  478. flagMap[flagTable->IDEName] = flagTable->value;
  479. }
  480. flagTable++;
  481. }
  482. }
  483. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  484. const char* configName,
  485. const char *libName,
  486. const cmTarget &target)
  487. {
  488. std::string temp;
  489. std::string debugPostfix = "";
  490. bool debug = !strcmp(configName,"Debug");
  491. if (debug && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX"))
  492. {
  493. debugPostfix = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  494. }
  495. std::string extraLinkOptions;
  496. if(target.GetType() == cmTarget::EXECUTABLE)
  497. {
  498. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
  499. }
  500. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  501. {
  502. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
  503. }
  504. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  505. {
  506. extraLinkOptions = m_Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
  507. }
  508. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  509. if(targetLinkFlags)
  510. {
  511. extraLinkOptions += " ";
  512. extraLinkOptions += targetLinkFlags;
  513. }
  514. switch(target.GetType())
  515. {
  516. case cmTarget::STATIC_LIBRARY:
  517. {
  518. std::string libpath = m_LibraryOutputPath +
  519. "$(OutDir)/" + libName + debugPostfix + ".lib";
  520. fout << "\t\t\t<Tool\n"
  521. << "\t\t\t\tName=\"VCLibrarianTool\"\n";
  522. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  523. {
  524. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  525. }
  526. fout << "\t\t\t\tOutputFile=\""
  527. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << ".\"/>\n";
  528. break;
  529. }
  530. case cmTarget::SHARED_LIBRARY:
  531. case cmTarget::MODULE_LIBRARY:
  532. fout << "\t\t\t<Tool\n"
  533. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  534. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386";
  535. if(extraLinkOptions.size())
  536. {
  537. fout << " " << cmLocalVisualStudio7Generator::EscapeForXML(
  538. extraLinkOptions.c_str()).c_str();
  539. }
  540. fout << "\"\n"
  541. << "\t\t\t\tAdditionalDependencies=\" odbc32.lib odbccp32.lib ";
  542. this->OutputLibraries(fout, configName, libName, target);
  543. fout << "\"\n";
  544. temp = m_LibraryOutputPath;
  545. temp += configName;
  546. temp += "/";
  547. temp += libName;
  548. temp += debugPostfix;
  549. temp += ".dll";
  550. fout << "\t\t\t\tOutputFile=\""
  551. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  552. fout << "\t\t\t\tLinkIncremental=\"1\"\n";
  553. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  554. {
  555. fout << "\t\t\t\tSuppressStartupBanner=\"FALSE\"\n";
  556. }
  557. else
  558. {
  559. fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n";
  560. }
  561. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  562. this->OutputLibraryDirectories(fout, configName, libName, target);
  563. fout << "\"\n";
  564. this->OutputModuleDefinitionFile(fout, target);
  565. temp = m_LibraryOutputPath;
  566. temp += "$(OutDir)/";
  567. temp += libName;
  568. temp += debugPostfix;
  569. temp += ".pdb";
  570. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  571. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  572. if(strcmp(configName, "Debug") == 0
  573. || strcmp(configName, "RelWithDebInfo") == 0)
  574. {
  575. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  576. }
  577. if(target.HasCxx())
  578. {
  579. fout << "\t\t\t\tStackReserveSize=\""
  580. << m_Makefile->GetRequiredDefinition("CMAKE_CXX_STACK_SIZE") << "\"\n";
  581. }
  582. temp = m_LibraryOutputPath;
  583. temp += configName;
  584. temp += "/";
  585. temp += libName;
  586. temp += debugPostfix;
  587. temp += ".lib";
  588. fout << "\t\t\t\tImportLibrary=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  589. break;
  590. case cmTarget::EXECUTABLE:
  591. fout << "\t\t\t<Tool\n"
  592. << "\t\t\t\tName=\"VCLinkerTool\"\n"
  593. << "\t\t\t\tAdditionalOptions=\"/MACHINE:I386";
  594. if(extraLinkOptions.size())
  595. {
  596. fout << " " << cmLocalVisualStudio7Generator::EscapeForXML(
  597. extraLinkOptions.c_str()).c_str();
  598. }
  599. fout << "\"\n"
  600. << "\t\t\t\tAdditionalDependencies=\""
  601. << m_Makefile->GetRequiredDefinition("CMAKE_STANDARD_LIBRARIES")
  602. << " ";
  603. this->OutputLibraries(fout, configName, libName, target);
  604. fout << "\"\n";
  605. temp = m_ExecutableOutputPath;
  606. temp += configName;
  607. temp += "/";
  608. temp += libName;
  609. temp += ".exe";
  610. fout << "\t\t\t\tOutputFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  611. fout << "\t\t\t\tLinkIncremental=\"1\"\n";
  612. if(m_Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
  613. {
  614. fout << "\t\t\t\tSuppressStartupBanner=\"FALSE\"\n";
  615. }
  616. else
  617. {
  618. fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n";
  619. }
  620. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  621. this->OutputLibraryDirectories(fout, configName, libName, target);
  622. fout << "\"\n";
  623. fout << "\t\t\t\tProgramDatabaseFile=\"" << m_LibraryOutputPath
  624. << "$(OutDir)\\" << libName << ".pdb\"\n";
  625. if(strcmp(configName, "Debug") == 0
  626. || strcmp(configName, "RelWithDebInfo") == 0)
  627. {
  628. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  629. }
  630. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  631. {
  632. fout << "\t\t\t\tSubSystem=\"2\"\n";
  633. }
  634. else
  635. {
  636. fout << "\t\t\t\tSubSystem=\"1\"\n";
  637. }
  638. if(target.HasCxx())
  639. {
  640. fout << "\t\t\t\tStackReserveSize=\""
  641. << m_Makefile->GetRequiredDefinition("CMAKE_CXX_STACK_SIZE") << "\"";
  642. }
  643. fout << "/>\n";
  644. break;
  645. case cmTarget::UTILITY:
  646. break;
  647. }
  648. }
  649. void cmLocalVisualStudio7Generator::OutputModuleDefinitionFile(std::ostream& fout,
  650. const cmTarget &target)
  651. {
  652. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  653. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  654. i != classes.end(); i++)
  655. {
  656. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  657. {
  658. fout << "\t\t\t\tModuleDefinitionFile=\""
  659. << this->ConvertToXMLOutputPath((*i)->GetFullPath().c_str())
  660. << "\"\n";
  661. return;
  662. }
  663. }
  664. }
  665. void cmLocalVisualStudio7Generator::OutputLibraryDirectories(std::ostream& fout,
  666. const char*,
  667. const char*,
  668. const cmTarget &tgt)
  669. {
  670. bool hasone = false;
  671. if(m_LibraryOutputPath.size())
  672. {
  673. hasone = true;
  674. std::string temp = m_LibraryOutputPath;
  675. temp += "$(INTDIR)";
  676. fout << this->ConvertToXMLOutputPath(temp.c_str()) << "," <<
  677. this->ConvertToXMLOutputPath(m_LibraryOutputPath.c_str());
  678. }
  679. if(m_ExecutableOutputPath.size() &&
  680. (m_LibraryOutputPath != m_ExecutableOutputPath))
  681. {
  682. if (hasone)
  683. {
  684. fout << ",";
  685. }
  686. hasone = true;
  687. std::string temp = m_ExecutableOutputPath;
  688. temp += "$(INTDIR)";
  689. fout << this->ConvertToXMLOutputPath(temp.c_str()) << "," <<
  690. this->ConvertToXMLOutputPath(m_ExecutableOutputPath.c_str());
  691. }
  692. std::set<std::string> pathEmitted;
  693. std::vector<std::string>::const_iterator i;
  694. const std::vector<std::string>& libdirs = tgt.GetLinkDirectories();
  695. for(i = libdirs.begin(); i != libdirs.end(); ++i)
  696. {
  697. std::string lpath = *i;
  698. if(lpath[lpath.size()-1] != '/')
  699. {
  700. lpath += "/";
  701. }
  702. if(pathEmitted.insert(lpath).second)
  703. {
  704. if(hasone)
  705. {
  706. fout << ",";
  707. }
  708. std::string lpathi = lpath + "$(INTDIR)";
  709. fout << this->ConvertToXMLOutputPath(lpathi.c_str()) << "," <<
  710. this->ConvertToXMLOutputPath(lpath.c_str());
  711. hasone = true;
  712. }
  713. }
  714. }
  715. void cmLocalVisualStudio7Generator::OutputLibraries(std::ostream& fout,
  716. const char* configName,
  717. const char* libName,
  718. const cmTarget &target)
  719. {
  720. const cmTarget::LinkLibraries& libs = target.GetLinkLibraries();
  721. cmTarget::LinkLibraries::const_iterator j;
  722. for(j = libs.begin(); j != libs.end(); ++j)
  723. {
  724. if(j->first != libName)
  725. {
  726. std::string lib = j->first;
  727. std::string debugPostfix = "";
  728. // if this is a library we are building then watch for a debugPostfix
  729. if (!strcmp(configName,"Debug"))
  730. {
  731. std::string libPath = j->first + "_CMAKE_PATH";
  732. const char* cacheValue
  733. = m_GlobalGenerator->GetCMakeInstance()->GetCacheDefinition(libPath.c_str());
  734. if(cacheValue && *cacheValue && m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX"))
  735. {
  736. debugPostfix = m_Makefile->GetDefinition("CMAKE_DEBUG_POSTFIX");
  737. }
  738. }
  739. if(j->first.find(".lib") == std::string::npos)
  740. {
  741. lib += debugPostfix + ".lib";
  742. }
  743. lib = this->ConvertToXMLOutputPath(lib.c_str());
  744. if (j->second == cmTarget::GENERAL
  745. || (j->second == cmTarget::DEBUG && strcmp(configName, "Debug") == 0)
  746. || (j->second == cmTarget::OPTIMIZED && strcmp(configName, "Debug") != 0))
  747. {
  748. fout << lib << " ";
  749. }
  750. }
  751. }
  752. }
  753. void cmLocalVisualStudio7Generator::OutputDefineFlags(std::ostream& fout)
  754. {
  755. std::string defs = m_Makefile->GetDefineFlags();
  756. cmSystemTools::ReplaceString(defs, "/D","-D");
  757. std::string::size_type pos = defs.find("-D");
  758. bool done = pos == std::string::npos;
  759. if(!done)
  760. {
  761. fout << ",";
  762. }
  763. while(!done)
  764. {
  765. std::string::size_type nextpos = defs.find("-D", pos+2);
  766. std::string define;
  767. if(nextpos != std::string::npos)
  768. {
  769. define = defs.substr(pos+2, nextpos - pos -3);
  770. }
  771. else
  772. {
  773. define = defs.substr(pos+2);
  774. done = true;
  775. }
  776. cmSystemTools::ReplaceString(define, "\"", "&quot;");
  777. fout << define << ",";
  778. if(!done)
  779. {
  780. pos = defs.find("-D", nextpos);
  781. }
  782. }
  783. }
  784. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  785. const char *libName,
  786. cmTarget &target)
  787. {
  788. // get the configurations
  789. std::vector<std::string> *configs =
  790. static_cast<cmGlobalVisualStudio7Generator *>
  791. (m_GlobalGenerator)->GetConfigurations();
  792. // if we should add regen rule then...
  793. const char *suppRegenRule =
  794. m_Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  795. if (!cmSystemTools::IsOn(suppRegenRule))
  796. {
  797. this->AddVCProjBuildRule();
  798. }
  799. // trace the visual studio dependencies
  800. std::string name = libName;
  801. name += ".vcproj.cmake";
  802. target.TraceVSDependencies(name, m_Makefile);
  803. // We may be modifying the source groups temporarily, so make a copy.
  804. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  805. // get the classes from the source lists then add them to the groups
  806. std::vector<cmSourceFile*> & classes = target.GetSourceFiles();
  807. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  808. i != classes.end(); i++)
  809. {
  810. // Add the file to the list of sources.
  811. std::string source = (*i)->GetFullPath();
  812. if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF")
  813. {
  814. m_ModuleDefinitionFile = (*i)->GetFullPath();
  815. }
  816. cmSourceGroup& sourceGroup =
  817. m_Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  818. sourceGroup.AssignSource(*i);
  819. }
  820. // open the project
  821. this->WriteProjectStart(fout, libName, target, sourceGroups);
  822. // write the configuration information
  823. this->WriteConfigurations(fout, libName, target);
  824. fout << "\t<Files>\n";
  825. // Loop through every source group.
  826. for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
  827. sg != sourceGroups.end(); ++sg)
  828. {
  829. const std::vector<const cmSourceFile *> &sourceFiles =
  830. sg->GetSourceFiles();
  831. // If the group is empty, don't write it at all.
  832. if(sourceFiles.empty())
  833. {
  834. continue;
  835. }
  836. // If the group has a name, write the header.
  837. std::string name = sg->GetName();
  838. if(name != "")
  839. {
  840. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  841. }
  842. // Loop through each source in the source group.
  843. for(std::vector<const cmSourceFile *>::const_iterator sf =
  844. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  845. {
  846. std::string source = (*sf)->GetFullPath();
  847. const cmCustomCommand *command = (*sf)->GetCustomCommand();
  848. std::string compileFlags;
  849. std::string additionalDeps;
  850. // Check for extra compiler flags.
  851. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  852. if(cflags)
  853. {
  854. compileFlags = cflags;
  855. }
  856. if(cmSystemTools::GetFileFormat((*sf)->GetSourceExtension().c_str())
  857. == cmSystemTools::CXX_FILE_FORMAT)
  858. {
  859. // force a C++ file type
  860. compileFlags += " /TP ";
  861. }
  862. // Check for extra object-file dependencies.
  863. const char* deps = (*sf)->GetProperty("OBJECT_DEPENDS");
  864. if(deps)
  865. {
  866. std::vector<std::string> depends;
  867. cmSystemTools::ExpandListArgument(deps, depends);
  868. if(!depends.empty())
  869. {
  870. std::vector<std::string>::iterator i = depends.begin();
  871. additionalDeps = this->ConvertToXMLOutputPath(i->c_str());
  872. for(++i;i != depends.end(); ++i)
  873. {
  874. additionalDeps += ";";
  875. additionalDeps += this->ConvertToXMLOutputPath(i->c_str());
  876. }
  877. }
  878. }
  879. if (source != libName || target.GetType() == cmTarget::UTILITY)
  880. {
  881. fout << "\t\t\t<File\n";
  882. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  883. // Tell MS-Dev what the source is. If the compiler knows how to
  884. // build it, then it will.
  885. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  886. if (command)
  887. {
  888. std::string totalCommandStr;
  889. totalCommandStr =
  890. this->ConvertToRelativeOutputPath(command->GetCommand().c_str());
  891. totalCommandStr += " ";
  892. totalCommandStr += command->GetArguments();
  893. totalCommandStr += "\n";
  894. const char* comment = command->GetComment().c_str();
  895. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  896. this->WriteCustomRule(fout, source.c_str(), totalCommandStr.c_str(),
  897. (*comment?comment:"Custom Rule"),
  898. command->GetDepends(),
  899. command->GetOutput().c_str(), flags);
  900. }
  901. else if(compileFlags.size() || additionalDeps.length())
  902. {
  903. const char* aCompilerTool = "VCCLCompilerTool";
  904. if((*sf)->GetSourceExtension() == "idl")
  905. {
  906. aCompilerTool = "VCMIDLTool";
  907. }
  908. for(std::vector<std::string>::iterator i = configs->begin();
  909. i != configs->end(); ++i)
  910. {
  911. fout << "\t\t\t\t<FileConfiguration\n"
  912. << "\t\t\t\t\tName=\"" << *i << "|Win32\">\n"
  913. << "\t\t\t\t\t<Tool\n"
  914. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  915. if(compileFlags.size())
  916. {
  917. fout << "\t\t\t\t\tAdditionalOptions=\""
  918. << this->EscapeForXML(compileFlags.c_str()) << "\"\n";
  919. }
  920. if(additionalDeps.length())
  921. {
  922. fout << "\t\t\t\t\tAdditionalDependencies=\""
  923. << additionalDeps.c_str() << "\"\n";
  924. }
  925. fout << "\t\t\t\t\t/>\n"
  926. << "\t\t\t\t</FileConfiguration>\n";
  927. }
  928. }
  929. fout << "\t\t\t</File>\n";
  930. }
  931. }
  932. // If the group has a name, write the footer.
  933. if(name != "")
  934. {
  935. this->WriteVCProjEndGroup(fout);
  936. }
  937. }
  938. fout << "\t</Files>\n";
  939. // Write the VCProj file's footer.
  940. this->WriteVCProjFooter(fout);
  941. }
  942. void cmLocalVisualStudio7Generator::
  943. WriteCustomRule(std::ostream& fout,
  944. const char* source,
  945. const char* command,
  946. const char* comment,
  947. const std::vector<std::string>& depends,
  948. const char *output,
  949. const char* compileFlags)
  950. {
  951. std::string cmd = command;
  952. cmSystemTools::ReplaceString(cmd, "\"", "&quot;");
  953. std::vector<std::string>::iterator i;
  954. std::vector<std::string> *configs =
  955. static_cast<cmGlobalVisualStudio7Generator *>(m_GlobalGenerator)->GetConfigurations();
  956. for(i = configs->begin(); i != configs->end(); ++i)
  957. {
  958. fout << "\t\t\t\t<FileConfiguration\n";
  959. fout << "\t\t\t\t\tName=\"" << *i << "|Win32\">\n";
  960. if(compileFlags)
  961. {
  962. fout << "\t\t\t\t\t<Tool\n"
  963. << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
  964. << "\t\t\t\t\tAdditionalOptions=\""
  965. << this->EscapeForXML(compileFlags) << "\"/>\n";
  966. }
  967. fout << "\t\t\t\t\t<Tool\n"
  968. << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
  969. << "\t\t\t\t\tDescription=\"Building " << comment;
  970. fout << " " << output;
  971. fout << "\"\n"
  972. << "\t\t\t\t\tCommandLine=\"" << cmd << "\n\"\n"
  973. << "\t\t\t\t\tAdditionalDependencies=\"";
  974. // Write out the dependencies for the rule.
  975. std::string temp;
  976. for(std::vector<std::string>::const_iterator d = depends.begin();
  977. d != depends.end(); ++d)
  978. {
  979. std::string dep = cmSystemTools::GetFilenameName(*d);
  980. if (cmSystemTools::GetFilenameLastExtension(dep) == ".exe")
  981. {
  982. dep = cmSystemTools::GetFilenameWithoutLastExtension(dep);
  983. }
  984. // check to see if the dependency is another target built by cmake
  985. std::string libPath = dep + "_CMAKE_PATH";
  986. const char* cacheValue = m_Makefile->GetDefinition(libPath.c_str());
  987. if (cacheValue && *cacheValue)
  988. {
  989. std::string exePath = "";
  990. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  991. {
  992. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  993. }
  994. if(exePath.size())
  995. {
  996. libPath = exePath;
  997. }
  998. else
  999. {
  1000. libPath = cacheValue;
  1001. }
  1002. libPath += "/";
  1003. libPath += "$(INTDIR)/";
  1004. libPath += dep;
  1005. libPath += ".exe";
  1006. fout << this->ConvertToXMLOutputPath(libPath.c_str())
  1007. << ";";
  1008. }
  1009. else
  1010. {
  1011. fout << this->ConvertToXMLOutputPath(d->c_str())
  1012. << ";";
  1013. }
  1014. }
  1015. fout << "\"\n";
  1016. fout << "\t\t\t\t\tOutputs=\"";
  1017. if(output == 0)
  1018. {
  1019. fout << source << "_force";
  1020. }
  1021. // Write a rule for the output generated by this command.
  1022. fout << this->ConvertToXMLOutputPathSingle(output);
  1023. fout << "\"/>\n";
  1024. fout << "\t\t\t\t</FileConfiguration>\n";
  1025. }
  1026. }
  1027. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1028. const char* group,
  1029. const char* )
  1030. {
  1031. fout << "\t\t<Filter\n"
  1032. << "\t\t\tName=\"" << group << "\"\n"
  1033. << "\t\t\tFilter=\"\">\n";
  1034. }
  1035. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1036. {
  1037. fout << "\t\t</Filter>\n";
  1038. }
  1039. // look for custom rules on a target and collect them together
  1040. void cmLocalVisualStudio7Generator::OutputTargetRules(std::ostream& fout,
  1041. const cmTarget &target,
  1042. const char * /* libName */)
  1043. {
  1044. if (target.GetType() > cmTarget::UTILITY)
  1045. {
  1046. return;
  1047. }
  1048. // add the pre build rules
  1049. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"";
  1050. bool init = false;
  1051. for (std::vector<cmCustomCommand>::const_iterator cr =
  1052. target.GetPreBuildCommands().begin();
  1053. cr != target.GetPreBuildCommands().end(); ++cr)
  1054. {
  1055. cmCustomCommand cc(*cr);
  1056. cc.ExpandVariables(*m_Makefile);
  1057. if(!init)
  1058. {
  1059. fout << "\nCommandLine=\"";
  1060. init = true;
  1061. }
  1062. std::string args = cc.GetArguments();
  1063. cmSystemTools::ReplaceString(args, "\"", "&quot;");
  1064. fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " <<
  1065. args << "\n";
  1066. }
  1067. if (init)
  1068. {
  1069. fout << "\"";
  1070. }
  1071. fout << "/>\n";
  1072. // add the pre Link rules
  1073. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"";
  1074. init = false;
  1075. for (std::vector<cmCustomCommand>::const_iterator cr =
  1076. target.GetPreLinkCommands().begin();
  1077. cr != target.GetPreLinkCommands().end(); ++cr)
  1078. {
  1079. cmCustomCommand cc(*cr);
  1080. cc.ExpandVariables(*m_Makefile);
  1081. if(!init)
  1082. {
  1083. fout << "\nCommandLine=\"";
  1084. init = true;
  1085. }
  1086. std::string args = cc.GetArguments();
  1087. cmSystemTools::ReplaceString(args, "\"", "&quot;");
  1088. fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " <<
  1089. args << "\n";
  1090. }
  1091. if (init)
  1092. {
  1093. fout << "\"";
  1094. }
  1095. fout << "/>\n";
  1096. // add the PostBuild rules
  1097. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"";
  1098. init = false;
  1099. for (std::vector<cmCustomCommand>::const_iterator cr =
  1100. target.GetPostBuildCommands().begin();
  1101. cr != target.GetPostBuildCommands().end(); ++cr)
  1102. {
  1103. cmCustomCommand cc(*cr);
  1104. cc.ExpandVariables(*m_Makefile);
  1105. if(!init)
  1106. {
  1107. fout << "\nCommandLine=\"";
  1108. init = true;
  1109. }
  1110. std::string args = cc.GetArguments();
  1111. cmSystemTools::ReplaceString(args, "\"", "&quot;");
  1112. fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " <<
  1113. args << "\n";
  1114. }
  1115. if (init)
  1116. {
  1117. fout << "\"";
  1118. }
  1119. fout << "/>\n";
  1120. }
  1121. void
  1122. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1123. const char *libName,
  1124. const cmTarget &,
  1125. std::vector<cmSourceGroup> &)
  1126. {
  1127. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1128. << "<VisualStudioProject\n"
  1129. << "\tProjectType=\"Visual C++\"\n";
  1130. if(m_Version == 71)
  1131. {
  1132. fout << "\tVersion=\"7.10\"\n";
  1133. }
  1134. else
  1135. {
  1136. if (m_Version == 8)
  1137. {
  1138. fout << "\tVersion=\"8.0\"\n";
  1139. }
  1140. else
  1141. {
  1142. fout << "\tVersion=\"7.00\"\n";
  1143. }
  1144. }
  1145. fout << "\tName=\"" << libName << "\"\n"
  1146. << "\tSccProjectName=\"\"\n"
  1147. << "\tSccLocalPath=\"\"\n"
  1148. << "\tKeyword=\"Win32Proj\">\n"
  1149. << "\t<Platforms>\n"
  1150. << "\t\t<Platform\n\t\t\tName=\"Win32\"/>\n"
  1151. << "\t</Platforms>\n";
  1152. }
  1153. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
  1154. {
  1155. fout << "\t<Globals>\n"
  1156. << "\t</Globals>\n"
  1157. << "</VisualStudioProject>\n";
  1158. }
  1159. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1160. {
  1161. std::string ret = s;
  1162. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1163. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1164. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1165. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1166. return ret;
  1167. }
  1168. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPath(const char* path)
  1169. {
  1170. std::string ret = this->ConvertToRelativeOutputPath(path);
  1171. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1172. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1173. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1174. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1175. return ret;
  1176. }
  1177. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPathSingle(const char* path)
  1178. {
  1179. std::string ret = this->ConvertToRelativeOutputPath(path);
  1180. cmSystemTools::ReplaceString(ret, "\"", "");
  1181. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1182. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1183. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1184. return ret;
  1185. }
  1186. void cmLocalVisualStudio7Generator::ConfigureFinalPass()
  1187. {
  1188. cmLocalGenerator::ConfigureFinalPass();
  1189. cmTargets &tgts = m_Makefile->GetTargets();
  1190. cmGlobalVisualStudio7Generator* gg =
  1191. static_cast<cmGlobalVisualStudio7Generator *>(m_GlobalGenerator);
  1192. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1193. {
  1194. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  1195. {
  1196. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  1197. std::string project_name = cc.GetCommand();
  1198. gg->CreateGUID(project_name.c_str());
  1199. }
  1200. else
  1201. {
  1202. gg->CreateGUID(l->first.c_str());
  1203. }
  1204. }
  1205. }