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.

1492 lines
65KB

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