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.

1470 lines
64KB

  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 (projectType.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 projectType.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 (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder)
  76. .toWindowsStyle();
  77. }
  78. String getTargetBinarySuffix() const
  79. {
  80. if (projectType.isLibrary())
  81. return ".lib";
  82. else if (isRTAS())
  83. return ".dpm";
  84. else if (projectType.isAudioPlugin() || projectType.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 (projectType.isCommandLineApp())
  103. defines.set ("_CONSOLE", "");
  104. if (projectType.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 (projectName + "sln_guid") << "\") = \"" << projectName << "\", \""
  147. << vcProject.getFileName() << "\", \"" << projectGUID << '"' << newLine
  148. << "EndProject" << newLine
  149. << "Global" << newLine
  150. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  151. int i;
  152. for (i = 0; i < configs.size(); ++i)
  153. {
  154. const Project::BuildConfiguration& config = configs.getReference(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 < configs.size(); ++i)
  160. {
  161. const Project::BuildConfiguration& config = configs.getReference(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 (getBestIconForSize (16, true));
  262. if (im.isValid())
  263. images.add (im);
  264. im = getBestIconForSize (32, true);
  265. if (im.isValid())
  266. images.add (im);
  267. im = getBestIconForSize (48, true);
  268. if (im.isValid())
  269. images.add (im);
  270. im = 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", projectName);
  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 < configs.size(); ++i)
  367. {
  368. const Project::BuildConfiguration& config = configs.getReference(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 (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", (projectType.isAudioPlugin() || projectType.isBrowserPlugin() || isLibraryDLL())
  439. ? "2" : (projectType.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 (! projectType.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", projectType.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 (! projectType.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", projectType.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 (! projectType.isLibrary())
  560. createToolElement (xml, "VCAppVerifierTool");
  561. createToolElement (xml, "VCPostBuildEventTool");
  562. }
  563. void createConfigs (XmlElement& xml)
  564. {
  565. for (int i = 0; i < configs.size(); ++i)
  566. createConfig (*xml.createNewChildElement ("Configuration"), configs.getReference(i));
  567. }
  568. //==============================================================================
  569. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008);
  570. };
  571. //==============================================================================
  572. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  573. {
  574. public:
  575. MSVCProjectExporterVC2005 (Project& project_, const ValueTree& settings_)
  576. : MSVCProjectExporterVC2008 (project_, settings_, "VisualStudio2005")
  577. {
  578. name = getName();
  579. }
  580. static const char* getName() { return "Visual Studio 2005"; }
  581. static const char* getValueTreeTypeName() { return "VS2005"; }
  582. int getLaunchPreferenceOrderForCurrentOS()
  583. {
  584. #if JUCE_WINDOWS
  585. return 2;
  586. #else
  587. return 0;
  588. #endif
  589. }
  590. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  591. {
  592. if (settings.hasType (getValueTreeTypeName()))
  593. return new MSVCProjectExporterVC2005 (project, settings);
  594. return 0;
  595. }
  596. protected:
  597. String getProjectVersionString() const { return "8.00"; }
  598. String getSolutionVersionString() const { return "8.00" + newLine + "# Visual C++ Express 2005"; }
  599. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005);
  600. };
  601. //==============================================================================
  602. class MSVCProjectExporterVC6 : public MSVCProjectExporterBase
  603. {
  604. public:
  605. //==============================================================================
  606. MSVCProjectExporterVC6 (Project& project_, const ValueTree& settings_)
  607. : MSVCProjectExporterBase (project_, settings_, "MSVC6")
  608. {
  609. name = getName();
  610. }
  611. static const char* getName() { return "Visual C++ 6.0"; }
  612. static const char* getValueTreeTypeName() { return "MSVC6"; }
  613. int getLaunchPreferenceOrderForCurrentOS()
  614. {
  615. #if JUCE_WINDOWS
  616. return 1;
  617. #else
  618. return 0;
  619. #endif
  620. }
  621. void launchProject() { getDSWFile().startAsProcess(); }
  622. static MSVCProjectExporterVC6* createForSettings (Project& project, const ValueTree& settings)
  623. {
  624. if (settings.hasType (getValueTreeTypeName()))
  625. return new MSVCProjectExporterVC6 (project, settings);
  626. return 0;
  627. }
  628. //==============================================================================
  629. void create()
  630. {
  631. {
  632. MemoryOutputStream mo;
  633. writeProject (mo);
  634. overwriteFileIfDifferentOrThrow (getDSPFile(), mo);
  635. }
  636. {
  637. MemoryOutputStream mo;
  638. writeDSWFile (mo);
  639. overwriteFileIfDifferentOrThrow (getDSWFile(), mo);
  640. }
  641. }
  642. private:
  643. File getDSPFile() const { return getProjectFile (".dsp"); }
  644. File getDSWFile() const { return getProjectFile (".dsw"); }
  645. //==============================================================================
  646. String createConfigName (const Project::BuildConfiguration& config) const
  647. {
  648. return projectName + " - Win32 " + config.getName().toString();
  649. }
  650. void writeProject (OutputStream& out)
  651. {
  652. const String defaultConfigName (createConfigName (configs.getReference(0)));
  653. const bool isDLL = projectType.isAudioPlugin() || projectType.isBrowserPlugin();
  654. String targetType, targetCode;
  655. if (isDLL) { targetType = "\"Win32 (x86) Dynamic-Link Library\""; targetCode = "0x0102"; }
  656. else if (projectType.isLibrary()) { targetType = "\"Win32 (x86) Static Library\""; targetCode = "0x0104"; }
  657. else if (projectType.isCommandLineApp()) { targetType = "\"Win32 (x86) Console Application\""; targetCode = "0x0103"; }
  658. else { targetType = "\"Win32 (x86) Application\""; targetCode = "0x0101"; }
  659. out << "# Microsoft Developer Studio Project File - Name=\"" << projectName
  660. << "\" - Package Owner=<4>" << newLine
  661. << "# Microsoft Developer Studio Generated Build File, Format Version 6.00" << newLine
  662. << "# ** DO NOT EDIT **" << newLine
  663. << "# TARGTYPE " << targetType << " " << targetCode << newLine
  664. << "CFG=" << defaultConfigName << newLine
  665. << "!MESSAGE This is not a valid makefile. To build this project using NMAKE," << newLine
  666. << "!MESSAGE use the Export Makefile command and run" << newLine
  667. << "!MESSAGE " << newLine
  668. << "!MESSAGE NMAKE /f \"" << projectName << ".mak.\"" << newLine
  669. << "!MESSAGE " << newLine
  670. << "!MESSAGE You can specify a configuration when running NMAKE" << newLine
  671. << "!MESSAGE by defining the macro CFG on the command line. For example:" << newLine
  672. << "!MESSAGE " << newLine
  673. << "!MESSAGE NMAKE /f \"" << projectName << ".mak\" CFG=\"" << defaultConfigName << '"' << newLine
  674. << "!MESSAGE " << newLine
  675. << "!MESSAGE Possible choices for configuration are:" << newLine
  676. << "!MESSAGE " << newLine;
  677. int i;
  678. for (i = 0; i < configs.size(); ++i)
  679. out << "!MESSAGE \"" << createConfigName (configs.getReference (i)) << "\" (based on " << targetType << ")" << newLine;
  680. out << "!MESSAGE " << newLine
  681. << "# Begin Project" << newLine
  682. << "# PROP AllowPerConfigDependencies 0" << newLine
  683. << "# PROP Scc_ProjName \"\"" << newLine
  684. << "# PROP Scc_LocalPath \"\"" << newLine
  685. << "CPP=cl.exe" << newLine
  686. << "MTL=midl.exe" << newLine
  687. << "RSC=rc.exe" << newLine;
  688. String targetList;
  689. for (i = 0; i < configs.size(); ++i)
  690. {
  691. const Project::BuildConfiguration& config = configs.getReference(i);
  692. const String configName (createConfigName (config));
  693. targetList << "# Name \"" << configName << '"' << newLine;
  694. const String binariesPath (getConfigTargetPath (config));
  695. const String targetBinary (FileHelpers::windowsStylePath (binariesPath + "/" + getBinaryFileForConfig (config)));
  696. const String optimisationFlag (((int) config.getOptimisationLevel().getValue() <= 1) ? "Od" : (config.getOptimisationLevel() == 2 ? "O2" : "O3"));
  697. const String defines (getPreprocessorDefs (config, " /D "));
  698. const bool isDebug = (bool) config.isDebug().getValue();
  699. const String extraDebugFlags (isDebug ? "/Gm /ZI /GZ" : "");
  700. out << (i == 0 ? "!IF" : "!ELSEIF") << " \"$(CFG)\" == \"" << configName << '"' << newLine
  701. << "# PROP BASE Use_MFC 0" << newLine
  702. << "# PROP BASE Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  703. << "# PROP BASE Output_Dir \"" << binariesPath << '"' << newLine
  704. << "# PROP BASE Intermediate_Dir \"" << getIntermediatesPath (config) << '"' << newLine
  705. << "# PROP BASE Target_Dir \"\"" << newLine
  706. << "# PROP Use_MFC 0" << newLine
  707. << "# PROP Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  708. << "# PROP Output_Dir \"" << binariesPath << '"' << newLine
  709. << "# PROP Intermediate_Dir \"" << getIntermediatesPath (config) << '"' << newLine
  710. << "# PROP Ignore_Export_Lib 0" << newLine
  711. << "# PROP Target_Dir \"\"" << newLine
  712. << "# ADD BASE CPP /nologo /W3 /GX /" << optimisationFlag << " /D " << defines
  713. << " /YX /FD /c " << extraDebugFlags << " /Zm1024" << newLine
  714. << "# ADD CPP /nologo " << (isDebug ? "/MTd" : "/MT") << " /W3 /GR /GX /" << optimisationFlag
  715. << " /I " << replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (" /I "))
  716. << " /D " << defines << " /D \"_UNICODE\" /D \"UNICODE\" /FD /c /Zm1024 " << extraDebugFlags
  717. << " " << replacePreprocessorTokens (config, getExtraCompilerFlags().toString()).trim() << newLine;
  718. if (! isDebug)
  719. out << "# SUBTRACT CPP /YX" << newLine;
  720. if (! projectType.isLibrary())
  721. out << "# ADD BASE MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine
  722. << "# ADD MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine;
  723. out << "# ADD BASE RSC /l 0x40c /d " << defines << newLine
  724. << "# ADD RSC /l 0x40c /d " << defines << newLine
  725. << "BSC32=bscmake.exe" << newLine
  726. << "# ADD BASE BSC32 /nologo" << newLine
  727. << "# ADD BSC32 /nologo" << newLine;
  728. if (projectType.isLibrary())
  729. {
  730. out << "LIB32=link.exe -lib" << newLine
  731. << "# ADD BASE LIB32 /nologo" << newLine
  732. << "# ADD LIB32 /nologo /out:\"" << targetBinary << '"' << newLine;
  733. }
  734. else
  735. {
  736. out << "LINK32=link.exe" << newLine
  737. << "# 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
  738. << "# ADD LINK32 \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\LIB\\shell32.lib\" " // This is avoid debug information corruption when mixing Platform SDK
  739. << "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "
  740. << (isDebug ? " /debug" : "")
  741. << " /nologo /machine:I386 /out:\"" << targetBinary << "\" "
  742. << (isDLL ? "/dll" : (projectType.isCommandLineApp() ? "/subsystem:console "
  743. : "/subsystem:windows "))
  744. << replacePreprocessorTokens (config, getExtraLinkerFlags().toString()).trim() << newLine;
  745. }
  746. }
  747. out << "!ENDIF" << newLine
  748. << "# Begin Target" << newLine
  749. << targetList;
  750. writeFiles (out, getMainGroup());
  751. for (int i = 0; i < generatedGroups.size(); ++i)
  752. if (generatedGroups.getReference(i).getNumChildren() > 0)
  753. writeFiles (out, generatedGroups.getReference(i));
  754. out << "# End Target" << newLine
  755. << "# End Project" << newLine;
  756. }
  757. void writeFile (OutputStream& out, const RelativePath& file, const bool excludeFromBuild)
  758. {
  759. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  760. out << "# Begin Source File" << newLine
  761. << "SOURCE=" << file.toWindowsStyle().quoted() << newLine;
  762. if (excludeFromBuild)
  763. out << "# PROP Exclude_From_Build 1" << newLine;
  764. out << "# End Source File" << newLine;
  765. }
  766. void writeFiles (OutputStream& out, const Project::Item& projectItem)
  767. {
  768. if (projectItem.isGroup())
  769. {
  770. out << "# Begin Group \"" << projectItem.getName() << '"' << newLine
  771. << "# PROP Default_Filter \"cpp;c;cc;cxx;rc;def;r;odl;idl;hpj;bat\"" << newLine;
  772. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  773. writeFiles (out, projectItem.getChild (i));
  774. out << "# End Group" << newLine;
  775. }
  776. else if (projectItem.shouldBeAddedToTargetProject())
  777. {
  778. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  779. writeFile (out, path, projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()));
  780. }
  781. }
  782. void writeGroup (OutputStream& out, const String& groupName, const Array<RelativePath>& files)
  783. {
  784. if (files.size() > 0)
  785. {
  786. out << "# Begin Group \"" << groupName << '"' << newLine;
  787. for (int i = 0; i < files.size(); ++i)
  788. if (files.getReference(i).hasFileExtension ("cpp;cc;c;cxx;h;hpp;hxx"))
  789. writeFile (out, files.getReference(i), false);
  790. out << "# End Group" << newLine;
  791. }
  792. }
  793. void writeDSWFile (OutputStream& out)
  794. {
  795. out << "Microsoft Developer Studio Workspace File, Format Version 6.00 " << newLine;
  796. if (! project.isUsingWrapperFiles())
  797. {
  798. out << "Project: \"JUCE\"= ..\\JUCE.dsp - Package Owner=<4>" << newLine
  799. << "Package=<5>" << newLine
  800. << "{{{" << newLine
  801. << "}}}" << newLine
  802. << "Package=<4>" << newLine
  803. << "{{{" << newLine
  804. << "}}}" << newLine;
  805. }
  806. out << "Project: \"" << projectName << "\" = .\\" << getDSPFile().getFileName() << " - Package Owner=<4>" << newLine
  807. << "Package=<5>" << newLine
  808. << "{{{" << newLine
  809. << "}}}" << newLine
  810. << "Package=<4>" << newLine
  811. << "{{{" << newLine;
  812. if (! project.isUsingWrapperFiles())
  813. {
  814. out << " Begin Project Dependency" << newLine
  815. << " Project_Dep_Name JUCE" << newLine
  816. << " End Project Dependency" << newLine;
  817. }
  818. out << "}}}" << newLine
  819. << "Global:" << newLine
  820. << "Package=<5>" << newLine
  821. << "{{{" << newLine
  822. << "}}}" << newLine
  823. << "Package=<3>" << newLine
  824. << "{{{" << newLine
  825. << "}}}" << newLine;
  826. }
  827. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC6);
  828. };
  829. //==============================================================================
  830. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  831. {
  832. public:
  833. MSVCProjectExporterVC2010 (Project& project_, const ValueTree& settings_)
  834. : MSVCProjectExporterBase (project_, settings_, "VisualStudio2010")
  835. {
  836. name = getName();
  837. }
  838. static const char* getName() { return "Visual Studio 2010"; }
  839. static const char* getValueTreeTypeName() { return "VS2010"; }
  840. int getLaunchPreferenceOrderForCurrentOS()
  841. {
  842. #if JUCE_WINDOWS
  843. return 3;
  844. #else
  845. return 0;
  846. #endif
  847. }
  848. void launchProject() { getSLNFile().startAsProcess(); }
  849. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  850. {
  851. if (settings.hasType (getValueTreeTypeName()))
  852. return new MSVCProjectExporterVC2010 (project, settings);
  853. return 0;
  854. }
  855. //==============================================================================
  856. void create()
  857. {
  858. createIconFile();
  859. {
  860. XmlElement projectXml ("Project");
  861. fillInProjectXml (projectXml);
  862. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  863. }
  864. {
  865. XmlElement filtersXml ("Project");
  866. fillInFiltersXml (filtersXml);
  867. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  868. }
  869. {
  870. MemoryOutputStream mo;
  871. writeSolutionFile (mo, "11.00", getVCProjFile());
  872. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  873. }
  874. }
  875. protected:
  876. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  877. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  878. File getSLNFile() const { return getProjectFile (".sln"); }
  879. static String createConfigName (const Project::BuildConfiguration& config)
  880. {
  881. return config.getName().toString() + "|Win32";
  882. }
  883. static void setConditionAttribute (XmlElement& xml, const Project::BuildConfiguration& config)
  884. {
  885. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  886. }
  887. //==============================================================================
  888. void fillInProjectXml (XmlElement& projectXml)
  889. {
  890. projectXml.setAttribute ("DefaultTargets", "Build");
  891. projectXml.setAttribute ("ToolsVersion", "4.0");
  892. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  893. {
  894. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  895. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  896. for (int i = 0; i < configs.size(); ++i)
  897. {
  898. const Project::BuildConfiguration& config = configs.getReference(i);
  899. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  900. e->setAttribute ("Include", createConfigName (config));
  901. e->createNewChildElement ("Configuration")->addTextElement (config.getName().toString());
  902. e->createNewChildElement ("Platform")->addTextElement ("Win32");
  903. }
  904. }
  905. {
  906. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  907. globals->setAttribute ("Label", "Globals");
  908. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  909. }
  910. {
  911. XmlElement* imports = projectXml.createNewChildElement ("Import");
  912. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  913. }
  914. for (int i = 0; i < configs.size(); ++i)
  915. {
  916. const Project::BuildConfiguration& config = configs.getReference(i);
  917. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  918. setConditionAttribute (*e, config);
  919. e->setAttribute ("Label", "Configuration");
  920. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  921. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  922. e->createNewChildElement ("CharacterSet")->addTextElement ("MultiByte");
  923. if (! config.isDebug().getValue())
  924. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  925. }
  926. {
  927. XmlElement* e = projectXml.createNewChildElement ("Import");
  928. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  929. }
  930. {
  931. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  932. e->setAttribute ("Label", "ExtensionSettings");
  933. }
  934. {
  935. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  936. e->setAttribute ("Label", "PropertySheets");
  937. XmlElement* p = e->createNewChildElement ("Import");
  938. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  939. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  940. p->setAttribute ("Label", "LocalAppDataPlatform");
  941. }
  942. {
  943. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  944. e->setAttribute ("Label", "UserMacros");
  945. }
  946. {
  947. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  948. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  949. for (int i = 0; i < configs.size(); ++i)
  950. {
  951. const Project::BuildConfiguration& config = configs.getReference(i);
  952. XmlElement* outdir = props->createNewChildElement ("OutDir");
  953. setConditionAttribute (*outdir, config);
  954. outdir->addTextElement (getConfigTargetPath (config) + "\\");
  955. XmlElement* intdir = props->createNewChildElement ("IntDir");
  956. setConditionAttribute (*intdir, config);
  957. intdir->addTextElement (getConfigTargetPath (config) + "\\");
  958. XmlElement* name = props->createNewChildElement ("TargetName");
  959. setConditionAttribute (*name, config);
  960. name->addTextElement (getBinaryFileForConfig (config).upToLastOccurrenceOf (".", false, false));
  961. }
  962. }
  963. for (int i = 0; i < configs.size(); ++i)
  964. {
  965. const Project::BuildConfiguration& config = configs.getReference(i);
  966. String binariesPath (getConfigTargetPath (config));
  967. String intermediatesPath (getIntermediatesPath (config));
  968. const bool isDebug = (bool) config.isDebug().getValue();
  969. const String binaryName (File::createLegalFileName (config.getTargetBinaryName().toString()));
  970. const String outputFileName (getBinaryFileForConfig (config));
  971. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  972. setConditionAttribute (*group, config);
  973. {
  974. XmlElement* midl = group->createNewChildElement ("Midl");
  975. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  976. : "NDEBUG;%(PreprocessorDefinitions)");
  977. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  978. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  979. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  980. //midl->createNewChildElement ("TypeLibraryName")->addTextElement ("");
  981. midl->createNewChildElement ("HeaderFileName");
  982. }
  983. {
  984. XmlElement* cl = group->createNewChildElement ("ClCompile");
  985. cl->createNewChildElement ("Optimization")->addTextElement (isDebug ? "Disabled" : "MaxSpeed");
  986. if (isDebug)
  987. cl->createNewChildElement ("DebugInformationFormat")->addTextElement ("EditAndContinue");
  988. StringArray includePaths (getHeaderSearchPaths (config));
  989. includePaths.add ("%(AdditionalIncludeDirectories)");
  990. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  991. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  992. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (isRTAS() ? (isDebug ? "MultiThreadedDLLDebug" : "MultiThreadedDLL")
  993. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  994. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  995. cl->createNewChildElement ("PrecompiledHeader");
  996. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  997. cl->createNewChildElement ("ObjectFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  998. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  999. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level4");
  1000. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1001. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlags().toString()).trim());
  1002. if (extraFlags.isNotEmpty())
  1003. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  1004. }
  1005. {
  1006. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  1007. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1008. : "NDEBUG;%(PreprocessorDefinitions)");
  1009. }
  1010. {
  1011. XmlElement* link = group->createNewChildElement ("Link");
  1012. link->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  1013. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1014. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  1015. : "%(IgnoreSpecificDefaultLibraries)");
  1016. link->createNewChildElement ("GenerateDebugInformation")->addTextElement (isDebug ? "true" : "false");
  1017. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".pdb"));
  1018. link->createNewChildElement ("SubSystem")->addTextElement (projectType.isCommandLineApp() ? "Console" : "Windows");
  1019. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  1020. if (! isDebug)
  1021. {
  1022. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  1023. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  1024. }
  1025. String extraLinkerOptions (getExtraLinkerFlags().toString());
  1026. if (extraLinkerOptions.isNotEmpty())
  1027. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  1028. + " %(AdditionalOptions)");
  1029. }
  1030. {
  1031. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  1032. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1033. bsc->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".bsc"));
  1034. }
  1035. }
  1036. {
  1037. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1038. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1039. addFilesToCompile (getMainGroup(), *cppFiles, *headerFiles, false);
  1040. for (int i = 0; i < generatedGroups.size(); ++i)
  1041. if (generatedGroups.getReference(i).getNumChildren() > 0)
  1042. addFilesToCompile (generatedGroups.getReference(i), *cppFiles, *headerFiles, false);
  1043. }
  1044. if (hasIcon)
  1045. {
  1046. {
  1047. XmlElement* iconGroup = projectXml.createNewChildElement ("ItemGroup");
  1048. XmlElement* e = iconGroup->createNewChildElement ("None");
  1049. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1050. }
  1051. {
  1052. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1053. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1054. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1055. }
  1056. }
  1057. {
  1058. XmlElement* e = projectXml.createNewChildElement ("Import");
  1059. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1060. }
  1061. {
  1062. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1063. e->setAttribute ("Label", "ExtensionTargets");
  1064. }
  1065. }
  1066. String getProjectType() const
  1067. {
  1068. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1069. else if (projectType.isAudioPlugin() || projectType.isBrowserPlugin()) return "DynamicLibrary";
  1070. else if (projectType.isLibrary()) return "StaticLibrary";
  1071. jassertfalse;
  1072. return String::empty;
  1073. }
  1074. //==============================================================================
  1075. void addFileToCompile (const RelativePath& file, XmlElement& cpps, XmlElement& headers, const bool excludeFromBuild, const bool useStdcall)
  1076. {
  1077. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1078. if (file.hasFileExtension ("cpp;cc;cxx;c"))
  1079. {
  1080. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1081. e->setAttribute ("Include", file.toWindowsStyle());
  1082. if (excludeFromBuild)
  1083. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1084. if (useStdcall)
  1085. {
  1086. jassertfalse;
  1087. }
  1088. }
  1089. else if (file.hasFileExtension (headerFileExtensions))
  1090. {
  1091. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", file.toWindowsStyle());
  1092. }
  1093. }
  1094. void addFilesToCompile (const Array<RelativePath>& files, XmlElement& cpps, XmlElement& headers, bool useStdCall)
  1095. {
  1096. for (int i = 0; i < files.size(); ++i)
  1097. addFileToCompile (files.getReference(i), cpps, headers, false, useStdCall);
  1098. }
  1099. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, bool useStdCall)
  1100. {
  1101. if (projectItem.isGroup())
  1102. {
  1103. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1104. addFilesToCompile (projectItem.getChild(i), cpps, headers, useStdCall);
  1105. }
  1106. else
  1107. {
  1108. if (projectItem.shouldBeAddedToTargetProject())
  1109. {
  1110. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1111. if (path.hasFileExtension (headerFileExtensions) || (path.hasFileExtension ("cpp;cc;c;cxx") && projectItem.shouldBeCompiled()))
  1112. addFileToCompile (path, cpps, headers, false, useStdCall);
  1113. }
  1114. }
  1115. }
  1116. //==============================================================================
  1117. void addFilterGroup (XmlElement& groups, const String& path)
  1118. {
  1119. XmlElement* e = groups.createNewChildElement ("Filter");
  1120. e->setAttribute ("Include", path);
  1121. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1122. }
  1123. void addFileToFilter (const RelativePath& file, const String& groupPath, XmlElement& cpps, XmlElement& headers)
  1124. {
  1125. XmlElement* e;
  1126. if (file.hasFileExtension (headerFileExtensions))
  1127. e = headers.createNewChildElement ("ClInclude");
  1128. else
  1129. e = cpps.createNewChildElement ("ClCompile");
  1130. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1131. e->setAttribute ("Include", file.toWindowsStyle());
  1132. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1133. }
  1134. void addFilesToFilter (const Project::Item& projectItem, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1135. {
  1136. if (projectItem.isGroup())
  1137. {
  1138. addFilterGroup (groups, path);
  1139. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1140. addFilesToFilter (projectItem.getChild(i),
  1141. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName().toString(),
  1142. cpps, headers, groups);
  1143. }
  1144. else
  1145. {
  1146. if (projectItem.shouldBeAddedToTargetProject())
  1147. {
  1148. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1149. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers);
  1150. }
  1151. }
  1152. }
  1153. void addFilesToFilter (const Array<RelativePath>& files, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1154. {
  1155. if (files.size() > 0)
  1156. {
  1157. addFilterGroup (groups, path);
  1158. for (int i = 0; i < files.size(); ++i)
  1159. addFileToFilter (files.getReference(i), path, cpps, headers);
  1160. }
  1161. }
  1162. void fillInFiltersXml (XmlElement& filterXml)
  1163. {
  1164. filterXml.setAttribute ("ToolsVersion", "4.0");
  1165. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1166. XmlElement* groups = filterXml.createNewChildElement ("ItemGroup");
  1167. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1168. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1169. addFilesToFilter (getMainGroup(), projectName, *cpps, *headers, *groups);
  1170. for (int i = 0; i < generatedGroups.size(); ++i)
  1171. if (generatedGroups.getReference(i).getNumChildren() > 0)
  1172. addFilesToFilter (generatedGroups.getReference(i), project.getJuceCodeGroupName(), *cpps, *headers, *groups);
  1173. if (iconFile.exists())
  1174. {
  1175. {
  1176. XmlElement* iconGroup = filterXml.createNewChildElement ("ItemGroup");
  1177. XmlElement* e = iconGroup->createNewChildElement ("None");
  1178. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1179. e->createNewChildElement ("Filter")->addTextElement (project.getJuceCodeGroupName());
  1180. }
  1181. {
  1182. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1183. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1184. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1185. e->createNewChildElement ("Filter")->addTextElement (project.getJuceCodeGroupName());
  1186. }
  1187. }
  1188. }
  1189. //==============================================================================
  1190. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010);
  1191. };
  1192. #endif // __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__