The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1430 lines
62KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__
  19. #define __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__
  20. #include "jucer_ProjectExporter.h"
  21. #include "jucer_ProjectSaver.h"
  22. //==============================================================================
  23. class MSVCProjectExporterBase : public ProjectExporter
  24. {
  25. public:
  26. //==============================================================================
  27. MSVCProjectExporterBase (Project& project_, const ValueTree& settings_, const char* const folderName)
  28. : ProjectExporter (project_, settings_), hasIcon (false)
  29. {
  30. if (getTargetLocation().toString().isEmpty())
  31. getTargetLocation() = getDefaultBuildsRootFolder() + folderName;
  32. if ((int) getLibraryType().getValue() <= 0)
  33. getLibraryType() = 1;
  34. projectGUID = createGUID (project.getProjectUID());
  35. }
  36. //==============================================================================
  37. bool isPossibleForCurrentProject() { return true; }
  38. bool usesMMFiles() const { return false; }
  39. bool isVisualStudio() const { return true; }
  40. void createPropertyEditors (Array <PropertyComponent*>& props)
  41. {
  42. ProjectExporter::createPropertyEditors (props);
  43. if (projectType.isLibrary())
  44. {
  45. const char* const libTypes[] = { "Static Library (.lib)", "Dynamic Library (.dll)", 0 };
  46. const int libTypeValues[] = { 1, 2, 0 };
  47. props.add (new ChoicePropertyComponent (getLibraryType(), "Library Type", StringArray (libTypes), Array<var> (libTypeValues)));
  48. props.add (new TextPropertyComponent (getSetting (Ids::libraryName_Debug), "Library Name (Debug)", 128, false));
  49. props.getLast()->setTooltip ("If set, this name will override the binary name specified in the configuration settings, for a debug build. You must include the .lib or .dll suffix on this filename.");
  50. props.add (new TextPropertyComponent (getSetting (Ids::libraryName_Release), "Library Name (Release)", 128, false));
  51. props.getLast()->setTooltip ("If set, this name will override the binary name specified in the configuration settings, for a release build. You must include the .lib or .dll suffix on this filename.");
  52. }
  53. }
  54. protected:
  55. String projectGUID;
  56. File rcFile, iconFile;
  57. bool hasIcon;
  58. File getProjectFile (const String& extension) const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (extension); }
  59. Value getLibraryType() const { return getSetting (Ids::libraryType); }
  60. bool isLibraryDLL() const { return msvcIsDLL || (projectType.isLibrary() && getLibraryType() == 2); }
  61. //==============================================================================
  62. String getIntermediatesPath (const Project::BuildConfiguration& config) const
  63. {
  64. return ".\\" + File::createLegalFileName (config.getName().toString().trim());
  65. }
  66. String getConfigTargetPath (const Project::BuildConfiguration& config) const
  67. {
  68. const String binaryPath (config.getTargetBinaryRelativePath().toString().trim());
  69. if (binaryPath.isEmpty())
  70. return getIntermediatesPath (config);
  71. RelativePath binaryRelPath (binaryPath, RelativePath::projectFolder);
  72. if (binaryRelPath.isAbsolute())
  73. return binaryRelPath.toWindowsStyle();
  74. return ".\\" + binaryRelPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder)
  75. .toWindowsStyle();
  76. }
  77. String getPreprocessorDefs (const Project::BuildConfiguration& config, const String& joinString) const
  78. {
  79. StringPairArray defines (msvcExtraPreprocessorDefs);
  80. defines.set ("WIN32", "");
  81. defines.set ("_WINDOWS", "");
  82. if (config.isDebug().getValue())
  83. {
  84. defines.set ("DEBUG", "");
  85. defines.set ("_DEBUG", "");
  86. }
  87. else
  88. {
  89. defines.set ("NDEBUG", "");
  90. }
  91. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  92. StringArray result;
  93. for (int i = 0; i < defines.size(); ++i)
  94. {
  95. String def (defines.getAllKeys()[i]);
  96. const String value (defines.getAllValues()[i]);
  97. if (value.isNotEmpty())
  98. def << "=" << value;
  99. result.add (def);
  100. }
  101. return result.joinIntoString (joinString);
  102. }
  103. StringArray getHeaderSearchPaths (const Project::BuildConfiguration& config) const
  104. {
  105. StringArray searchPaths (extraSearchPaths);
  106. searchPaths.addArray (config.getHeaderSearchPaths());
  107. searchPaths.removeDuplicates (false);
  108. return searchPaths;
  109. }
  110. String getBinaryFileForConfig (const Project::BuildConfiguration& config) const
  111. {
  112. const String targetBinary (getSetting (config.isDebug().getValue() ? Ids::libraryName_Debug : Ids::libraryName_Release).toString().trim());
  113. if (targetBinary.isNotEmpty())
  114. return targetBinary;
  115. return config.getTargetBinaryName().toString() + msvcTargetSuffix;
  116. }
  117. static String createConfigName (const Project::BuildConfiguration& config)
  118. {
  119. return config.getName().toString() + "|Win32";
  120. }
  121. //==============================================================================
  122. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString, const File& vcProject)
  123. {
  124. if (commentString.isNotEmpty())
  125. commentString += newLine;
  126. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  127. << commentString
  128. << "Project(\"" << createGUID (projectName + "sln_guid") << "\") = \"" << projectName << "\", \""
  129. << vcProject.getFileName() << "\", \"" << projectGUID << '"' << newLine
  130. << "EndProject" << newLine
  131. << "Global" << newLine
  132. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  133. int i;
  134. for (i = 0; i < configs.size(); ++i)
  135. {
  136. const Project::BuildConfiguration& config = configs.getReference(i);
  137. out << "\t\t" << createConfigName (config) << " = " << createConfigName (config) << newLine;
  138. }
  139. out << "\tEndGlobalSection" << newLine
  140. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  141. for (i = 0; i < configs.size(); ++i)
  142. {
  143. const Project::BuildConfiguration& config = configs.getReference(i);
  144. out << "\t\t" << projectGUID << "." << createConfigName (config) << ".ActiveCfg = " << createConfigName (config) << newLine;
  145. out << "\t\t" << projectGUID << "." << createConfigName (config) << ".Build.0 = " << createConfigName (config) << newLine;
  146. }
  147. out << "\tEndGlobalSection" << newLine
  148. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  149. << "\t\tHideSolutionNode = FALSE" << newLine
  150. << "\tEndGlobalSection" << newLine
  151. << "EndGlobal" << newLine;
  152. }
  153. //==============================================================================
  154. static bool writeRCFile (const File& file, const File& iconFile)
  155. {
  156. return file.deleteFile()
  157. && file.appendText ("IDI_ICON1 ICON DISCARDABLE "
  158. + iconFile.getFileName().quoted(), false, false);
  159. }
  160. static void writeIconFile (const Array<Image>& images, OutputStream& out)
  161. {
  162. out.writeShort (0); // reserved
  163. out.writeShort (1); // .ico tag
  164. out.writeShort ((short) images.size());
  165. MemoryOutputStream dataBlock;
  166. const int imageDirEntrySize = 16;
  167. const int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  168. for (int i = 0; i < images.size(); ++i)
  169. {
  170. const Image& image = images.getReference (i);
  171. const int w = image.getWidth();
  172. const int h = image.getHeight();
  173. const int maskStride = (w / 8 + 3) & ~3;
  174. const size_t oldDataSize = dataBlock.getDataSize();
  175. dataBlock.writeInt (40); // bitmapinfoheader size
  176. dataBlock.writeInt (w);
  177. dataBlock.writeInt (h * 2);
  178. dataBlock.writeShort (1); // planes
  179. dataBlock.writeShort (32); // bits
  180. dataBlock.writeInt (0); // compression
  181. dataBlock.writeInt ((h * w * 4) + (h * maskStride)); // size image
  182. dataBlock.writeInt (0); // x pixels per meter
  183. dataBlock.writeInt (0); // y pixels per meter
  184. dataBlock.writeInt (0); // clr used
  185. dataBlock.writeInt (0); // clr important
  186. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  187. const int alphaThreshold = 5;
  188. int y;
  189. for (y = h; --y >= 0;)
  190. {
  191. for (int x = 0; x < w; ++x)
  192. {
  193. const Colour pixel (bitmap.getPixelColour (x, y));
  194. if (pixel.getAlpha() <= alphaThreshold)
  195. {
  196. dataBlock.writeInt (0);
  197. }
  198. else
  199. {
  200. dataBlock.writeByte ((char) pixel.getBlue());
  201. dataBlock.writeByte ((char) pixel.getGreen());
  202. dataBlock.writeByte ((char) pixel.getRed());
  203. dataBlock.writeByte ((char) pixel.getAlpha());
  204. }
  205. }
  206. }
  207. for (y = h; --y >= 0;)
  208. {
  209. int mask = 0, count = 0;
  210. for (int x = 0; x < w; ++x)
  211. {
  212. const Colour pixel (bitmap.getPixelColour (x, y));
  213. mask <<= 1;
  214. if (pixel.getAlpha() <= alphaThreshold)
  215. mask |= 1;
  216. if (++count == 8)
  217. {
  218. dataBlock.writeByte ((char) mask);
  219. count = 0;
  220. mask = 0;
  221. }
  222. }
  223. if (mask != 0)
  224. dataBlock.writeByte ((char) mask);
  225. for (int i = maskStride - w / 8; --i >= 0;)
  226. dataBlock.writeByte (0);
  227. }
  228. out.writeByte ((char) w);
  229. out.writeByte ((char) h);
  230. out.writeByte (0);
  231. out.writeByte (0);
  232. out.writeShort (1); // colour planes
  233. out.writeShort (32); // bits per pixel
  234. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  235. out.writeInt (dataBlockStart + oldDataSize);
  236. }
  237. jassert (out.getPosition() == dataBlockStart);
  238. out << dataBlock;
  239. }
  240. bool createIconFile()
  241. {
  242. Array<Image> images;
  243. Image im (getBestIconForSize (16, true));
  244. if (im.isValid())
  245. images.add (im);
  246. im = getBestIconForSize (32, true);
  247. if (im.isValid())
  248. images.add (im);
  249. im = getBestIconForSize (48, true);
  250. if (im.isValid())
  251. images.add (im);
  252. im = getBestIconForSize (128, true);
  253. if (im.isValid())
  254. images.add (im);
  255. if (images.size() == 0)
  256. return true;
  257. MemoryOutputStream mo;
  258. writeIconFile (images, mo);
  259. iconFile = getTargetFolder().getChildFile ("icon.ico");
  260. rcFile = getTargetFolder().getChildFile ("resources.rc");
  261. hasIcon = FileHelpers::overwriteFileWithNewDataIfDifferent (iconFile, mo)
  262. && writeRCFile (rcFile, iconFile);
  263. return hasIcon;
  264. }
  265. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase);
  266. };
  267. //==============================================================================
  268. class MSVCProjectExporterVC2008 : public MSVCProjectExporterBase
  269. {
  270. public:
  271. //==============================================================================
  272. MSVCProjectExporterVC2008 (Project& project_, const ValueTree& settings_, const char* folderName = "VisualStudio2008")
  273. : MSVCProjectExporterBase (project_, settings_, folderName)
  274. {
  275. name = getName();
  276. }
  277. static const char* getName() { return "Visual Studio 2008"; }
  278. static const char* getValueTreeTypeName() { return "VS2008"; }
  279. void launchProject() { getSLNFile().startAsProcess(); }
  280. int getLaunchPreferenceOrderForCurrentOS()
  281. {
  282. #if JUCE_WINDOWS
  283. return 4;
  284. #else
  285. return 0;
  286. #endif
  287. }
  288. static MSVCProjectExporterVC2008* createForSettings (Project& project, const ValueTree& settings)
  289. {
  290. if (settings.hasType (getValueTreeTypeName()))
  291. return new MSVCProjectExporterVC2008 (project, settings);
  292. return nullptr;
  293. }
  294. //==============================================================================
  295. void create()
  296. {
  297. createIconFile();
  298. if (hasIcon)
  299. {
  300. for (int i = 0; i < groups.size(); ++i)
  301. {
  302. Project::Item& group = groups.getReference(i);
  303. if (group.getID() == ProjectSaver::getGeneratedGroupID())
  304. {
  305. group.addFile (iconFile, -1, true);
  306. group.addFile (rcFile, -1, true);
  307. group.findItemForFile (iconFile).getShouldAddToResourceValue() = false;
  308. group.findItemForFile (rcFile).getShouldAddToResourceValue() = false;
  309. break;
  310. }
  311. }
  312. }
  313. {
  314. XmlElement projectXml ("VisualStudioProject");
  315. fillInProjectXml (projectXml);
  316. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  317. }
  318. {
  319. MemoryOutputStream mo;
  320. writeSolutionFile (mo, getSolutionVersionString(), String::empty, getVCProjFile());
  321. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  322. }
  323. }
  324. protected:
  325. virtual String getProjectVersionString() const { return "9.00"; }
  326. virtual String getSolutionVersionString() const { return "10.00" + newLine + "# Visual C++ Express 2008"; }
  327. File getVCProjFile() const { return getProjectFile (".vcproj"); }
  328. File getSLNFile() const { return getProjectFile (".sln"); }
  329. //==============================================================================
  330. void fillInProjectXml (XmlElement& projectXml)
  331. {
  332. projectXml.setAttribute ("ProjectType", "Visual C++");
  333. projectXml.setAttribute ("Version", getProjectVersionString());
  334. projectXml.setAttribute ("Name", projectName);
  335. projectXml.setAttribute ("ProjectGUID", projectGUID);
  336. projectXml.setAttribute ("TargetFrameworkVersion", "131072");
  337. {
  338. XmlElement* platforms = projectXml.createNewChildElement ("Platforms");
  339. XmlElement* platform = platforms->createNewChildElement ("Platform");
  340. platform->setAttribute ("Name", "Win32");
  341. }
  342. projectXml.createNewChildElement ("ToolFiles");
  343. createConfigs (*projectXml.createNewChildElement ("Configurations"));
  344. projectXml.createNewChildElement ("References");
  345. createFiles (*projectXml.createNewChildElement ("Files"));
  346. projectXml.createNewChildElement ("Globals");
  347. }
  348. //==============================================================================
  349. void addFile (const RelativePath& file, XmlElement& parent, const bool excludeFromBuild, const bool useStdcall)
  350. {
  351. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  352. XmlElement* fileXml = parent.createNewChildElement ("File");
  353. fileXml->setAttribute ("RelativePath", file.toWindowsStyle());
  354. if (excludeFromBuild || useStdcall)
  355. {
  356. for (int i = 0; i < configs.size(); ++i)
  357. {
  358. const Project::BuildConfiguration& config = configs.getReference(i);
  359. XmlElement* fileConfig = fileXml->createNewChildElement ("FileConfiguration");
  360. fileConfig->setAttribute ("Name", createConfigName (config));
  361. if (excludeFromBuild)
  362. fileConfig->setAttribute ("ExcludedFromBuild", "true");
  363. XmlElement* tool = createToolElement (*fileConfig, "VCCLCompilerTool");
  364. if (useStdcall)
  365. tool->setAttribute ("CallingConvention", "2");
  366. }
  367. }
  368. }
  369. XmlElement* createGroup (const String& groupName, XmlElement& parent)
  370. {
  371. XmlElement* filter = parent.createNewChildElement ("Filter");
  372. filter->setAttribute ("Name", groupName);
  373. return filter;
  374. }
  375. void addFiles (const Project::Item& projectItem, XmlElement& parent)
  376. {
  377. if (projectItem.isGroup())
  378. {
  379. XmlElement* filter = createGroup (projectItem.getName().toString(), parent);
  380. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  381. addFiles (projectItem.getChild(i), *filter);
  382. }
  383. else if (projectItem.shouldBeAddedToTargetProject())
  384. {
  385. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  386. addFile (path, parent,
  387. projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()),
  388. shouldFileBeCompiledByDefault (path) && (bool) projectItem.getShouldUseStdCallValue().getValue());
  389. }
  390. }
  391. void createFiles (XmlElement& files)
  392. {
  393. for (int i = 0; i < groups.size(); ++i)
  394. if (groups.getReference(i).getNumChildren() > 0)
  395. addFiles (groups.getReference(i), files);
  396. }
  397. //==============================================================================
  398. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  399. {
  400. XmlElement* const e = parent.createNewChildElement ("Tool");
  401. e->setAttribute ("Name", toolName);
  402. return e;
  403. }
  404. void createConfig (XmlElement& xml, const Project::BuildConfiguration& config) const
  405. {
  406. String binariesPath (getConfigTargetPath (config));
  407. String intermediatesPath (getIntermediatesPath (config));
  408. const bool isDebug = (bool) config.isDebug().getValue();
  409. const String binaryName (File::createLegalFileName (config.getTargetBinaryName().toString()));
  410. xml.setAttribute ("Name", createConfigName (config));
  411. xml.setAttribute ("OutputDirectory", FileHelpers::windowsStylePath (binariesPath));
  412. xml.setAttribute ("IntermediateDirectory", FileHelpers::windowsStylePath (intermediatesPath));
  413. xml.setAttribute ("ConfigurationType", isLibraryDLL() ? "2" : (projectType.isLibrary() ? "4" : "1"));
  414. xml.setAttribute ("UseOfMFC", "0");
  415. xml.setAttribute ("ATLMinimizesCRunTimeLibraryUsage", "false");
  416. xml.setAttribute ("CharacterSet", "2");
  417. if (! isDebug)
  418. xml.setAttribute ("WholeProgramOptimization", "1");
  419. XmlElement* preBuildEvent = createToolElement (xml, "VCPreBuildEventTool");
  420. if (msvcPreBuildDescription.isNotEmpty() || msvcPreBuildCommand.isNotEmpty())
  421. {
  422. preBuildEvent->setAttribute ("Description", msvcPreBuildDescription);
  423. preBuildEvent->setAttribute ("CommandLine", msvcPreBuildCommand);
  424. }
  425. XmlElement* customBuild = createToolElement (xml, "VCCustomBuildTool");
  426. if (msvcPostBuildCommand.isNotEmpty())
  427. customBuild->setAttribute ("CommandLine", msvcPostBuildCommand);
  428. if (msvcPostBuildOutputs.isNotEmpty())
  429. customBuild->setAttribute ("Outputs", msvcPostBuildOutputs);
  430. createToolElement (xml, "VCXMLDataGeneratorTool");
  431. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  432. if (! projectType.isLibrary())
  433. {
  434. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  435. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  436. midl->setAttribute ("MkTypLibCompatible", "true");
  437. midl->setAttribute ("SuppressStartupBanner", "true");
  438. midl->setAttribute ("TargetEnvironment", "1");
  439. midl->setAttribute ("TypeLibraryName", FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".tlb"));
  440. midl->setAttribute ("HeaderFileName", "");
  441. }
  442. {
  443. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  444. const int optimiseLevel = (int) config.getOptimisationLevel().getValue();
  445. compiler->setAttribute ("Optimization", optimiseLevel <= 1 ? "0" : (optimiseLevel == 2 ? "1" : "2"));
  446. if (isDebug)
  447. {
  448. compiler->setAttribute ("BufferSecurityCheck", "");
  449. compiler->setAttribute ("DebugInformationFormat", projectType.isLibrary() ? "3" : "4");
  450. }
  451. else
  452. {
  453. compiler->setAttribute ("InlineFunctionExpansion", "1");
  454. compiler->setAttribute ("StringPooling", "true");
  455. }
  456. compiler->setAttribute ("AdditionalIncludeDirectories", replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (";")));
  457. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  458. compiler->setAttribute ("RuntimeLibrary", msvcNeedsDLLRuntimeLib ? (isDebug ? 3 : 2) // MT DLL
  459. : (isDebug ? 1 : 0)); // MT static
  460. compiler->setAttribute ("RuntimeTypeInfo", "true");
  461. compiler->setAttribute ("UsePrecompiledHeader", "0");
  462. compiler->setAttribute ("PrecompiledHeaderFile", FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".pch"));
  463. compiler->setAttribute ("AssemblerListingLocation", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  464. compiler->setAttribute ("ObjectFile", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  465. compiler->setAttribute ("ProgramDataBaseFileName", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  466. compiler->setAttribute ("WarningLevel", "4");
  467. compiler->setAttribute ("SuppressStartupBanner", "true");
  468. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlags().toString()).trim());
  469. if (extraFlags.isNotEmpty())
  470. compiler->setAttribute ("AdditionalOptions", extraFlags);
  471. }
  472. createToolElement (xml, "VCManagedResourceCompilerTool");
  473. {
  474. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  475. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  476. }
  477. createToolElement (xml, "VCPreLinkEventTool");
  478. const String outputFileName (getBinaryFileForConfig (config));
  479. if (! projectType.isLibrary())
  480. {
  481. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  482. linker->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  483. linker->setAttribute ("SuppressStartupBanner", "true");
  484. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  485. linker->setAttribute ("GenerateDebugInformation", isDebug ? "true" : "false");
  486. linker->setAttribute ("ProgramDatabaseFile", FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".pdb"));
  487. linker->setAttribute ("SubSystem", msvcIsWindowsSubsystem ? "2" : "1");
  488. if (! isDebug)
  489. {
  490. linker->setAttribute ("GenerateManifest", "false");
  491. linker->setAttribute ("OptimizeReferences", "2");
  492. linker->setAttribute ("EnableCOMDATFolding", "2");
  493. }
  494. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  495. if (msvcDelayLoadedDLLs.isNotEmpty())
  496. linker->setAttribute ("DelayLoadDLLs", msvcDelayLoadedDLLs);
  497. if (msvcModuleDefinitionFile.isNotEmpty())
  498. linker->setAttribute ("ModuleDefinitionFile", msvcModuleDefinitionFile);
  499. String extraLinkerOptions (getExtraLinkerFlags().toString());
  500. if (msvcExtraLinkerOptions.isNotEmpty())
  501. extraLinkerOptions << ' ' << msvcExtraLinkerOptions;
  502. if (extraLinkerOptions.isNotEmpty())
  503. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  504. }
  505. else
  506. {
  507. if (isLibraryDLL())
  508. {
  509. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  510. String extraLinkerOptions (getExtraLinkerFlags().toString());
  511. extraLinkerOptions << " /IMPLIB:" << FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName.upToLastOccurrenceOf (".", false, false) + ".lib");
  512. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  513. linker->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  514. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  515. }
  516. else
  517. {
  518. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  519. librarian->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  520. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  521. }
  522. }
  523. createToolElement (xml, "VCALinkTool");
  524. createToolElement (xml, "VCManifestTool");
  525. createToolElement (xml, "VCXDCMakeTool");
  526. {
  527. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  528. bscMake->setAttribute ("SuppressStartupBanner", "true");
  529. bscMake->setAttribute ("OutputFile", FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".bsc"));
  530. }
  531. createToolElement (xml, "VCFxCopTool");
  532. if (! projectType.isLibrary())
  533. createToolElement (xml, "VCAppVerifierTool");
  534. createToolElement (xml, "VCPostBuildEventTool");
  535. }
  536. void createConfigs (XmlElement& xml)
  537. {
  538. for (int i = 0; i < configs.size(); ++i)
  539. createConfig (*xml.createNewChildElement ("Configuration"), configs.getReference(i));
  540. }
  541. //==============================================================================
  542. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008);
  543. };
  544. //==============================================================================
  545. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  546. {
  547. public:
  548. MSVCProjectExporterVC2005 (Project& project_, const ValueTree& settings_)
  549. : MSVCProjectExporterVC2008 (project_, settings_, "VisualStudio2005")
  550. {
  551. name = getName();
  552. }
  553. static const char* getName() { return "Visual Studio 2005"; }
  554. static const char* getValueTreeTypeName() { return "VS2005"; }
  555. int getLaunchPreferenceOrderForCurrentOS()
  556. {
  557. #if JUCE_WINDOWS
  558. return 2;
  559. #else
  560. return 0;
  561. #endif
  562. }
  563. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  564. {
  565. if (settings.hasType (getValueTreeTypeName()))
  566. return new MSVCProjectExporterVC2005 (project, settings);
  567. return 0;
  568. }
  569. protected:
  570. String getProjectVersionString() const { return "8.00"; }
  571. String getSolutionVersionString() const { return "8.00" + newLine + "# Visual C++ Express 2005"; }
  572. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005);
  573. };
  574. //==============================================================================
  575. class MSVCProjectExporterVC6 : public MSVCProjectExporterBase
  576. {
  577. public:
  578. //==============================================================================
  579. MSVCProjectExporterVC6 (Project& project_, const ValueTree& settings_)
  580. : MSVCProjectExporterBase (project_, settings_, "MSVC6")
  581. {
  582. name = getName();
  583. }
  584. static const char* getName() { return "Visual C++ 6.0"; }
  585. static const char* getValueTreeTypeName() { return "MSVC6"; }
  586. int getLaunchPreferenceOrderForCurrentOS()
  587. {
  588. #if JUCE_WINDOWS
  589. return 1;
  590. #else
  591. return 0;
  592. #endif
  593. }
  594. void launchProject() { getDSWFile().startAsProcess(); }
  595. static MSVCProjectExporterVC6* createForSettings (Project& project, const ValueTree& settings)
  596. {
  597. if (settings.hasType (getValueTreeTypeName()))
  598. return new MSVCProjectExporterVC6 (project, settings);
  599. return nullptr;
  600. }
  601. //==============================================================================
  602. void create()
  603. {
  604. {
  605. MemoryOutputStream mo;
  606. writeProject (mo);
  607. overwriteFileIfDifferentOrThrow (getDSPFile(), mo);
  608. }
  609. {
  610. MemoryOutputStream mo;
  611. writeDSWFile (mo);
  612. overwriteFileIfDifferentOrThrow (getDSWFile(), mo);
  613. }
  614. }
  615. private:
  616. File getDSPFile() const { return getProjectFile (".dsp"); }
  617. File getDSWFile() const { return getProjectFile (".dsw"); }
  618. //==============================================================================
  619. String createConfigName (const Project::BuildConfiguration& config) const
  620. {
  621. return projectName + " - Win32 " + config.getName().toString();
  622. }
  623. void writeProject (OutputStream& out)
  624. {
  625. const String defaultConfigName (createConfigName (configs.getReference(0)));
  626. String targetType, targetCode;
  627. if (isLibraryDLL()) { targetType = "\"Win32 (x86) Dynamic-Link Library\""; targetCode = "0x0102"; }
  628. else if (projectType.isLibrary()) { targetType = "\"Win32 (x86) Static Library\""; targetCode = "0x0104"; }
  629. else if (projectType.isCommandLineApp()) { targetType = "\"Win32 (x86) Console Application\""; targetCode = "0x0103"; }
  630. else { targetType = "\"Win32 (x86) Application\""; targetCode = "0x0101"; }
  631. out << "# Microsoft Developer Studio Project File - Name=\"" << projectName
  632. << "\" - Package Owner=<4>" << newLine
  633. << "# Microsoft Developer Studio Generated Build File, Format Version 6.00" << newLine
  634. << "# ** DO NOT EDIT **" << newLine
  635. << "# TARGTYPE " << targetType << " " << targetCode << newLine
  636. << "CFG=" << defaultConfigName << newLine
  637. << "!MESSAGE This is not a valid makefile. To build this project using NMAKE," << newLine
  638. << "!MESSAGE use the Export Makefile command and run" << newLine
  639. << "!MESSAGE " << newLine
  640. << "!MESSAGE NMAKE /f \"" << projectName << ".mak.\"" << newLine
  641. << "!MESSAGE " << newLine
  642. << "!MESSAGE You can specify a configuration when running NMAKE" << newLine
  643. << "!MESSAGE by defining the macro CFG on the command line. For example:" << newLine
  644. << "!MESSAGE " << newLine
  645. << "!MESSAGE NMAKE /f \"" << projectName << ".mak\" CFG=\"" << defaultConfigName << '"' << newLine
  646. << "!MESSAGE " << newLine
  647. << "!MESSAGE Possible choices for configuration are:" << newLine
  648. << "!MESSAGE " << newLine;
  649. int i;
  650. for (i = 0; i < configs.size(); ++i)
  651. out << "!MESSAGE \"" << createConfigName (configs.getReference (i)) << "\" (based on " << targetType << ")" << newLine;
  652. out << "!MESSAGE " << newLine
  653. << "# Begin Project" << newLine
  654. << "# PROP AllowPerConfigDependencies 0" << newLine
  655. << "# PROP Scc_ProjName \"\"" << newLine
  656. << "# PROP Scc_LocalPath \"\"" << newLine
  657. << "CPP=cl.exe" << newLine
  658. << "MTL=midl.exe" << newLine
  659. << "RSC=rc.exe" << newLine;
  660. String targetList;
  661. for (i = 0; i < configs.size(); ++i)
  662. {
  663. const Project::BuildConfiguration& config = configs.getReference(i);
  664. const String configName (createConfigName (config));
  665. targetList << "# Name \"" << configName << '"' << newLine;
  666. const String binariesPath (getConfigTargetPath (config));
  667. const String targetBinary (FileHelpers::windowsStylePath (binariesPath + "/" + getBinaryFileForConfig (config)));
  668. const String optimisationFlag (((int) config.getOptimisationLevel().getValue() <= 1) ? "Od" : (config.getOptimisationLevel() == 2 ? "O2" : "O3"));
  669. const String defines (getPreprocessorDefs (config, " /D "));
  670. const bool isDebug = (bool) config.isDebug().getValue();
  671. const String extraDebugFlags (isDebug ? "/Gm /ZI /GZ" : "");
  672. out << (i == 0 ? "!IF" : "!ELSEIF") << " \"$(CFG)\" == \"" << configName << '"' << newLine
  673. << "# PROP BASE Use_MFC 0" << newLine
  674. << "# PROP BASE Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  675. << "# PROP BASE Output_Dir \"" << binariesPath << '"' << newLine
  676. << "# PROP BASE Intermediate_Dir \"" << getIntermediatesPath (config) << '"' << newLine
  677. << "# PROP BASE Target_Dir \"\"" << newLine
  678. << "# PROP Use_MFC 0" << newLine
  679. << "# PROP Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  680. << "# PROP Output_Dir \"" << binariesPath << '"' << newLine
  681. << "# PROP Intermediate_Dir \"" << getIntermediatesPath (config) << '"' << newLine
  682. << "# PROP Ignore_Export_Lib 0" << newLine
  683. << "# PROP Target_Dir \"\"" << newLine
  684. << "# ADD BASE CPP /nologo /W3 /GX /" << optimisationFlag << " /D " << defines
  685. << " /YX /FD /c " << extraDebugFlags << " /Zm1024" << newLine
  686. << "# ADD CPP /nologo " << (isDebug ? "/MTd" : "/MT") << " /W3 /GR /GX /" << optimisationFlag
  687. << " /I " << replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (" /I "))
  688. << " /D " << defines << " /D \"_UNICODE\" /D \"UNICODE\" /FD /c /Zm1024 " << extraDebugFlags
  689. << " " << replacePreprocessorTokens (config, getExtraCompilerFlags().toString()).trim() << newLine;
  690. if (! isDebug)
  691. out << "# SUBTRACT CPP /YX" << newLine;
  692. if (! projectType.isLibrary())
  693. out << "# ADD BASE MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine
  694. << "# ADD MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine;
  695. out << "# ADD BASE RSC /l 0x40c /d " << defines << newLine
  696. << "# ADD RSC /l 0x40c /d " << defines << newLine
  697. << "BSC32=bscmake.exe" << newLine
  698. << "# ADD BASE BSC32 /nologo" << newLine
  699. << "# ADD BSC32 /nologo" << newLine;
  700. if (projectType.isLibrary())
  701. {
  702. out << "LIB32=link.exe -lib" << newLine
  703. << "# ADD BASE LIB32 /nologo" << newLine
  704. << "# ADD LIB32 /nologo /out:\"" << targetBinary << '"' << newLine;
  705. }
  706. else
  707. {
  708. out << "LINK32=link.exe" << newLine
  709. << "# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386" << newLine
  710. << "# ADD LINK32 \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\LIB\\shell32.lib\" " // This is avoid debug information corruption when mixing Platform SDK
  711. << "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "
  712. << (isDebug ? " /debug" : "")
  713. << " /nologo /machine:I386 /out:\"" << targetBinary << "\" "
  714. << (isLibraryDLL() ? "/dll" : (msvcIsWindowsSubsystem ? "/subsystem:windows "
  715. : "/subsystem:console "))
  716. << replacePreprocessorTokens (config, getExtraLinkerFlags().toString()).trim() << newLine;
  717. }
  718. }
  719. out << "!ENDIF" << newLine
  720. << "# Begin Target" << newLine
  721. << targetList;
  722. for (int i = 0; i < groups.size(); ++i)
  723. if (groups.getReference(i).getNumChildren() > 0)
  724. writeFiles (out, groups.getReference(i));
  725. out << "# End Target" << newLine
  726. << "# End Project" << newLine;
  727. }
  728. void writeFile (OutputStream& out, const RelativePath& file, const bool excludeFromBuild)
  729. {
  730. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  731. out << "# Begin Source File" << newLine
  732. << "SOURCE=" << file.toWindowsStyle().quoted() << newLine;
  733. if (excludeFromBuild)
  734. out << "# PROP Exclude_From_Build 1" << newLine;
  735. out << "# End Source File" << newLine;
  736. }
  737. void writeFiles (OutputStream& out, const Project::Item& projectItem)
  738. {
  739. if (projectItem.isGroup())
  740. {
  741. out << "# Begin Group \"" << projectItem.getName() << '"' << newLine
  742. << "# PROP Default_Filter \"cpp;c;cc;cxx;rc;def;r;odl;idl;hpj;bat\"" << newLine;
  743. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  744. writeFiles (out, projectItem.getChild (i));
  745. out << "# End Group" << newLine;
  746. }
  747. else if (projectItem.shouldBeAddedToTargetProject())
  748. {
  749. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  750. writeFile (out, path, projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()));
  751. }
  752. }
  753. void writeGroup (OutputStream& out, const String& groupName, const Array<RelativePath>& files)
  754. {
  755. if (files.size() > 0)
  756. {
  757. out << "# Begin Group \"" << groupName << '"' << newLine;
  758. for (int i = 0; i < files.size(); ++i)
  759. if (files.getReference(i).hasFileExtension ("cpp;cc;c;cxx;h;hpp;hxx"))
  760. writeFile (out, files.getReference(i), false);
  761. out << "# End Group" << newLine;
  762. }
  763. }
  764. void writeDSWFile (OutputStream& out)
  765. {
  766. out << "Microsoft Developer Studio Workspace File, Format Version 6.00 " << newLine;
  767. /*if (! project.isUsingWrapperFiles())
  768. {
  769. out << "Project: \"JUCE\"= ..\\JUCE.dsp - Package Owner=<4>" << newLine
  770. << "Package=<5>" << newLine
  771. << "{{{" << newLine
  772. << "}}}" << newLine
  773. << "Package=<4>" << newLine
  774. << "{{{" << newLine
  775. << "}}}" << newLine;
  776. }*/
  777. out << "Project: \"" << projectName << "\" = .\\" << getDSPFile().getFileName() << " - Package Owner=<4>" << newLine
  778. << "Package=<5>" << newLine
  779. << "{{{" << newLine
  780. << "}}}" << newLine
  781. << "Package=<4>" << newLine
  782. << "{{{" << newLine;
  783. /*if (! project.isUsingWrapperFiles())
  784. {
  785. out << " Begin Project Dependency" << newLine
  786. << " Project_Dep_Name JUCE" << newLine
  787. << " End Project Dependency" << newLine;
  788. }*/
  789. out << "}}}" << newLine
  790. << "Global:" << newLine
  791. << "Package=<5>" << newLine
  792. << "{{{" << newLine
  793. << "}}}" << newLine
  794. << "Package=<3>" << newLine
  795. << "{{{" << newLine
  796. << "}}}" << newLine;
  797. }
  798. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC6);
  799. };
  800. //==============================================================================
  801. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  802. {
  803. public:
  804. MSVCProjectExporterVC2010 (Project& project_, const ValueTree& settings_)
  805. : MSVCProjectExporterBase (project_, settings_, "VisualStudio2010")
  806. {
  807. name = getName();
  808. }
  809. static const char* getName() { return "Visual Studio 2010"; }
  810. static const char* getValueTreeTypeName() { return "VS2010"; }
  811. int getLaunchPreferenceOrderForCurrentOS()
  812. {
  813. #if JUCE_WINDOWS
  814. return 3;
  815. #else
  816. return 0;
  817. #endif
  818. }
  819. void launchProject() { getSLNFile().startAsProcess(); }
  820. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  821. {
  822. if (settings.hasType (getValueTreeTypeName()))
  823. return new MSVCProjectExporterVC2010 (project, settings);
  824. return nullptr;
  825. }
  826. //==============================================================================
  827. void create()
  828. {
  829. createIconFile();
  830. {
  831. XmlElement projectXml ("Project");
  832. fillInProjectXml (projectXml);
  833. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  834. }
  835. {
  836. XmlElement filtersXml ("Project");
  837. fillInFiltersXml (filtersXml);
  838. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  839. }
  840. {
  841. MemoryOutputStream mo;
  842. writeSolutionFile (mo, "11.00", "# Visual Studio 2010", getVCProjFile());
  843. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  844. }
  845. }
  846. protected:
  847. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  848. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  849. File getSLNFile() const { return getProjectFile (".sln"); }
  850. static String createConfigName (const Project::BuildConfiguration& config)
  851. {
  852. return config.getName().toString() + "|Win32";
  853. }
  854. static void setConditionAttribute (XmlElement& xml, const Project::BuildConfiguration& config)
  855. {
  856. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  857. }
  858. //==============================================================================
  859. void fillInProjectXml (XmlElement& projectXml)
  860. {
  861. projectXml.setAttribute ("DefaultTargets", "Build");
  862. projectXml.setAttribute ("ToolsVersion", "4.0");
  863. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  864. {
  865. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  866. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  867. for (int i = 0; i < configs.size(); ++i)
  868. {
  869. const Project::BuildConfiguration& config = configs.getReference(i);
  870. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  871. e->setAttribute ("Include", createConfigName (config));
  872. e->createNewChildElement ("Configuration")->addTextElement (config.getName().toString());
  873. e->createNewChildElement ("Platform")->addTextElement ("Win32");
  874. }
  875. }
  876. {
  877. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  878. globals->setAttribute ("Label", "Globals");
  879. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  880. }
  881. {
  882. XmlElement* imports = projectXml.createNewChildElement ("Import");
  883. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  884. }
  885. for (int i = 0; i < configs.size(); ++i)
  886. {
  887. const Project::BuildConfiguration& config = configs.getReference(i);
  888. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  889. setConditionAttribute (*e, config);
  890. e->setAttribute ("Label", "Configuration");
  891. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  892. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  893. e->createNewChildElement ("CharacterSet")->addTextElement ("MultiByte");
  894. if (! config.isDebug().getValue())
  895. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  896. }
  897. {
  898. XmlElement* e = projectXml.createNewChildElement ("Import");
  899. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  900. }
  901. {
  902. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  903. e->setAttribute ("Label", "ExtensionSettings");
  904. }
  905. {
  906. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  907. e->setAttribute ("Label", "PropertySheets");
  908. XmlElement* p = e->createNewChildElement ("Import");
  909. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  910. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  911. p->setAttribute ("Label", "LocalAppDataPlatform");
  912. }
  913. {
  914. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  915. e->setAttribute ("Label", "UserMacros");
  916. }
  917. {
  918. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  919. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  920. for (int i = 0; i < configs.size(); ++i)
  921. {
  922. const Project::BuildConfiguration& config = configs.getReference(i);
  923. XmlElement* outdir = props->createNewChildElement ("OutDir");
  924. setConditionAttribute (*outdir, config);
  925. outdir->addTextElement (getConfigTargetPath (config) + "\\");
  926. XmlElement* intdir = props->createNewChildElement ("IntDir");
  927. setConditionAttribute (*intdir, config);
  928. intdir->addTextElement (getConfigTargetPath (config) + "\\");
  929. XmlElement* name = props->createNewChildElement ("TargetName");
  930. setConditionAttribute (*name, config);
  931. name->addTextElement (getBinaryFileForConfig (config).upToLastOccurrenceOf (".", false, false));
  932. }
  933. }
  934. for (int i = 0; i < configs.size(); ++i)
  935. {
  936. const Project::BuildConfiguration& config = configs.getReference(i);
  937. String binariesPath (getConfigTargetPath (config));
  938. String intermediatesPath (getIntermediatesPath (config));
  939. const bool isDebug = (bool) config.isDebug().getValue();
  940. const String binaryName (File::createLegalFileName (config.getTargetBinaryName().toString()));
  941. const String outputFileName (getBinaryFileForConfig (config));
  942. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  943. setConditionAttribute (*group, config);
  944. {
  945. XmlElement* midl = group->createNewChildElement ("Midl");
  946. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  947. : "NDEBUG;%(PreprocessorDefinitions)");
  948. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  949. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  950. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  951. //midl->createNewChildElement ("TypeLibraryName")->addTextElement ("");
  952. midl->createNewChildElement ("HeaderFileName");
  953. }
  954. {
  955. XmlElement* cl = group->createNewChildElement ("ClCompile");
  956. cl->createNewChildElement ("Optimization")->addTextElement (isDebug ? "Disabled" : "MaxSpeed");
  957. if (isDebug)
  958. cl->createNewChildElement ("DebugInformationFormat")->addTextElement ("EditAndContinue");
  959. StringArray includePaths (getHeaderSearchPaths (config));
  960. includePaths.add ("%(AdditionalIncludeDirectories)");
  961. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  962. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  963. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (msvcNeedsDLLRuntimeLib ? (isDebug ? "MultiThreadedDLLDebug" : "MultiThreadedDLL")
  964. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  965. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  966. cl->createNewChildElement ("PrecompiledHeader");
  967. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  968. cl->createNewChildElement ("ObjectFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  969. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  970. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level4");
  971. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  972. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  973. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlags().toString()).trim());
  974. if (extraFlags.isNotEmpty())
  975. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  976. }
  977. {
  978. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  979. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  980. : "NDEBUG;%(PreprocessorDefinitions)");
  981. }
  982. {
  983. XmlElement* link = group->createNewChildElement ("Link");
  984. link->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  985. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  986. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  987. : "%(IgnoreSpecificDefaultLibraries)");
  988. link->createNewChildElement ("GenerateDebugInformation")->addTextElement (isDebug ? "true" : "false");
  989. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".pdb"));
  990. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  991. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  992. if (! isDebug)
  993. {
  994. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  995. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  996. }
  997. String extraLinkerOptions (getExtraLinkerFlags().toString());
  998. if (extraLinkerOptions.isNotEmpty())
  999. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  1000. + " %(AdditionalOptions)");
  1001. }
  1002. {
  1003. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  1004. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1005. bsc->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".bsc"));
  1006. }
  1007. }
  1008. {
  1009. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1010. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1011. for (int i = 0; i < groups.size(); ++i)
  1012. if (groups.getReference(i).getNumChildren() > 0)
  1013. addFilesToCompile (groups.getReference(i), *cppFiles, *headerFiles, false);
  1014. }
  1015. if (hasIcon)
  1016. {
  1017. {
  1018. XmlElement* iconGroup = projectXml.createNewChildElement ("ItemGroup");
  1019. XmlElement* e = iconGroup->createNewChildElement ("None");
  1020. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1021. }
  1022. {
  1023. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1024. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1025. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1026. }
  1027. }
  1028. {
  1029. XmlElement* e = projectXml.createNewChildElement ("Import");
  1030. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1031. }
  1032. {
  1033. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1034. e->setAttribute ("Label", "ExtensionTargets");
  1035. }
  1036. }
  1037. String getProjectType() const
  1038. {
  1039. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1040. else if (isLibraryDLL()) return "DynamicLibrary";
  1041. else if (projectType.isLibrary()) return "StaticLibrary";
  1042. jassertfalse;
  1043. return String::empty;
  1044. }
  1045. //==============================================================================
  1046. void addFileToCompile (const RelativePath& file, XmlElement& cpps, XmlElement& headers, const bool excludeFromBuild, const bool useStdcall)
  1047. {
  1048. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1049. if (file.hasFileExtension ("cpp;cc;cxx;c"))
  1050. {
  1051. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1052. e->setAttribute ("Include", file.toWindowsStyle());
  1053. if (excludeFromBuild)
  1054. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1055. if (useStdcall)
  1056. {
  1057. jassertfalse;
  1058. }
  1059. }
  1060. else if (file.hasFileExtension (headerFileExtensions))
  1061. {
  1062. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", file.toWindowsStyle());
  1063. }
  1064. }
  1065. void addFilesToCompile (const Array<RelativePath>& files, XmlElement& cpps, XmlElement& headers, bool useStdCall)
  1066. {
  1067. for (int i = 0; i < files.size(); ++i)
  1068. addFileToCompile (files.getReference(i), cpps, headers, false, useStdCall);
  1069. }
  1070. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, bool useStdCall)
  1071. {
  1072. if (projectItem.isGroup())
  1073. {
  1074. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1075. addFilesToCompile (projectItem.getChild(i), cpps, headers, useStdCall);
  1076. }
  1077. else
  1078. {
  1079. if (projectItem.shouldBeAddedToTargetProject())
  1080. {
  1081. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1082. if (path.hasFileExtension (headerFileExtensions) || (path.hasFileExtension ("cpp;cc;c;cxx")))
  1083. addFileToCompile (path, cpps, headers, ! projectItem.shouldBeCompiled(), useStdCall);
  1084. }
  1085. }
  1086. }
  1087. //==============================================================================
  1088. void addFilterGroup (XmlElement& groups, const String& path)
  1089. {
  1090. XmlElement* e = groups.createNewChildElement ("Filter");
  1091. e->setAttribute ("Include", path);
  1092. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1093. }
  1094. void addFileToFilter (const RelativePath& file, const String& groupPath, XmlElement& cpps, XmlElement& headers)
  1095. {
  1096. XmlElement* e;
  1097. if (file.hasFileExtension (headerFileExtensions))
  1098. e = headers.createNewChildElement ("ClInclude");
  1099. else
  1100. e = cpps.createNewChildElement ("ClCompile");
  1101. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1102. e->setAttribute ("Include", file.toWindowsStyle());
  1103. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1104. }
  1105. void addFilesToFilter (const Project::Item& projectItem, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1106. {
  1107. if (projectItem.isGroup())
  1108. {
  1109. addFilterGroup (groups, path);
  1110. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1111. addFilesToFilter (projectItem.getChild(i),
  1112. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName().toString(),
  1113. cpps, headers, groups);
  1114. }
  1115. else
  1116. {
  1117. if (projectItem.shouldBeAddedToTargetProject())
  1118. {
  1119. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1120. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers);
  1121. }
  1122. }
  1123. }
  1124. void addFilesToFilter (const Array<RelativePath>& files, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1125. {
  1126. if (files.size() > 0)
  1127. {
  1128. addFilterGroup (groups, path);
  1129. for (int i = 0; i < files.size(); ++i)
  1130. addFileToFilter (files.getReference(i), path, cpps, headers);
  1131. }
  1132. }
  1133. void fillInFiltersXml (XmlElement& filterXml)
  1134. {
  1135. filterXml.setAttribute ("ToolsVersion", "4.0");
  1136. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1137. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1138. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1139. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1140. for (int i = 0; i < groups.size(); ++i)
  1141. if (groups.getReference(i).getNumChildren() > 0)
  1142. addFilesToFilter (groups.getReference(i), groups.getReference(i).getName().toString(), *cpps, *headers, *groupsXml);
  1143. if (iconFile.exists())
  1144. {
  1145. {
  1146. XmlElement* iconGroup = filterXml.createNewChildElement ("ItemGroup");
  1147. XmlElement* e = iconGroup->createNewChildElement ("None");
  1148. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1149. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1150. }
  1151. {
  1152. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1153. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1154. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1155. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1156. }
  1157. }
  1158. }
  1159. //==============================================================================
  1160. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010);
  1161. };
  1162. #endif // __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__