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.

1473 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. for (int i = 0; i < libraryModules.size(); ++i)
  128. libraryModules.getUnchecked(i)->addExtraSearchPaths (*this, searchPaths);
  129. return searchPaths;
  130. }
  131. String getBinaryFileForConfig (const Project::BuildConfiguration& config) const
  132. {
  133. const String targetBinary (getSetting (config.isDebug().getValue() ? Ids::libraryName_Debug : Ids::libraryName_Release).toString().trim());
  134. if (targetBinary.isNotEmpty())
  135. return targetBinary;
  136. return config.getTargetBinaryName().toString() + getTargetBinarySuffix();
  137. }
  138. static String createConfigName (const Project::BuildConfiguration& config)
  139. {
  140. return config.getName().toString() + "|Win32";
  141. }
  142. //==============================================================================
  143. void writeSolutionFile (OutputStream& out, const String& versionString, const File& vcProject)
  144. {
  145. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  146. << "Project(\"" << createGUID (project.getProjectName().toString() + "sln_guid") << "\") = \"" << project.getProjectName().toString() << "\", \""
  147. << vcProject.getFileName() << "\", \"" << projectGUID << '"' << newLine
  148. << "EndProject" << newLine
  149. << "Global" << newLine
  150. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  151. int i;
  152. for (i = 0; i < project.getNumConfigurations(); ++i)
  153. {
  154. Project::BuildConfiguration config (project.getConfiguration (i));
  155. out << "\t\t" << createConfigName (config) << " = " << createConfigName (config) << newLine;
  156. }
  157. out << "\tEndGlobalSection" << newLine
  158. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  159. for (i = 0; i < project.getNumConfigurations(); ++i)
  160. {
  161. Project::BuildConfiguration config (project.getConfiguration (i));
  162. out << "\t\t" << projectGUID << "." << createConfigName (config) << ".ActiveCfg = " << createConfigName (config) << newLine;
  163. out << "\t\t" << projectGUID << "." << createConfigName (config) << ".Build.0 = " << createConfigName (config) << newLine;
  164. }
  165. out << "\tEndGlobalSection" << newLine
  166. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  167. << "\t\tHideSolutionNode = FALSE" << newLine
  168. << "\tEndGlobalSection" << newLine
  169. << "EndGlobal" << newLine;
  170. }
  171. //==============================================================================
  172. static bool writeRCFile (const File& file, const File& iconFile)
  173. {
  174. return file.deleteFile()
  175. && file.appendText ("IDI_ICON1 ICON DISCARDABLE "
  176. + iconFile.getFileName().quoted(), false, false);
  177. }
  178. static void writeIconFile (const Array<Image>& images, OutputStream& out)
  179. {
  180. out.writeShort (0); // reserved
  181. out.writeShort (1); // .ico tag
  182. out.writeShort ((short) images.size());
  183. MemoryOutputStream dataBlock;
  184. const int imageDirEntrySize = 16;
  185. const int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  186. for (int i = 0; i < images.size(); ++i)
  187. {
  188. const Image& image = images.getReference (i);
  189. const int w = image.getWidth();
  190. const int h = image.getHeight();
  191. const int maskStride = (w / 8 + 3) & ~3;
  192. const size_t oldDataSize = dataBlock.getDataSize();
  193. dataBlock.writeInt (40); // bitmapinfoheader size
  194. dataBlock.writeInt (w);
  195. dataBlock.writeInt (h * 2);
  196. dataBlock.writeShort (1); // planes
  197. dataBlock.writeShort (32); // bits
  198. dataBlock.writeInt (0); // compression
  199. dataBlock.writeInt ((h * w * 4) + (h * maskStride)); // size image
  200. dataBlock.writeInt (0); // x pixels per meter
  201. dataBlock.writeInt (0); // y pixels per meter
  202. dataBlock.writeInt (0); // clr used
  203. dataBlock.writeInt (0); // clr important
  204. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  205. const int alphaThreshold = 5;
  206. int y;
  207. for (y = h; --y >= 0;)
  208. {
  209. for (int x = 0; x < w; ++x)
  210. {
  211. const Colour pixel (bitmap.getPixelColour (x, y));
  212. if (pixel.getAlpha() <= alphaThreshold)
  213. {
  214. dataBlock.writeInt (0);
  215. }
  216. else
  217. {
  218. dataBlock.writeByte ((char) pixel.getBlue());
  219. dataBlock.writeByte ((char) pixel.getGreen());
  220. dataBlock.writeByte ((char) pixel.getRed());
  221. dataBlock.writeByte ((char) pixel.getAlpha());
  222. }
  223. }
  224. }
  225. for (y = h; --y >= 0;)
  226. {
  227. int mask = 0, count = 0;
  228. for (int x = 0; x < w; ++x)
  229. {
  230. const Colour pixel (bitmap.getPixelColour (x, y));
  231. mask <<= 1;
  232. if (pixel.getAlpha() <= alphaThreshold)
  233. mask |= 1;
  234. if (++count == 8)
  235. {
  236. dataBlock.writeByte ((char) mask);
  237. count = 0;
  238. mask = 0;
  239. }
  240. }
  241. if (mask != 0)
  242. dataBlock.writeByte ((char) mask);
  243. for (int i = maskStride - w / 8; --i >= 0;)
  244. dataBlock.writeByte (0);
  245. }
  246. out.writeByte ((char) w);
  247. out.writeByte ((char) h);
  248. out.writeByte (0);
  249. out.writeByte (0);
  250. out.writeShort (1); // colour planes
  251. out.writeShort (32); // bits per pixel
  252. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  253. out.writeInt (dataBlockStart + oldDataSize);
  254. }
  255. jassert (out.getPosition() == dataBlockStart);
  256. out << dataBlock;
  257. }
  258. bool createIconFile()
  259. {
  260. Array<Image> images;
  261. Image im (project.getBestIconForSize (16, true));
  262. if (im.isValid())
  263. images.add (im);
  264. im = project.getBestIconForSize (32, true);
  265. if (im.isValid())
  266. images.add (im);
  267. im = project.getBestIconForSize (48, true);
  268. if (im.isValid())
  269. images.add (im);
  270. im = project.getBestIconForSize (128, true);
  271. if (im.isValid())
  272. images.add (im);
  273. if (images.size() == 0)
  274. return true;
  275. MemoryOutputStream mo;
  276. writeIconFile (images, mo);
  277. iconFile = getTargetFolder().getChildFile ("icon.ico");
  278. rcFile = getTargetFolder().getChildFile ("resources.rc");
  279. hasIcon = FileHelpers::overwriteFileWithNewDataIfDifferent (iconFile, mo)
  280. && writeRCFile (rcFile, iconFile);
  281. return hasIcon;
  282. }
  283. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase);
  284. };
  285. //==============================================================================
  286. class MSVCProjectExporterVC2008 : public MSVCProjectExporterBase
  287. {
  288. public:
  289. //==============================================================================
  290. MSVCProjectExporterVC2008 (Project& project_, const ValueTree& settings_, const char* folderName = "VisualStudio2008")
  291. : MSVCProjectExporterBase (project_, settings_, folderName)
  292. {
  293. name = getName();
  294. }
  295. static const char* getName() { return "Visual Studio 2008"; }
  296. static const char* getValueTreeTypeName() { return "VS2008"; }
  297. void launchProject() { getSLNFile().startAsProcess(); }
  298. int getLaunchPreferenceOrderForCurrentOS()
  299. {
  300. #if JUCE_WINDOWS
  301. return 4;
  302. #else
  303. return 0;
  304. #endif
  305. }
  306. static MSVCProjectExporterVC2008* createForSettings (Project& project, const ValueTree& settings)
  307. {
  308. if (settings.hasType (getValueTreeTypeName()))
  309. return new MSVCProjectExporterVC2008 (project, settings);
  310. return 0;
  311. }
  312. //==============================================================================
  313. void create()
  314. {
  315. createIconFile();
  316. if (hasIcon)
  317. {
  318. generatedGroups.getReference(0).addFile (iconFile, -1);
  319. generatedGroups.getReference(0).addFile (rcFile, -1);
  320. generatedGroups.getReference(0).findItemForFile (iconFile).getShouldAddToResourceValue() = false;
  321. generatedGroups.getReference(0).findItemForFile (rcFile).getShouldAddToResourceValue() = false;
  322. }
  323. {
  324. XmlElement projectXml ("VisualStudioProject");
  325. fillInProjectXml (projectXml);
  326. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  327. }
  328. {
  329. MemoryOutputStream mo;
  330. writeSolutionFile (mo, getSolutionVersionString(), getVCProjFile());
  331. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  332. }
  333. }
  334. protected:
  335. virtual String getProjectVersionString() const { return "9.00"; }
  336. virtual String getSolutionVersionString() const { return "10.00" + newLine + "# Visual C++ Express 2008"; }
  337. File getVCProjFile() const { return getProjectFile (".vcproj"); }
  338. File getSLNFile() const { return getProjectFile (".sln"); }
  339. //==============================================================================
  340. void fillInProjectXml (XmlElement& projectXml)
  341. {
  342. projectXml.setAttribute ("ProjectType", "Visual C++");
  343. projectXml.setAttribute ("Version", getProjectVersionString());
  344. projectXml.setAttribute ("Name", project.getProjectName().toString());
  345. projectXml.setAttribute ("ProjectGUID", projectGUID);
  346. projectXml.setAttribute ("TargetFrameworkVersion", "131072");
  347. {
  348. XmlElement* platforms = projectXml.createNewChildElement ("Platforms");
  349. XmlElement* platform = platforms->createNewChildElement ("Platform");
  350. platform->setAttribute ("Name", "Win32");
  351. }
  352. projectXml.createNewChildElement ("ToolFiles");
  353. createConfigs (*projectXml.createNewChildElement ("Configurations"));
  354. projectXml.createNewChildElement ("References");
  355. createFiles (*projectXml.createNewChildElement ("Files"));
  356. projectXml.createNewChildElement ("Globals");
  357. }
  358. //==============================================================================
  359. void addFile (const RelativePath& file, XmlElement& parent, const bool excludeFromBuild, const bool useStdcall)
  360. {
  361. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  362. XmlElement* fileXml = parent.createNewChildElement ("File");
  363. fileXml->setAttribute ("RelativePath", file.toWindowsStyle());
  364. if (excludeFromBuild || useStdcall)
  365. {
  366. for (int i = 0; i < project.getNumConfigurations(); ++i)
  367. {
  368. Project::BuildConfiguration config (project.getConfiguration (i));
  369. XmlElement* fileConfig = fileXml->createNewChildElement ("FileConfiguration");
  370. fileConfig->setAttribute ("Name", createConfigName (config));
  371. if (excludeFromBuild)
  372. fileConfig->setAttribute ("ExcludedFromBuild", "true");
  373. XmlElement* tool = createToolElement (*fileConfig, "VCCLCompilerTool");
  374. if (useStdcall)
  375. tool->setAttribute ("CallingConvention", "2");
  376. }
  377. }
  378. }
  379. XmlElement* createGroup (const String& groupName, XmlElement& parent)
  380. {
  381. XmlElement* filter = parent.createNewChildElement ("Filter");
  382. filter->setAttribute ("Name", groupName);
  383. return filter;
  384. }
  385. void addFiles (const Project::Item& projectItem, XmlElement& parent, const bool useStdcall)
  386. {
  387. if (projectItem.isGroup())
  388. {
  389. XmlElement* filter = createGroup (projectItem.getName().toString(), parent);
  390. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  391. addFiles (projectItem.getChild(i), *filter, useStdcall);
  392. }
  393. else
  394. {
  395. if (projectItem.shouldBeAddedToTargetProject())
  396. {
  397. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  398. addFile (path, parent,
  399. projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()),
  400. useStdcall);
  401. }
  402. }
  403. }
  404. void addGroup (XmlElement& parent, const String& groupName, const Array<RelativePath>& files, const bool useStdcall)
  405. {
  406. if (files.size() > 0)
  407. {
  408. XmlElement* const group = createGroup (groupName, parent);
  409. for (int i = 0; i < files.size(); ++i)
  410. if (files.getReference(i).hasFileExtension ("cpp;c;cc;cxx;h;hpp;hxx;rc;ico"))
  411. addFile (files.getReference(i), *group, false,
  412. useStdcall && shouldFileBeCompiledByDefault (files.getReference(i)));
  413. }
  414. }
  415. void createFiles (XmlElement& files)
  416. {
  417. addFiles (project.getMainGroup(), files, false);
  418. for (int i = 0; i < generatedGroups.size(); ++i)
  419. if (generatedGroups.getReference(i).getNumChildren() > 0)
  420. addFiles (generatedGroups.getReference(i), files, false);
  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. for (int i = 0; i < generatedGroups.size(); ++i)
  755. if (generatedGroups.getReference(i).getNumChildren() > 0)
  756. writeFiles (out, generatedGroups.getReference(i));
  757. out << "# End Target" << newLine
  758. << "# End Project" << newLine;
  759. }
  760. void writeFile (OutputStream& out, const RelativePath& file, const bool excludeFromBuild)
  761. {
  762. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  763. out << "# Begin Source File" << newLine
  764. << "SOURCE=" << file.toWindowsStyle().quoted() << newLine;
  765. if (excludeFromBuild)
  766. out << "# PROP Exclude_From_Build 1" << newLine;
  767. out << "# End Source File" << newLine;
  768. }
  769. void writeFiles (OutputStream& out, const Project::Item& projectItem)
  770. {
  771. if (projectItem.isGroup())
  772. {
  773. out << "# Begin Group \"" << projectItem.getName() << '"' << newLine
  774. << "# PROP Default_Filter \"cpp;c;cc;cxx;rc;def;r;odl;idl;hpj;bat\"" << newLine;
  775. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  776. writeFiles (out, projectItem.getChild (i));
  777. out << "# End Group" << newLine;
  778. }
  779. else if (projectItem.shouldBeAddedToTargetProject())
  780. {
  781. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  782. writeFile (out, path, projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()));
  783. }
  784. }
  785. void writeGroup (OutputStream& out, const String& groupName, const Array<RelativePath>& files)
  786. {
  787. if (files.size() > 0)
  788. {
  789. out << "# Begin Group \"" << groupName << '"' << newLine;
  790. for (int i = 0; i < files.size(); ++i)
  791. if (files.getReference(i).hasFileExtension ("cpp;cc;c;cxx;h;hpp;hxx"))
  792. writeFile (out, files.getReference(i), false);
  793. out << "# End Group" << newLine;
  794. }
  795. }
  796. void writeDSWFile (OutputStream& out)
  797. {
  798. out << "Microsoft Developer Studio Workspace File, Format Version 6.00 " << newLine;
  799. if (! project.isUsingWrapperFiles())
  800. {
  801. out << "Project: \"JUCE\"= ..\\JUCE.dsp - Package Owner=<4>" << newLine
  802. << "Package=<5>" << newLine
  803. << "{{{" << newLine
  804. << "}}}" << newLine
  805. << "Package=<4>" << newLine
  806. << "{{{" << newLine
  807. << "}}}" << newLine;
  808. }
  809. out << "Project: \"" << project.getProjectName() << "\" = .\\" << getDSPFile().getFileName() << " - Package Owner=<4>" << newLine
  810. << "Package=<5>" << newLine
  811. << "{{{" << newLine
  812. << "}}}" << newLine
  813. << "Package=<4>" << newLine
  814. << "{{{" << newLine;
  815. if (! project.isUsingWrapperFiles())
  816. {
  817. out << " Begin Project Dependency" << newLine
  818. << " Project_Dep_Name JUCE" << newLine
  819. << " End Project Dependency" << newLine;
  820. }
  821. out << "}}}" << newLine
  822. << "Global:" << newLine
  823. << "Package=<5>" << newLine
  824. << "{{{" << newLine
  825. << "}}}" << newLine
  826. << "Package=<3>" << newLine
  827. << "{{{" << newLine
  828. << "}}}" << newLine;
  829. }
  830. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC6);
  831. };
  832. //==============================================================================
  833. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  834. {
  835. public:
  836. MSVCProjectExporterVC2010 (Project& project_, const ValueTree& settings_)
  837. : MSVCProjectExporterBase (project_, settings_, "VisualStudio2010")
  838. {
  839. name = getName();
  840. }
  841. static const char* getName() { return "Visual Studio 2010"; }
  842. static const char* getValueTreeTypeName() { return "VS2010"; }
  843. int getLaunchPreferenceOrderForCurrentOS()
  844. {
  845. #if JUCE_WINDOWS
  846. return 3;
  847. #else
  848. return 0;
  849. #endif
  850. }
  851. void launchProject() { getSLNFile().startAsProcess(); }
  852. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  853. {
  854. if (settings.hasType (getValueTreeTypeName()))
  855. return new MSVCProjectExporterVC2010 (project, settings);
  856. return 0;
  857. }
  858. //==============================================================================
  859. void create()
  860. {
  861. createIconFile();
  862. {
  863. XmlElement projectXml ("Project");
  864. fillInProjectXml (projectXml);
  865. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  866. }
  867. {
  868. XmlElement filtersXml ("Project");
  869. fillInFiltersXml (filtersXml);
  870. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  871. }
  872. {
  873. MemoryOutputStream mo;
  874. writeSolutionFile (mo, "11.00", getVCProjFile());
  875. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  876. }
  877. }
  878. protected:
  879. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  880. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  881. File getSLNFile() const { return getProjectFile (".sln"); }
  882. static String createConfigName (const Project::BuildConfiguration& config)
  883. {
  884. return config.getName().toString() + "|Win32";
  885. }
  886. static void setConditionAttribute (XmlElement& xml, const Project::BuildConfiguration& config)
  887. {
  888. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  889. }
  890. //==============================================================================
  891. void fillInProjectXml (XmlElement& projectXml)
  892. {
  893. projectXml.setAttribute ("DefaultTargets", "Build");
  894. projectXml.setAttribute ("ToolsVersion", "4.0");
  895. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  896. {
  897. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  898. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  899. for (int i = 0; i < project.getNumConfigurations(); ++i)
  900. {
  901. Project::BuildConfiguration config (project.getConfiguration (i));
  902. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  903. e->setAttribute ("Include", createConfigName (config));
  904. e->createNewChildElement ("Configuration")->addTextElement (config.getName().toString());
  905. e->createNewChildElement ("Platform")->addTextElement ("Win32");
  906. }
  907. }
  908. {
  909. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  910. globals->setAttribute ("Label", "Globals");
  911. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  912. }
  913. {
  914. XmlElement* imports = projectXml.createNewChildElement ("Import");
  915. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  916. }
  917. for (int i = 0; i < project.getNumConfigurations(); ++i)
  918. {
  919. Project::BuildConfiguration config (project.getConfiguration (i));
  920. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  921. setConditionAttribute (*e, config);
  922. e->setAttribute ("Label", "Configuration");
  923. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  924. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  925. e->createNewChildElement ("CharacterSet")->addTextElement ("MultiByte");
  926. if (! config.isDebug().getValue())
  927. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  928. }
  929. {
  930. XmlElement* e = projectXml.createNewChildElement ("Import");
  931. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  932. }
  933. {
  934. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  935. e->setAttribute ("Label", "ExtensionSettings");
  936. }
  937. {
  938. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  939. e->setAttribute ("Label", "PropertySheets");
  940. XmlElement* p = e->createNewChildElement ("Import");
  941. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  942. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  943. p->setAttribute ("Label", "LocalAppDataPlatform");
  944. }
  945. {
  946. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  947. e->setAttribute ("Label", "UserMacros");
  948. }
  949. {
  950. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  951. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  952. for (int i = 0; i < project.getNumConfigurations(); ++i)
  953. {
  954. Project::BuildConfiguration config (project.getConfiguration (i));
  955. XmlElement* outdir = props->createNewChildElement ("OutDir");
  956. setConditionAttribute (*outdir, config);
  957. outdir->addTextElement (getConfigTargetPath (config) + "\\");
  958. XmlElement* intdir = props->createNewChildElement ("IntDir");
  959. setConditionAttribute (*intdir, config);
  960. intdir->addTextElement (getConfigTargetPath (config) + "\\");
  961. XmlElement* name = props->createNewChildElement ("TargetName");
  962. setConditionAttribute (*name, config);
  963. name->addTextElement (getBinaryFileForConfig (config).upToLastOccurrenceOf (".", false, false));
  964. }
  965. }
  966. for (int i = 0; i < project.getNumConfigurations(); ++i)
  967. {
  968. Project::BuildConfiguration config (project.getConfiguration (i));
  969. String binariesPath (getConfigTargetPath (config));
  970. String intermediatesPath (getIntermediatesPath (config));
  971. const bool isDebug = (bool) config.isDebug().getValue();
  972. const String binaryName (File::createLegalFileName (config.getTargetBinaryName().toString()));
  973. const String outputFileName (getBinaryFileForConfig (config));
  974. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  975. setConditionAttribute (*group, config);
  976. {
  977. XmlElement* midl = group->createNewChildElement ("Midl");
  978. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  979. : "NDEBUG;%(PreprocessorDefinitions)");
  980. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  981. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  982. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  983. //midl->createNewChildElement ("TypeLibraryName")->addTextElement ("");
  984. midl->createNewChildElement ("HeaderFileName");
  985. }
  986. {
  987. XmlElement* cl = group->createNewChildElement ("ClCompile");
  988. cl->createNewChildElement ("Optimization")->addTextElement (isDebug ? "Disabled" : "MaxSpeed");
  989. if (isDebug)
  990. cl->createNewChildElement ("DebugInformationFormat")->addTextElement ("EditAndContinue");
  991. StringArray includePaths (getHeaderSearchPaths (config));
  992. includePaths.add ("%(AdditionalIncludeDirectories)");
  993. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  994. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  995. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (isRTAS() ? (isDebug ? "MultiThreadedDLLDebug" : "MultiThreadedDLL")
  996. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  997. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  998. cl->createNewChildElement ("PrecompiledHeader");
  999. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  1000. cl->createNewChildElement ("ObjectFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  1001. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  1002. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level4");
  1003. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1004. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlags().toString()).trim());
  1005. if (extraFlags.isNotEmpty())
  1006. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  1007. }
  1008. {
  1009. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  1010. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1011. : "NDEBUG;%(PreprocessorDefinitions)");
  1012. }
  1013. {
  1014. XmlElement* link = group->createNewChildElement ("Link");
  1015. link->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  1016. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1017. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  1018. : "%(IgnoreSpecificDefaultLibraries)");
  1019. link->createNewChildElement ("GenerateDebugInformation")->addTextElement (isDebug ? "true" : "false");
  1020. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".pdb"));
  1021. link->createNewChildElement ("SubSystem")->addTextElement (project.getProjectType().isCommandLineApp() ? "Console" : "Windows");
  1022. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  1023. if (! isDebug)
  1024. {
  1025. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  1026. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  1027. }
  1028. String extraLinkerOptions (getExtraLinkerFlags().toString());
  1029. if (extraLinkerOptions.isNotEmpty())
  1030. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  1031. + " %(AdditionalOptions)");
  1032. }
  1033. {
  1034. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  1035. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1036. bsc->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".bsc"));
  1037. }
  1038. }
  1039. {
  1040. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1041. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1042. addFilesToCompile (project.getMainGroup(), *cppFiles, *headerFiles, false);
  1043. for (int i = 0; i < generatedGroups.size(); ++i)
  1044. if (generatedGroups.getReference(i).getNumChildren() > 0)
  1045. addFilesToCompile (generatedGroups.getReference(i), *cppFiles, *headerFiles, false);
  1046. }
  1047. if (hasIcon)
  1048. {
  1049. {
  1050. XmlElement* iconGroup = projectXml.createNewChildElement ("ItemGroup");
  1051. XmlElement* e = iconGroup->createNewChildElement ("None");
  1052. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1053. }
  1054. {
  1055. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1056. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1057. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1058. }
  1059. }
  1060. {
  1061. XmlElement* e = projectXml.createNewChildElement ("Import");
  1062. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1063. }
  1064. {
  1065. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1066. e->setAttribute ("Label", "ExtensionTargets");
  1067. }
  1068. }
  1069. String getProjectType() const
  1070. {
  1071. if (project.getProjectType().isGUIApplication() || project.getProjectType().isCommandLineApp()) return "Application";
  1072. else if (project.getProjectType().isAudioPlugin() || project.getProjectType().isBrowserPlugin()) return "DynamicLibrary";
  1073. else if (project.getProjectType().isLibrary()) return "StaticLibrary";
  1074. jassertfalse;
  1075. return String::empty;
  1076. }
  1077. //==============================================================================
  1078. void addFileToCompile (const RelativePath& file, XmlElement& cpps, XmlElement& headers, const bool excludeFromBuild, const bool useStdcall)
  1079. {
  1080. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1081. if (file.hasFileExtension ("cpp;cc;cxx;c"))
  1082. {
  1083. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1084. e->setAttribute ("Include", file.toWindowsStyle());
  1085. if (excludeFromBuild)
  1086. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1087. if (useStdcall)
  1088. {
  1089. jassertfalse;
  1090. }
  1091. }
  1092. else if (file.hasFileExtension (headerFileExtensions))
  1093. {
  1094. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", file.toWindowsStyle());
  1095. }
  1096. }
  1097. void addFilesToCompile (const Array<RelativePath>& files, XmlElement& cpps, XmlElement& headers, bool useStdCall)
  1098. {
  1099. for (int i = 0; i < files.size(); ++i)
  1100. addFileToCompile (files.getReference(i), cpps, headers, false, useStdCall);
  1101. }
  1102. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, bool useStdCall)
  1103. {
  1104. if (projectItem.isGroup())
  1105. {
  1106. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1107. addFilesToCompile (projectItem.getChild(i), cpps, headers, useStdCall);
  1108. }
  1109. else
  1110. {
  1111. if (projectItem.shouldBeAddedToTargetProject())
  1112. {
  1113. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1114. if (path.hasFileExtension (headerFileExtensions) || (path.hasFileExtension ("cpp;cc;c;cxx") && projectItem.shouldBeCompiled()))
  1115. addFileToCompile (path, cpps, headers, false, useStdCall);
  1116. }
  1117. }
  1118. }
  1119. //==============================================================================
  1120. void addFilterGroup (XmlElement& groups, const String& path)
  1121. {
  1122. XmlElement* e = groups.createNewChildElement ("Filter");
  1123. e->setAttribute ("Include", path);
  1124. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1125. }
  1126. void addFileToFilter (const RelativePath& file, const String& groupPath, XmlElement& cpps, XmlElement& headers)
  1127. {
  1128. XmlElement* e;
  1129. if (file.hasFileExtension (headerFileExtensions))
  1130. e = headers.createNewChildElement ("ClInclude");
  1131. else
  1132. e = cpps.createNewChildElement ("ClCompile");
  1133. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1134. e->setAttribute ("Include", file.toWindowsStyle());
  1135. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1136. }
  1137. void addFilesToFilter (const Project::Item& projectItem, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1138. {
  1139. if (projectItem.isGroup())
  1140. {
  1141. addFilterGroup (groups, path);
  1142. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1143. addFilesToFilter (projectItem.getChild(i),
  1144. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName().toString(),
  1145. cpps, headers, groups);
  1146. }
  1147. else
  1148. {
  1149. if (projectItem.shouldBeAddedToTargetProject())
  1150. {
  1151. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1152. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers);
  1153. }
  1154. }
  1155. }
  1156. void addFilesToFilter (const Array<RelativePath>& files, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1157. {
  1158. if (files.size() > 0)
  1159. {
  1160. addFilterGroup (groups, path);
  1161. for (int i = 0; i < files.size(); ++i)
  1162. addFileToFilter (files.getReference(i), path, cpps, headers);
  1163. }
  1164. }
  1165. void fillInFiltersXml (XmlElement& filterXml)
  1166. {
  1167. filterXml.setAttribute ("ToolsVersion", "4.0");
  1168. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1169. XmlElement* groups = filterXml.createNewChildElement ("ItemGroup");
  1170. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1171. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1172. addFilesToFilter (project.getMainGroup(), project.getProjectName().toString(), *cpps, *headers, *groups);
  1173. for (int i = 0; i < generatedGroups.size(); ++i)
  1174. if (generatedGroups.getReference(i).getNumChildren() > 0)
  1175. addFilesToFilter (generatedGroups.getReference(i), project.getJuceCodeGroupName(), *cpps, *headers, *groups);
  1176. if (iconFile.exists())
  1177. {
  1178. {
  1179. XmlElement* iconGroup = filterXml.createNewChildElement ("ItemGroup");
  1180. XmlElement* e = iconGroup->createNewChildElement ("None");
  1181. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1182. e->createNewChildElement ("Filter")->addTextElement (project.getJuceCodeGroupName());
  1183. }
  1184. {
  1185. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1186. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1187. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1188. e->createNewChildElement ("Filter")->addTextElement (project.getJuceCodeGroupName());
  1189. }
  1190. }
  1191. }
  1192. //==============================================================================
  1193. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010);
  1194. };
  1195. #endif // __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__