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.

1670 lines
73KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. class MSVCProjectExporterBase : public ProjectExporter
  18. {
  19. public:
  20. MSVCProjectExporterBase (Project& p, const ValueTree& t, const char* const folderName)
  21. : ProjectExporter (p, t)
  22. {
  23. if (getTargetLocationString().isEmpty())
  24. getTargetLocationValue() = getDefaultBuildsRootFolder() + folderName;
  25. projectGUID = createGUID (project.getProjectUID());
  26. updateOldSettings();
  27. }
  28. //==============================================================================
  29. bool usesMMFiles() const override { return false; }
  30. bool isVisualStudio() const override { return true; }
  31. bool isWindows() const override { return true; }
  32. bool canCopeWithDuplicateFiles() override { return false; }
  33. bool launchProject() override
  34. {
  35. #if JUCE_WINDOWS
  36. return getSLNFile().startAsProcess();
  37. #else
  38. return false;
  39. #endif
  40. }
  41. bool canLaunchProject() override
  42. {
  43. #if JUCE_WINDOWS
  44. return true;
  45. #else
  46. return false;
  47. #endif
  48. }
  49. void createExporterProperties (PropertyListBuilder&) override
  50. {
  51. }
  52. enum OptimisationLevel
  53. {
  54. optimisationOff = 1,
  55. optimiseMinSize = 2,
  56. optimiseMaxSpeed = 3
  57. };
  58. protected:
  59. String projectGUID;
  60. mutable File rcFile, iconFile;
  61. File getProjectFile (const String& extension) const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (extension); }
  62. File getSLNFile() const { return getProjectFile (".sln"); }
  63. bool isLibraryDLL() const { return msvcIsDLL || projectType.isDynamicLibrary(); }
  64. static String prependIfNotAbsolute (const String& file, const char* prefix)
  65. {
  66. if (File::isAbsolutePath (file) || file.startsWithChar ('$'))
  67. prefix = "";
  68. return prefix + FileHelpers::windowsStylePath (file);
  69. }
  70. String getIntDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(IntDir)\\"); }
  71. String getOutDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(OutDir)\\"); }
  72. void updateOldSettings()
  73. {
  74. {
  75. const String oldStylePrebuildCommand (getSettingString (Ids::prebuildCommand));
  76. settings.removeProperty (Ids::prebuildCommand, nullptr);
  77. if (oldStylePrebuildCommand.isNotEmpty())
  78. for (ConfigIterator config (*this); config.next();)
  79. dynamic_cast<MSVCBuildConfiguration&> (*config).getPrebuildCommand() = oldStylePrebuildCommand;
  80. }
  81. {
  82. const String oldStyleLibName (getSettingString ("libraryName_Debug"));
  83. settings.removeProperty ("libraryName_Debug", nullptr);
  84. if (oldStyleLibName.isNotEmpty())
  85. for (ConfigIterator config (*this); config.next();)
  86. if (config->isDebug())
  87. config->getTargetBinaryName() = oldStyleLibName;
  88. }
  89. {
  90. const String oldStyleLibName (getSettingString ("libraryName_Release"));
  91. settings.removeProperty ("libraryName_Release", nullptr);
  92. if (oldStyleLibName.isNotEmpty())
  93. for (ConfigIterator config (*this); config.next();)
  94. if (! config->isDebug())
  95. config->getTargetBinaryName() = oldStyleLibName;
  96. }
  97. }
  98. //==============================================================================
  99. class MSVCBuildConfiguration : public BuildConfiguration
  100. {
  101. public:
  102. MSVCBuildConfiguration (Project& p, const ValueTree& settings)
  103. : BuildConfiguration (p, settings)
  104. {
  105. if (getWarningLevel() == 0)
  106. getWarningLevelValue() = 4;
  107. setValueIfVoid (shouldGenerateManifestValue(), true);
  108. }
  109. Value getWarningLevelValue() { return getValue (Ids::winWarningLevel); }
  110. int getWarningLevel() const { return config [Ids::winWarningLevel]; }
  111. Value getWarningsTreatedAsErrors() { return getValue (Ids::warningsAreErrors); }
  112. bool areWarningsTreatedAsErrors() const { return config [Ids::warningsAreErrors]; }
  113. Value getPrebuildCommand() { return getValue (Ids::prebuildCommand); }
  114. String getPrebuildCommandString() const { return config [Ids::prebuildCommand]; }
  115. Value getPostbuildCommand() { return getValue (Ids::postbuildCommand); }
  116. String getPostbuildCommandString() const { return config [Ids::postbuildCommand]; }
  117. Value shouldGenerateDebugSymbolsValue() { return getValue (Ids::alwaysGenerateDebugSymbols); }
  118. bool shouldGenerateDebugSymbols() const { return config [Ids::alwaysGenerateDebugSymbols]; }
  119. Value shouldGenerateManifestValue() { return getValue (Ids::generateManifest); }
  120. bool shouldGenerateManifest() const { return config [Ids::generateManifest]; }
  121. Value getWholeProgramOptValue() { return getValue (Ids::wholeProgramOptimisation); }
  122. bool shouldDisableWholeProgramOpt() const { return static_cast<int> (config [Ids::wholeProgramOptimisation]) > 0; }
  123. Value getUsingRuntimeLibDLL() { return getValue (Ids::useRuntimeLibDLL); }
  124. bool isUsingRuntimeLibDLL() const { return config [Ids::useRuntimeLibDLL]; }
  125. String getIntermediatesPath() const { return config [Ids::intermediatesPath].toString(); }
  126. Value getIntermediatesPathValue() { return getValue (Ids::intermediatesPath); }
  127. String getCharacterSet() const { return config [Ids::characterSet].toString(); }
  128. Value getCharacterSetValue() { return getValue (Ids::characterSet); }
  129. String getOutputFilename (const String& suffix, bool forceSuffix) const
  130. {
  131. const String target (File::createLegalFileName (getTargetBinaryNameString().trim()));
  132. if (forceSuffix || ! target.containsChar ('.'))
  133. return target.upToLastOccurrenceOf (".", false, false) + suffix;
  134. return target;
  135. }
  136. var getDefaultOptimisationLevel() const override { return var ((int) (isDebug() ? optimisationOff : optimiseMaxSpeed)); }
  137. void createConfigProperties (PropertyListBuilder& props) override
  138. {
  139. static const char* optimisationLevels[] = { "No optimisation", "Minimise size", "Maximise speed", 0 };
  140. const int optimisationLevelValues[] = { optimisationOff, optimiseMinSize, optimiseMaxSpeed, 0 };
  141. props.add (new ChoicePropertyComponent (getOptimisationLevel(), "Optimisation",
  142. StringArray (optimisationLevels),
  143. Array<var> (optimisationLevelValues)),
  144. "The optimisation level for this configuration");
  145. props.add (new TextPropertyComponent (getIntermediatesPathValue(), "Intermediates path", 2048, false),
  146. "An optional path to a folder to use for the intermediate build files. Note that Visual Studio allows "
  147. "you to use macros in this path, e.g. \"$(TEMP)\\MyAppBuildFiles\\$(Configuration)\", which is a handy way to "
  148. "send them to the user's temp folder.");
  149. static const char* warningLevelNames[] = { "Low", "Medium", "High", nullptr };
  150. const int warningLevels[] = { 2, 3, 4 };
  151. props.add (new ChoicePropertyComponent (getWarningLevelValue(), "Warning Level",
  152. StringArray (warningLevelNames), Array<var> (warningLevels, numElementsInArray (warningLevels))));
  153. props.add (new BooleanPropertyComponent (getWarningsTreatedAsErrors(), "Warnings", "Treat warnings as errors"));
  154. {
  155. static const char* runtimeNames[] = { "(Default)", "Use static runtime", "Use DLL runtime", nullptr };
  156. const var runtimeValues[] = { var(), var (false), var (true) };
  157. props.add (new ChoicePropertyComponent (getUsingRuntimeLibDLL(), "Runtime Library",
  158. StringArray (runtimeNames), Array<var> (runtimeValues, numElementsInArray (runtimeValues))));
  159. }
  160. {
  161. static const char* wpoNames[] = { "Enable link-time code generation when possible",
  162. "Always disable link-time code generation", nullptr };
  163. const var wpoValues[] = { var(), var (1) };
  164. props.add (new ChoicePropertyComponent (getWholeProgramOptValue(), "Whole Program Optimisation",
  165. StringArray (wpoNames), Array<var> (wpoValues, numElementsInArray (wpoValues))));
  166. }
  167. if (! isDebug())
  168. props.add (new BooleanPropertyComponent (shouldGenerateDebugSymbolsValue(), "Debug Symbols", "Force generation of debug symbols"));
  169. props.add (new TextPropertyComponent (getPrebuildCommand(), "Pre-build Command", 2048, true));
  170. props.add (new TextPropertyComponent (getPostbuildCommand(), "Post-build Command", 2048, true));
  171. props.add (new BooleanPropertyComponent (shouldGenerateManifestValue(), "Manifest", "Generate Manifest"));
  172. {
  173. static const char* characterSetNames[] = { "Default", "MultiByte", "Unicode", nullptr };
  174. const var charSets[] = { var::null, "MultiByte", "Unicode", };
  175. props.add (new ChoicePropertyComponent (getCharacterSetValue(), "Character Set",
  176. StringArray (characterSetNames), Array<var> (charSets, numElementsInArray (charSets))));
  177. }
  178. }
  179. };
  180. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  181. {
  182. return new MSVCBuildConfiguration (project, v);
  183. }
  184. //==============================================================================
  185. String getConfigTargetPath (const BuildConfiguration& config) const
  186. {
  187. const String binaryPath (config.getTargetBinaryRelativePathString().trim());
  188. if (binaryPath.isEmpty())
  189. return binaryPath;
  190. RelativePath binaryRelPath (binaryPath, RelativePath::projectFolder);
  191. if (binaryRelPath.isAbsolute())
  192. return binaryRelPath.toWindowsStyle();
  193. return prependDot (binaryRelPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder)
  194. .toWindowsStyle());
  195. }
  196. String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const
  197. {
  198. StringPairArray defines (msvcExtraPreprocessorDefs);
  199. defines.set ("WIN32", "");
  200. defines.set ("_WINDOWS", "");
  201. if (config.isDebug())
  202. {
  203. defines.set ("DEBUG", "");
  204. defines.set ("_DEBUG", "");
  205. }
  206. else
  207. {
  208. defines.set ("NDEBUG", "");
  209. }
  210. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  211. StringArray result;
  212. for (int i = 0; i < defines.size(); ++i)
  213. {
  214. String def (defines.getAllKeys()[i]);
  215. const String value (defines.getAllValues()[i]);
  216. if (value.isNotEmpty())
  217. def << "=" << value;
  218. result.add (def);
  219. }
  220. return result.joinIntoString (joinString);
  221. }
  222. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  223. {
  224. StringArray searchPaths (extraSearchPaths);
  225. searchPaths.addArray (config.getHeaderSearchPaths());
  226. return getCleanedStringArray (searchPaths);
  227. }
  228. virtual String createConfigName (const BuildConfiguration& config) const
  229. {
  230. return config.getName() + "|Win32";
  231. }
  232. //==============================================================================
  233. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString, const File& vcProject) const
  234. {
  235. if (commentString.isNotEmpty())
  236. commentString += newLine;
  237. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  238. << commentString
  239. << "Project(\"" << createGUID (projectName + "sln_guid") << "\") = \"" << projectName << "\", \""
  240. << vcProject.getFileName() << "\", \"" << projectGUID << '"' << newLine
  241. << "EndProject" << newLine
  242. << "Global" << newLine
  243. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  244. for (ConstConfigIterator i (*this); i.next();)
  245. {
  246. const String configName (createConfigName (*i));
  247. out << "\t\t" << configName << " = " << configName << newLine;
  248. }
  249. out << "\tEndGlobalSection" << newLine
  250. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  251. for (ConstConfigIterator i (*this); i.next();)
  252. {
  253. const String configName (createConfigName (*i));
  254. out << "\t\t" << projectGUID << "." << configName << ".ActiveCfg = " << configName << newLine;
  255. out << "\t\t" << projectGUID << "." << configName << ".Build.0 = " << configName << newLine;
  256. }
  257. out << "\tEndGlobalSection" << newLine
  258. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  259. << "\t\tHideSolutionNode = FALSE" << newLine
  260. << "\tEndGlobalSection" << newLine
  261. << "EndGlobal" << newLine;
  262. }
  263. //==============================================================================
  264. static void writeBMPImage (const Image& image, const int w, const int h, MemoryOutputStream& out)
  265. {
  266. const int maskStride = (w / 8 + 3) & ~3;
  267. out.writeInt (40); // bitmapinfoheader size
  268. out.writeInt (w);
  269. out.writeInt (h * 2);
  270. out.writeShort (1); // planes
  271. out.writeShort (32); // bits
  272. out.writeInt (0); // compression
  273. out.writeInt ((h * w * 4) + (h * maskStride)); // size image
  274. out.writeInt (0); // x pixels per meter
  275. out.writeInt (0); // y pixels per meter
  276. out.writeInt (0); // clr used
  277. out.writeInt (0); // clr important
  278. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  279. const int alphaThreshold = 5;
  280. int y;
  281. for (y = h; --y >= 0;)
  282. {
  283. for (int x = 0; x < w; ++x)
  284. {
  285. const Colour pixel (bitmap.getPixelColour (x, y));
  286. if (pixel.getAlpha() <= alphaThreshold)
  287. {
  288. out.writeInt (0);
  289. }
  290. else
  291. {
  292. out.writeByte ((char) pixel.getBlue());
  293. out.writeByte ((char) pixel.getGreen());
  294. out.writeByte ((char) pixel.getRed());
  295. out.writeByte ((char) pixel.getAlpha());
  296. }
  297. }
  298. }
  299. for (y = h; --y >= 0;)
  300. {
  301. int mask = 0, count = 0;
  302. for (int x = 0; x < w; ++x)
  303. {
  304. const Colour pixel (bitmap.getPixelColour (x, y));
  305. mask <<= 1;
  306. if (pixel.getAlpha() <= alphaThreshold)
  307. mask |= 1;
  308. if (++count == 8)
  309. {
  310. out.writeByte ((char) mask);
  311. count = 0;
  312. mask = 0;
  313. }
  314. }
  315. if (mask != 0)
  316. out.writeByte ((char) mask);
  317. for (int i = maskStride - w / 8; --i >= 0;)
  318. out.writeByte (0);
  319. }
  320. }
  321. static void writeIconFile (const Array<Image>& images, MemoryOutputStream& out)
  322. {
  323. out.writeShort (0); // reserved
  324. out.writeShort (1); // .ico tag
  325. out.writeShort ((short) images.size());
  326. MemoryOutputStream dataBlock;
  327. const int imageDirEntrySize = 16;
  328. const int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  329. for (int i = 0; i < images.size(); ++i)
  330. {
  331. const size_t oldDataSize = dataBlock.getDataSize();
  332. const Image& image = images.getReference (i);
  333. const int w = image.getWidth();
  334. const int h = image.getHeight();
  335. if (w >= 256 || h >= 256)
  336. {
  337. PNGImageFormat pngFormat;
  338. pngFormat.writeImageToStream (image, dataBlock);
  339. }
  340. else
  341. {
  342. writeBMPImage (image, w, h, dataBlock);
  343. }
  344. out.writeByte ((char) w);
  345. out.writeByte ((char) h);
  346. out.writeByte (0);
  347. out.writeByte (0);
  348. out.writeShort (1); // colour planes
  349. out.writeShort (32); // bits per pixel
  350. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  351. out.writeInt (dataBlockStart + (int) oldDataSize);
  352. }
  353. jassert (out.getPosition() == dataBlockStart);
  354. out << dataBlock;
  355. }
  356. bool hasResourceFile() const
  357. {
  358. return ! projectType.isStaticLibrary();
  359. }
  360. void createResourcesAndIcon() const
  361. {
  362. if (hasResourceFile())
  363. {
  364. Array<Image> images;
  365. const int sizes[] = { 16, 32, 48, 256 };
  366. for (int i = 0; i < numElementsInArray (sizes); ++i)
  367. {
  368. Image im (getBestIconForSize (sizes[i], true));
  369. if (im.isValid())
  370. images.add (im);
  371. }
  372. if (images.size() > 0)
  373. {
  374. iconFile = getTargetFolder().getChildFile ("icon.ico");
  375. MemoryOutputStream mo;
  376. writeIconFile (images, mo);
  377. overwriteFileIfDifferentOrThrow (iconFile, mo);
  378. }
  379. createRCFile();
  380. }
  381. }
  382. void createRCFile() const
  383. {
  384. rcFile = getTargetFolder().getChildFile ("resources.rc");
  385. const String version (project.getVersionString());
  386. MemoryOutputStream mo;
  387. mo << "#ifdef JUCE_USER_DEFINED_RC_FILE" << newLine
  388. << " #include JUCE_USER_DEFINED_RC_FILE" << newLine
  389. << "#else" << newLine
  390. << newLine
  391. << "#undef WIN32_LEAN_AND_MEAN" << newLine
  392. << "#define WIN32_LEAN_AND_MEAN" << newLine
  393. << "#include <windows.h>" << newLine
  394. << newLine
  395. << "VS_VERSION_INFO VERSIONINFO" << newLine
  396. << "FILEVERSION " << getCommaSeparatedVersionNumber (version) << newLine
  397. << "BEGIN" << newLine
  398. << " BLOCK \"StringFileInfo\"" << newLine
  399. << " BEGIN" << newLine
  400. << " BLOCK \"040904E4\"" << newLine
  401. << " BEGIN" << newLine;
  402. writeRCValue (mo, "CompanyName", project.getCompanyName().toString());
  403. writeRCValue (mo, "FileDescription", project.getTitle());
  404. writeRCValue (mo, "FileVersion", version);
  405. writeRCValue (mo, "ProductName", project.getTitle());
  406. writeRCValue (mo, "ProductVersion", version);
  407. mo << " END" << newLine
  408. << " END" << newLine
  409. << newLine
  410. << " BLOCK \"VarFileInfo\"" << newLine
  411. << " BEGIN" << newLine
  412. << " VALUE \"Translation\", 0x409, 65001" << newLine
  413. << " END" << newLine
  414. << "END" << newLine
  415. << newLine
  416. << "#endif" << newLine;
  417. if (iconFile != File::nonexistent)
  418. mo << newLine
  419. << "IDI_ICON1 ICON DISCARDABLE " << iconFile.getFileName().quoted()
  420. << newLine
  421. << "IDI_ICON2 ICON DISCARDABLE " << iconFile.getFileName().quoted();
  422. overwriteFileIfDifferentOrThrow (rcFile, mo);
  423. }
  424. static void writeRCValue (MemoryOutputStream& mo, const String& name, const String& value)
  425. {
  426. if (value.isNotEmpty())
  427. mo << " VALUE \"" << name << "\", \""
  428. << CppTokeniserFunctions::addEscapeChars (value) << "\\0\"" << newLine;
  429. }
  430. static String getCommaSeparatedVersionNumber (const String& version)
  431. {
  432. StringArray versionParts;
  433. versionParts.addTokens (version, ",.", "");
  434. versionParts.trim();
  435. versionParts.removeEmptyStrings();
  436. while (versionParts.size() < 4)
  437. versionParts.add ("0");
  438. return versionParts.joinIntoString (",");
  439. }
  440. static String prependDot (const String& filename)
  441. {
  442. return FileHelpers::isAbsolutePath (filename) ? filename
  443. : (".\\" + filename);
  444. }
  445. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase)
  446. };
  447. //==============================================================================
  448. class MSVCProjectExporterVC2008 : public MSVCProjectExporterBase
  449. {
  450. public:
  451. //==============================================================================
  452. MSVCProjectExporterVC2008 (Project& p, const ValueTree& s,
  453. const char* folderName = "VisualStudio2008")
  454. : MSVCProjectExporterBase (p, s, folderName)
  455. {
  456. name = getName();
  457. }
  458. static const char* getName() { return "Visual Studio 2008"; }
  459. static const char* getValueTreeTypeName() { return "VS2008"; }
  460. int getVisualStudioVersion() const override { return 9; }
  461. static MSVCProjectExporterVC2008* createForSettings (Project& project, const ValueTree& settings)
  462. {
  463. if (settings.hasType (getValueTreeTypeName()))
  464. return new MSVCProjectExporterVC2008 (project, settings);
  465. return nullptr;
  466. }
  467. //==============================================================================
  468. void create (const OwnedArray<LibraryModule>&) const
  469. {
  470. createResourcesAndIcon();
  471. if (hasResourceFile())
  472. {
  473. for (int i = 0; i < getAllGroups().size(); ++i)
  474. {
  475. Project::Item& group = getAllGroups().getReference(i);
  476. if (group.getID() == ProjectSaver::getGeneratedGroupID())
  477. {
  478. if (iconFile != File::nonexistent)
  479. {
  480. group.addFile (iconFile, -1, true);
  481. group.findItemForFile (iconFile).getShouldAddToResourceValue() = false;
  482. }
  483. group.addFile (rcFile, -1, true);
  484. group.findItemForFile (rcFile).getShouldAddToResourceValue() = false;
  485. break;
  486. }
  487. }
  488. }
  489. {
  490. XmlElement projectXml ("VisualStudioProject");
  491. fillInProjectXml (projectXml);
  492. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  493. }
  494. {
  495. MemoryOutputStream mo;
  496. writeSolutionFile (mo, getSolutionVersionString(), String::empty, getVCProjFile());
  497. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  498. }
  499. }
  500. protected:
  501. virtual String getProjectVersionString() const { return "9.00"; }
  502. virtual String getSolutionVersionString() const { return String ("10.00") + newLine + "# Visual C++ Express 2008"; }
  503. File getVCProjFile() const { return getProjectFile (".vcproj"); }
  504. //==============================================================================
  505. void fillInProjectXml (XmlElement& projectXml) const
  506. {
  507. projectXml.setAttribute ("ProjectType", "Visual C++");
  508. projectXml.setAttribute ("Version", getProjectVersionString());
  509. projectXml.setAttribute ("Name", projectName);
  510. projectXml.setAttribute ("ProjectGUID", projectGUID);
  511. projectXml.setAttribute ("TargetFrameworkVersion", "131072");
  512. {
  513. XmlElement* platforms = projectXml.createNewChildElement ("Platforms");
  514. XmlElement* platform = platforms->createNewChildElement ("Platform");
  515. platform->setAttribute ("Name", "Win32");
  516. }
  517. projectXml.createNewChildElement ("ToolFiles");
  518. createConfigs (*projectXml.createNewChildElement ("Configurations"));
  519. projectXml.createNewChildElement ("References");
  520. createFiles (*projectXml.createNewChildElement ("Files"));
  521. projectXml.createNewChildElement ("Globals");
  522. }
  523. //==============================================================================
  524. void addFile (const RelativePath& file, XmlElement& parent, const bool excludeFromBuild, const bool useStdcall) const
  525. {
  526. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  527. XmlElement* fileXml = parent.createNewChildElement ("File");
  528. fileXml->setAttribute ("RelativePath", file.toWindowsStyle());
  529. if (excludeFromBuild || useStdcall)
  530. {
  531. for (ConstConfigIterator i (*this); i.next();)
  532. {
  533. XmlElement* fileConfig = fileXml->createNewChildElement ("FileConfiguration");
  534. fileConfig->setAttribute ("Name", createConfigName (*i));
  535. if (excludeFromBuild)
  536. fileConfig->setAttribute ("ExcludedFromBuild", "true");
  537. XmlElement* tool = createToolElement (*fileConfig, "VCCLCompilerTool");
  538. if (useStdcall)
  539. tool->setAttribute ("CallingConvention", "2");
  540. }
  541. }
  542. }
  543. XmlElement* createGroup (const String& groupName, XmlElement& parent) const
  544. {
  545. XmlElement* filter = parent.createNewChildElement ("Filter");
  546. filter->setAttribute ("Name", groupName);
  547. return filter;
  548. }
  549. void addFiles (const Project::Item& projectItem, XmlElement& parent) const
  550. {
  551. if (projectItem.isGroup())
  552. {
  553. XmlElement* filter = createGroup (projectItem.getName(), parent);
  554. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  555. addFiles (projectItem.getChild(i), *filter);
  556. }
  557. else if (projectItem.shouldBeAddedToTargetProject())
  558. {
  559. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  560. addFile (path, parent,
  561. projectItem.shouldBeAddedToBinaryResources()
  562. || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()),
  563. shouldFileBeCompiledByDefault (path) && (bool) projectItem.shouldUseStdCall());
  564. }
  565. }
  566. void createFiles (XmlElement& files) const
  567. {
  568. for (int i = 0; i < getAllGroups().size(); ++i)
  569. {
  570. const Project::Item& group = getAllGroups().getReference(i);
  571. if (group.getNumChildren() > 0)
  572. addFiles (group, files);
  573. }
  574. }
  575. //==============================================================================
  576. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  577. {
  578. XmlElement* const e = parent.createNewChildElement ("Tool");
  579. e->setAttribute ("Name", toolName);
  580. return e;
  581. }
  582. void createConfig (XmlElement& xml, const MSVCBuildConfiguration& config) const
  583. {
  584. const bool isDebug = config.isDebug();
  585. xml.setAttribute ("Name", createConfigName (config));
  586. if (getConfigTargetPath (config).isNotEmpty())
  587. xml.setAttribute ("OutputDirectory", FileHelpers::windowsStylePath (getConfigTargetPath (config)));
  588. if (config.getIntermediatesPath().isNotEmpty())
  589. xml.setAttribute ("IntermediateDirectory", FileHelpers::windowsStylePath (config.getIntermediatesPath()));
  590. xml.setAttribute ("ConfigurationType", isLibraryDLL() ? "2" : (projectType.isStaticLibrary() ? "4" : "1"));
  591. xml.setAttribute ("UseOfMFC", "0");
  592. xml.setAttribute ("ATLMinimizesCRunTimeLibraryUsage", "false");
  593. xml.setAttribute ("CharacterSet", "2");
  594. if (! (isDebug || config.shouldDisableWholeProgramOpt()))
  595. xml.setAttribute ("WholeProgramOptimization", "1");
  596. XmlElement* preBuildEvent = createToolElement (xml, "VCPreBuildEventTool");
  597. if (config.getPrebuildCommandString().isNotEmpty())
  598. {
  599. preBuildEvent->setAttribute ("Description", "Pre-build");
  600. preBuildEvent->setAttribute ("CommandLine", config.getPrebuildCommandString());
  601. }
  602. createToolElement (xml, "VCCustomBuildTool");
  603. createToolElement (xml, "VCXMLDataGeneratorTool");
  604. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  605. if (! projectType.isStaticLibrary())
  606. {
  607. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  608. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  609. midl->setAttribute ("MkTypLibCompatible", "true");
  610. midl->setAttribute ("SuppressStartupBanner", "true");
  611. midl->setAttribute ("TargetEnvironment", "1");
  612. midl->setAttribute ("TypeLibraryName", getIntDirFile (config, config.getOutputFilename (".tlb", true)));
  613. midl->setAttribute ("HeaderFileName", "");
  614. }
  615. {
  616. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  617. compiler->setAttribute ("Optimization", getOptimisationLevelString (config.getOptimisationLevelInt()));
  618. if (isDebug)
  619. {
  620. compiler->setAttribute ("BufferSecurityCheck", "");
  621. compiler->setAttribute ("DebugInformationFormat", projectType.isStaticLibrary() ? "3" : "4");
  622. }
  623. else
  624. {
  625. compiler->setAttribute ("InlineFunctionExpansion", "1");
  626. compiler->setAttribute ("StringPooling", "true");
  627. }
  628. compiler->setAttribute ("AdditionalIncludeDirectories", replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (";")));
  629. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  630. compiler->setAttribute ("RuntimeLibrary", config.isUsingRuntimeLibDLL() ? (isDebug ? 3 : 2) // MT DLL
  631. : (isDebug ? 1 : 0)); // MT static
  632. compiler->setAttribute ("RuntimeTypeInfo", "true");
  633. compiler->setAttribute ("UsePrecompiledHeader", "0");
  634. compiler->setAttribute ("PrecompiledHeaderFile", getIntDirFile (config, config.getOutputFilename (".pch", true)));
  635. compiler->setAttribute ("AssemblerListingLocation", "$(IntDir)\\");
  636. compiler->setAttribute ("ObjectFile", "$(IntDir)\\");
  637. compiler->setAttribute ("ProgramDataBaseFileName", "$(IntDir)\\");
  638. compiler->setAttribute ("WarningLevel", String (config.getWarningLevel()));
  639. compiler->setAttribute ("SuppressStartupBanner", "true");
  640. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  641. if (extraFlags.isNotEmpty())
  642. compiler->setAttribute ("AdditionalOptions", extraFlags);
  643. }
  644. createToolElement (xml, "VCManagedResourceCompilerTool");
  645. {
  646. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  647. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  648. }
  649. createToolElement (xml, "VCPreLinkEventTool");
  650. if (! projectType.isStaticLibrary())
  651. {
  652. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  653. linker->setAttribute ("OutputFile", getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  654. linker->setAttribute ("SuppressStartupBanner", "true");
  655. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  656. linker->setAttribute ("GenerateDebugInformation", (isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  657. linker->setAttribute ("ProgramDatabaseFile", getIntDirFile (config, config.getOutputFilename (".pdb", true)));
  658. linker->setAttribute ("SubSystem", msvcIsWindowsSubsystem ? "2" : "1");
  659. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  660. if (librarySearchPaths.size() > 0)
  661. linker->setAttribute ("AdditionalLibraryDirectories", librarySearchPaths.joinIntoString (";"));
  662. linker->setAttribute ("GenerateManifest", config.shouldGenerateManifest() ? "true" : "false");
  663. if (! isDebug)
  664. {
  665. linker->setAttribute ("OptimizeReferences", "2");
  666. linker->setAttribute ("EnableCOMDATFolding", "2");
  667. }
  668. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  669. if (msvcDelayLoadedDLLs.isNotEmpty())
  670. linker->setAttribute ("DelayLoadDLLs", msvcDelayLoadedDLLs);
  671. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  672. linker->setAttribute ("ModuleDefinitionFile", config.config [Ids::msvcModuleDefinitionFile].toString());
  673. String externalLibraries (getExternalLibrariesString());
  674. if (externalLibraries.isNotEmpty())
  675. linker->setAttribute ("AdditionalDependencies", replacePreprocessorTokens (config, externalLibraries).trim());
  676. String extraLinkerOptions (getExtraLinkerFlagsString());
  677. if (extraLinkerOptions.isNotEmpty())
  678. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  679. }
  680. else
  681. {
  682. if (isLibraryDLL())
  683. {
  684. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  685. String extraLinkerOptions (getExtraLinkerFlagsString());
  686. extraLinkerOptions << " /IMPLIB:" << getOutDirFile (config, config.getOutputFilename (".lib", true));
  687. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  688. String externalLibraries (getExternalLibrariesString());
  689. if (externalLibraries.isNotEmpty())
  690. linker->setAttribute ("AdditionalDependencies", replacePreprocessorTokens (config, externalLibraries).trim());
  691. linker->setAttribute ("OutputFile", getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  692. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  693. }
  694. else
  695. {
  696. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  697. librarian->setAttribute ("OutputFile", getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  698. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  699. }
  700. }
  701. createToolElement (xml, "VCALinkTool");
  702. createToolElement (xml, "VCManifestTool");
  703. createToolElement (xml, "VCXDCMakeTool");
  704. {
  705. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  706. bscMake->setAttribute ("SuppressStartupBanner", "true");
  707. bscMake->setAttribute ("OutputFile", getIntDirFile (config, config.getOutputFilename (".bsc", true)));
  708. }
  709. createToolElement (xml, "VCFxCopTool");
  710. if (! projectType.isStaticLibrary())
  711. createToolElement (xml, "VCAppVerifierTool");
  712. XmlElement* postBuildEvent = createToolElement (xml, "VCPostBuildEventTool");
  713. if (config.getPostbuildCommandString().isNotEmpty())
  714. {
  715. postBuildEvent->setAttribute ("Description", "Post-build");
  716. postBuildEvent->setAttribute ("CommandLine", config.getPostbuildCommandString());
  717. }
  718. }
  719. void createConfigs (XmlElement& xml) const
  720. {
  721. for (ConstConfigIterator config (*this); config.next();)
  722. createConfig (*xml.createNewChildElement ("Configuration"),
  723. dynamic_cast<const MSVCBuildConfiguration&> (*config));
  724. }
  725. static const char* getOptimisationLevelString (int level)
  726. {
  727. switch (level)
  728. {
  729. case optimiseMaxSpeed: return "3";
  730. case optimiseMinSize: return "1";
  731. default: return "0";
  732. }
  733. }
  734. //==============================================================================
  735. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008)
  736. };
  737. //==============================================================================
  738. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  739. {
  740. public:
  741. MSVCProjectExporterVC2005 (Project& p, const ValueTree& t)
  742. : MSVCProjectExporterVC2008 (p, t, "VisualStudio2005")
  743. {
  744. name = getName();
  745. }
  746. static const char* getName() { return "Visual Studio 2005"; }
  747. static const char* getValueTreeTypeName() { return "VS2005"; }
  748. int getVisualStudioVersion() const override { return 8; }
  749. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  750. {
  751. if (settings.hasType (getValueTreeTypeName()))
  752. return new MSVCProjectExporterVC2005 (project, settings);
  753. return nullptr;
  754. }
  755. protected:
  756. String getProjectVersionString() const { return "8.00"; }
  757. String getSolutionVersionString() const { return String ("9.00") + newLine + "# Visual C++ Express 2005"; }
  758. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005)
  759. };
  760. //==============================================================================
  761. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  762. {
  763. public:
  764. MSVCProjectExporterVC2010 (Project& p, const ValueTree& t, const char* folderName = "VisualStudio2010")
  765. : MSVCProjectExporterBase (p, t, folderName)
  766. {
  767. name = getName();
  768. }
  769. static const char* getName() { return "Visual Studio 2010"; }
  770. static const char* getValueTreeTypeName() { return "VS2010"; }
  771. int getVisualStudioVersion() const override { return 10; }
  772. virtual String getSolutionComment() const { return "# Visual Studio 2010"; }
  773. virtual String getToolsVersion() const { return "4.0"; }
  774. virtual String getDefaultToolset() const { return "Windows7.1SDK"; }
  775. Value getPlatformToolsetValue() { return getSetting (Ids::toolset); }
  776. String getPlatformToolset() const
  777. {
  778. const String s (settings [Ids::toolset].toString());
  779. return s.isNotEmpty() ? s : getDefaultToolset();
  780. }
  781. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  782. {
  783. if (settings.hasType (getValueTreeTypeName()))
  784. return new MSVCProjectExporterVC2010 (project, settings);
  785. return nullptr;
  786. }
  787. void createExporterProperties (PropertyListBuilder& props) override
  788. {
  789. MSVCProjectExporterBase::createExporterProperties (props);
  790. static const char* toolsetNames[] = { "(default)", "v100", "v100_xp", "Windows7.1SDK", "CTP_Nov2013", nullptr };
  791. const var toolsets[] = { var(), "v100", "v100_xp", "Windows7.1SDK", "CTP_Nov2013" };
  792. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  793. StringArray (toolsetNames),
  794. Array<var> (toolsets, numElementsInArray (toolsets))));
  795. }
  796. //==============================================================================
  797. void create (const OwnedArray<LibraryModule>&) const
  798. {
  799. createResourcesAndIcon();
  800. {
  801. XmlElement projectXml ("Project");
  802. fillInProjectXml (projectXml);
  803. addPlatformToolsetToPropertyGroup (projectXml);
  804. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  805. }
  806. {
  807. XmlElement filtersXml ("Project");
  808. fillInFiltersXml (filtersXml);
  809. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  810. }
  811. {
  812. MemoryOutputStream mo;
  813. writeSolutionFile (mo, "11.00", getSolutionComment(), getVCProjFile());
  814. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  815. }
  816. }
  817. protected:
  818. //==============================================================================
  819. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  820. {
  821. public:
  822. VC2010BuildConfiguration (Project& p, const ValueTree& settings)
  823. : MSVCBuildConfiguration (p, settings)
  824. {
  825. if (getArchitectureType().toString().isEmpty())
  826. getArchitectureType() = get32BitArchName();
  827. }
  828. //==============================================================================
  829. static const char* get32BitArchName() { return "32-bit"; }
  830. static const char* get64BitArchName() { return "x64"; }
  831. Value getArchitectureType() { return getValue (Ids::winArchitecture); }
  832. bool is64Bit() const { return config [Ids::winArchitecture].toString() == get64BitArchName(); }
  833. Value getFastMathValue() { return getValue (Ids::fastMath); }
  834. bool isFastMathEnabled() const { return config [Ids::fastMath]; }
  835. //==============================================================================
  836. void createConfigProperties (PropertyListBuilder& props) override
  837. {
  838. MSVCBuildConfiguration::createConfigProperties (props);
  839. const char* const archTypes[] = { get32BitArchName(), get64BitArchName() };
  840. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  841. StringArray (archTypes, numElementsInArray (archTypes)),
  842. Array<var> (archTypes, numElementsInArray (archTypes))));
  843. props.add (new BooleanPropertyComponent (getFastMathValue(), "Relax IEEE compliance", "Enabled"),
  844. "Enable this to use FAST_MATH non-IEEE mode. (Warning: this can have unexpected results!)");
  845. }
  846. };
  847. virtual void addPlatformToolsetToPropertyGroup (XmlElement&) const {}
  848. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const
  849. {
  850. return new VC2010BuildConfiguration (project, v);
  851. }
  852. static bool is64Bit (const BuildConfiguration& config)
  853. {
  854. return dynamic_cast<const VC2010BuildConfiguration&> (config).is64Bit();
  855. }
  856. //==============================================================================
  857. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  858. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  859. String createConfigName (const BuildConfiguration& config) const
  860. {
  861. return config.getName() + (is64Bit (config) ? "|x64"
  862. : "|Win32");
  863. }
  864. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  865. {
  866. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  867. }
  868. //==============================================================================
  869. void fillInProjectXml (XmlElement& projectXml) const
  870. {
  871. projectXml.setAttribute ("DefaultTargets", "Build");
  872. projectXml.setAttribute ("ToolsVersion", getToolsVersion());
  873. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  874. {
  875. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  876. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  877. for (ConstConfigIterator config (*this); config.next();)
  878. {
  879. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  880. e->setAttribute ("Include", createConfigName (*config));
  881. e->createNewChildElement ("Configuration")->addTextElement (config->getName());
  882. e->createNewChildElement ("Platform")->addTextElement (is64Bit (*config) ? "x64" : "Win32");
  883. }
  884. }
  885. {
  886. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  887. globals->setAttribute ("Label", "Globals");
  888. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  889. }
  890. {
  891. XmlElement* imports = projectXml.createNewChildElement ("Import");
  892. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  893. }
  894. for (ConstConfigIterator i (*this); i.next();)
  895. {
  896. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  897. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  898. setConditionAttribute (*e, config);
  899. e->setAttribute ("Label", "Configuration");
  900. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  901. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  902. const String charSet (config.getCharacterSet());
  903. if (charSet.isNotEmpty())
  904. e->createNewChildElement ("CharacterSet")->addTextElement (charSet);
  905. if (! (config.isDebug() || config.shouldDisableWholeProgramOpt()))
  906. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  907. if (config.is64Bit())
  908. e->createNewChildElement ("PlatformToolset")->addTextElement (getPlatformToolset());
  909. }
  910. {
  911. XmlElement* e = projectXml.createNewChildElement ("Import");
  912. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  913. }
  914. {
  915. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  916. e->setAttribute ("Label", "ExtensionSettings");
  917. }
  918. {
  919. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  920. e->setAttribute ("Label", "PropertySheets");
  921. XmlElement* p = e->createNewChildElement ("Import");
  922. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  923. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  924. p->setAttribute ("Label", "LocalAppDataPlatform");
  925. }
  926. {
  927. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  928. e->setAttribute ("Label", "UserMacros");
  929. }
  930. {
  931. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  932. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  933. for (ConstConfigIterator i (*this); i.next();)
  934. {
  935. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  936. if (getConfigTargetPath (config).isNotEmpty())
  937. {
  938. XmlElement* outdir = props->createNewChildElement ("OutDir");
  939. setConditionAttribute (*outdir, config);
  940. outdir->addTextElement (FileHelpers::windowsStylePath (getConfigTargetPath (config)) + "\\");
  941. }
  942. if (config.getIntermediatesPath().isNotEmpty())
  943. {
  944. XmlElement* intdir = props->createNewChildElement ("IntDir");
  945. setConditionAttribute (*intdir, config);
  946. intdir->addTextElement (FileHelpers::windowsStylePath (config.getIntermediatesPath()) + "\\");
  947. }
  948. {
  949. XmlElement* targetName = props->createNewChildElement ("TargetName");
  950. setConditionAttribute (*targetName, config);
  951. targetName->addTextElement (config.getOutputFilename (String::empty, true));
  952. }
  953. {
  954. XmlElement* manifest = props->createNewChildElement ("GenerateManifest");
  955. setConditionAttribute (*manifest, config);
  956. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  957. }
  958. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  959. if (librarySearchPaths.size() > 0)
  960. {
  961. XmlElement* libPath = props->createNewChildElement ("LibraryPath");
  962. setConditionAttribute (*libPath, config);
  963. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  964. }
  965. }
  966. }
  967. for (ConstConfigIterator i (*this); i.next();)
  968. {
  969. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  970. const bool isDebug = config.isDebug();
  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 ("HeaderFileName");
  981. }
  982. bool isUsingEditAndContinue = false;
  983. {
  984. XmlElement* cl = group->createNewChildElement ("ClCompile");
  985. cl->createNewChildElement ("Optimization")->addTextElement (getOptimisationLevelString (config.getOptimisationLevelInt()));
  986. if (isDebug && config.getOptimisationLevelInt() <= optimisationOff)
  987. {
  988. isUsingEditAndContinue = ! config.is64Bit();
  989. cl->createNewChildElement ("DebugInformationFormat")
  990. ->addTextElement (isUsingEditAndContinue ? "EditAndContinue"
  991. : "ProgramDatabase");
  992. }
  993. StringArray includePaths (getHeaderSearchPaths (config));
  994. includePaths.add ("%(AdditionalIncludeDirectories)");
  995. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  996. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  997. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (config.isUsingRuntimeLibDLL() ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  998. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  999. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  1000. cl->createNewChildElement ("PrecompiledHeader");
  1001. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  1002. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  1003. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement ("$(IntDir)\\");
  1004. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (config.getWarningLevel()));
  1005. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1006. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  1007. if (config.isFastMathEnabled())
  1008. cl->createNewChildElement ("FloatingPointModel")->addTextElement ("Fast");
  1009. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  1010. if (extraFlags.isNotEmpty())
  1011. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  1012. if (config.areWarningsTreatedAsErrors())
  1013. cl->createNewChildElement ("TreatWarningAsError")->addTextElement ("true");
  1014. }
  1015. {
  1016. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  1017. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1018. : "NDEBUG;%(PreprocessorDefinitions)");
  1019. }
  1020. {
  1021. XmlElement* link = group->createNewChildElement ("Link");
  1022. link->createNewChildElement ("OutputFile")->addTextElement (getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  1023. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1024. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  1025. : "%(IgnoreSpecificDefaultLibraries)");
  1026. link->createNewChildElement ("GenerateDebugInformation")->addTextElement ((isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  1027. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (getIntDirFile (config, config.getOutputFilename (".pdb", true)));
  1028. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  1029. if (! config.is64Bit())
  1030. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  1031. if (isUsingEditAndContinue)
  1032. link->createNewChildElement ("ImageHasSafeExceptionHandlers")->addTextElement ("false");
  1033. if (! isDebug)
  1034. {
  1035. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  1036. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  1037. }
  1038. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  1039. if (librarySearchPaths.size() > 0)
  1040. link->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (replacePreprocessorTokens (config, librarySearchPaths.joinIntoString (";"))
  1041. + ";%(AdditionalLibraryDirectories)");
  1042. link->createNewChildElement ("LargeAddressAware")->addTextElement ("true");
  1043. String externalLibraries (getExternalLibrariesString());
  1044. if (externalLibraries.isNotEmpty())
  1045. link->createNewChildElement ("AdditionalDependencies")->addTextElement (replacePreprocessorTokens (config, externalLibraries).trim()
  1046. + ";%(AdditionalDependencies)");
  1047. String extraLinkerOptions (getExtraLinkerFlagsString());
  1048. if (extraLinkerOptions.isNotEmpty())
  1049. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  1050. + " %(AdditionalOptions)");
  1051. if (msvcDelayLoadedDLLs.isNotEmpty())
  1052. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (msvcDelayLoadedDLLs);
  1053. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  1054. link->createNewChildElement ("ModuleDefinitionFile")
  1055. ->addTextElement (config.config [Ids::msvcModuleDefinitionFile].toString());
  1056. }
  1057. {
  1058. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  1059. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1060. bsc->createNewChildElement ("OutputFile")->addTextElement (getIntDirFile (config, config.getOutputFilename (".bsc", true)));
  1061. }
  1062. if (config.getPrebuildCommandString().isNotEmpty())
  1063. group->createNewChildElement ("PreBuildEvent")
  1064. ->createNewChildElement ("Command")
  1065. ->addTextElement (config.getPrebuildCommandString());
  1066. if (config.getPostbuildCommandString().isNotEmpty())
  1067. group->createNewChildElement ("PostBuildEvent")
  1068. ->createNewChildElement ("Command")
  1069. ->addTextElement (config.getPostbuildCommandString());
  1070. }
  1071. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1072. {
  1073. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1074. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1075. for (int i = 0; i < getAllGroups().size(); ++i)
  1076. {
  1077. const Project::Item& group = getAllGroups().getReference(i);
  1078. if (group.getNumChildren() > 0)
  1079. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  1080. }
  1081. }
  1082. if (iconFile != File::nonexistent)
  1083. {
  1084. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1085. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1086. }
  1087. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1088. projectXml.addChildElement (otherFilesGroup.release());
  1089. if (hasResourceFile())
  1090. {
  1091. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1092. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1093. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1094. }
  1095. {
  1096. XmlElement* e = projectXml.createNewChildElement ("Import");
  1097. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1098. }
  1099. {
  1100. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1101. e->setAttribute ("Label", "ExtensionTargets");
  1102. }
  1103. }
  1104. String getProjectType() const
  1105. {
  1106. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1107. if (isLibraryDLL()) return "DynamicLibrary";
  1108. if (projectType.isStaticLibrary()) return "StaticLibrary";
  1109. jassertfalse;
  1110. return String::empty;
  1111. }
  1112. static const char* getOptimisationLevelString (int level)
  1113. {
  1114. switch (level)
  1115. {
  1116. case optimiseMaxSpeed: return "Full";
  1117. case optimiseMinSize: return "MinSpace";
  1118. default: return "Disabled";
  1119. }
  1120. }
  1121. //==============================================================================
  1122. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1123. {
  1124. if (projectItem.isGroup())
  1125. {
  1126. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1127. addFilesToCompile (projectItem.getChild(i), cpps, headers, otherFiles);
  1128. }
  1129. else if (projectItem.shouldBeAddedToTargetProject())
  1130. {
  1131. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1132. jassert (path.getRoot() == RelativePath::buildTargetFolder);
  1133. if (path.hasFileExtension (cOrCppFileExtensions))
  1134. {
  1135. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1136. e->setAttribute ("Include", path.toWindowsStyle());
  1137. if (! projectItem.shouldBeCompiled())
  1138. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1139. if (projectItem.shouldUseStdCall())
  1140. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  1141. }
  1142. else if (path.hasFileExtension (headerFileExtensions))
  1143. {
  1144. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  1145. }
  1146. else if (! path.hasFileExtension (objCFileExtensions))
  1147. {
  1148. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  1149. }
  1150. }
  1151. }
  1152. //==============================================================================
  1153. void addFilterGroup (XmlElement& groups, const String& path) const
  1154. {
  1155. XmlElement* e = groups.createNewChildElement ("Filter");
  1156. e->setAttribute ("Include", path);
  1157. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1158. }
  1159. void addFileToFilter (const RelativePath& file, const String& groupPath,
  1160. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1161. {
  1162. XmlElement* e;
  1163. if (file.hasFileExtension (headerFileExtensions))
  1164. e = headers.createNewChildElement ("ClInclude");
  1165. else if (file.hasFileExtension (sourceFileExtensions))
  1166. e = cpps.createNewChildElement ("ClCompile");
  1167. else
  1168. e = otherFiles.createNewChildElement ("None");
  1169. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1170. e->setAttribute ("Include", file.toWindowsStyle());
  1171. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1172. }
  1173. void addFilesToFilter (const Project::Item& projectItem, const String& path,
  1174. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  1175. {
  1176. if (projectItem.isGroup())
  1177. {
  1178. addFilterGroup (groups, path);
  1179. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1180. addFilesToFilter (projectItem.getChild(i),
  1181. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName(),
  1182. cpps, headers, otherFiles, groups);
  1183. }
  1184. else if (projectItem.shouldBeAddedToTargetProject())
  1185. {
  1186. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1187. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers, otherFiles);
  1188. }
  1189. }
  1190. void addFilesToFilter (const Array<RelativePath>& files, const String& path,
  1191. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups)
  1192. {
  1193. if (files.size() > 0)
  1194. {
  1195. addFilterGroup (groups, path);
  1196. for (int i = 0; i < files.size(); ++i)
  1197. addFileToFilter (files.getReference(i), path, cpps, headers, otherFiles);
  1198. }
  1199. }
  1200. void fillInFiltersXml (XmlElement& filterXml) const
  1201. {
  1202. filterXml.setAttribute ("ToolsVersion", getToolsVersion());
  1203. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1204. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1205. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1206. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1207. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1208. for (int i = 0; i < getAllGroups().size(); ++i)
  1209. {
  1210. const Project::Item& group = getAllGroups().getReference(i);
  1211. if (group.getNumChildren() > 0)
  1212. addFilesToFilter (group, group.getName(), *cpps, *headers, *otherFilesGroup, *groupsXml);
  1213. }
  1214. if (iconFile.exists())
  1215. {
  1216. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1217. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1218. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1219. }
  1220. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1221. filterXml.addChildElement (otherFilesGroup.release());
  1222. if (hasResourceFile())
  1223. {
  1224. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1225. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1226. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1227. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1228. }
  1229. }
  1230. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010)
  1231. };
  1232. //==============================================================================
  1233. class MSVCProjectExporterVC2012 : public MSVCProjectExporterVC2010
  1234. {
  1235. public:
  1236. MSVCProjectExporterVC2012 (Project& p, const ValueTree& t,
  1237. const char* folderName = "VisualStudio2012")
  1238. : MSVCProjectExporterVC2010 (p, t, folderName)
  1239. {
  1240. name = getName();
  1241. }
  1242. static const char* getName() { return "Visual Studio 2012"; }
  1243. static const char* getValueTreeTypeName() { return "VS2012"; }
  1244. int getVisualStudioVersion() const override { return 11; }
  1245. String getSolutionComment() const override { return "# Visual Studio 2012"; }
  1246. virtual String getDefaultToolset() const { return "v110"; }
  1247. static MSVCProjectExporterVC2012* createForSettings (Project& project, const ValueTree& settings)
  1248. {
  1249. if (settings.hasType (getValueTreeTypeName()))
  1250. return new MSVCProjectExporterVC2012 (project, settings);
  1251. return nullptr;
  1252. }
  1253. void createExporterProperties (PropertyListBuilder& props) override
  1254. {
  1255. MSVCProjectExporterBase::createExporterProperties (props);
  1256. static const char* toolsetNames[] = { "(default)", "v110", "v110_xp", "Windows7.1SDK", "CTP_Nov2013", nullptr };
  1257. const var toolsets[] = { var(), "v110", "v110_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1258. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1259. StringArray (toolsetNames),
  1260. Array<var> (toolsets, numElementsInArray (toolsets))));
  1261. }
  1262. private:
  1263. void addPlatformToolsetToPropertyGroup (XmlElement& p) const override
  1264. {
  1265. forEachXmlChildElementWithTagName (p, e, "PropertyGroup")
  1266. {
  1267. XmlElement* platformToolset (new XmlElement ("PlatformToolset"));
  1268. platformToolset->addTextElement (getPlatformToolset());
  1269. e->addChildElement (platformToolset);
  1270. }
  1271. }
  1272. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2012)
  1273. };
  1274. //==============================================================================
  1275. class MSVCProjectExporterVC2013 : public MSVCProjectExporterVC2012
  1276. {
  1277. public:
  1278. MSVCProjectExporterVC2013 (Project& p, const ValueTree& t)
  1279. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2013")
  1280. {
  1281. name = getName();
  1282. }
  1283. static const char* getName() { return "Visual Studio 2013"; }
  1284. static const char* getValueTreeTypeName() { return "VS2013"; }
  1285. int getVisualStudioVersion() const override { return 12; }
  1286. String getSolutionComment() const override { return "# Visual Studio 2013"; }
  1287. String getToolsVersion() const override { return "12.0"; }
  1288. String getDefaultToolset() const override { return "v120"; }
  1289. static MSVCProjectExporterVC2013* createForSettings (Project& project, const ValueTree& settings)
  1290. {
  1291. if (settings.hasType (getValueTreeTypeName()))
  1292. return new MSVCProjectExporterVC2013 (project, settings);
  1293. return nullptr;
  1294. }
  1295. void createExporterProperties (PropertyListBuilder& props) override
  1296. {
  1297. MSVCProjectExporterBase::createExporterProperties (props);
  1298. static const char* toolsetNames[] = { "(default)", "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013", nullptr };
  1299. const var toolsets[] = { var(), "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1300. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1301. StringArray (toolsetNames),
  1302. Array<var> (toolsets, numElementsInArray (toolsets))));
  1303. }
  1304. private:
  1305. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2013)
  1306. };
  1307. //==============================================================================
  1308. class MSVCProjectExporterVC2015 : public MSVCProjectExporterVC2012
  1309. {
  1310. public:
  1311. MSVCProjectExporterVC2015 (Project& p, const ValueTree& t)
  1312. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2015")
  1313. {
  1314. name = getName();
  1315. }
  1316. static const char* getName() { return "Visual Studio 2015"; }
  1317. static const char* getValueTreeTypeName() { return "VS2015"; }
  1318. int getVisualStudioVersion() const override { return 14; }
  1319. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1320. String getToolsVersion() const override { return "14.0"; }
  1321. String getDefaultToolset() const override { return "v140"; }
  1322. static MSVCProjectExporterVC2015* createForSettings (Project& project, const ValueTree& settings)
  1323. {
  1324. if (settings.hasType (getValueTreeTypeName()))
  1325. return new MSVCProjectExporterVC2015 (project, settings);
  1326. return nullptr;
  1327. }
  1328. void createExporterProperties (PropertyListBuilder& props) override
  1329. {
  1330. MSVCProjectExporterBase::createExporterProperties (props);
  1331. static const char* toolsetNames[] = { "(default)", "v140", "v140_xp", nullptr };
  1332. const var toolsets[] = { var(), "v140", "v140_xp" };
  1333. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1334. StringArray (toolsetNames),
  1335. Array<var> (toolsets, numElementsInArray (toolsets))));
  1336. }
  1337. private:
  1338. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1339. };