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.

1671 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. searchPaths.removeDuplicates (false);
  227. return searchPaths;
  228. }
  229. virtual String createConfigName (const BuildConfiguration& config) const
  230. {
  231. return config.getName() + "|Win32";
  232. }
  233. //==============================================================================
  234. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString, const File& vcProject) const
  235. {
  236. if (commentString.isNotEmpty())
  237. commentString += newLine;
  238. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  239. << commentString
  240. << "Project(\"" << createGUID (projectName + "sln_guid") << "\") = \"" << projectName << "\", \""
  241. << vcProject.getFileName() << "\", \"" << projectGUID << '"' << newLine
  242. << "EndProject" << newLine
  243. << "Global" << newLine
  244. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  245. for (ConstConfigIterator i (*this); i.next();)
  246. {
  247. const String configName (createConfigName (*i));
  248. out << "\t\t" << configName << " = " << configName << newLine;
  249. }
  250. out << "\tEndGlobalSection" << newLine
  251. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  252. for (ConstConfigIterator i (*this); i.next();)
  253. {
  254. const String configName (createConfigName (*i));
  255. out << "\t\t" << projectGUID << "." << configName << ".ActiveCfg = " << configName << newLine;
  256. out << "\t\t" << projectGUID << "." << configName << ".Build.0 = " << configName << newLine;
  257. }
  258. out << "\tEndGlobalSection" << newLine
  259. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  260. << "\t\tHideSolutionNode = FALSE" << newLine
  261. << "\tEndGlobalSection" << newLine
  262. << "EndGlobal" << newLine;
  263. }
  264. //==============================================================================
  265. static void writeBMPImage (const Image& image, const int w, const int h, MemoryOutputStream& out)
  266. {
  267. const int maskStride = (w / 8 + 3) & ~3;
  268. out.writeInt (40); // bitmapinfoheader size
  269. out.writeInt (w);
  270. out.writeInt (h * 2);
  271. out.writeShort (1); // planes
  272. out.writeShort (32); // bits
  273. out.writeInt (0); // compression
  274. out.writeInt ((h * w * 4) + (h * maskStride)); // size image
  275. out.writeInt (0); // x pixels per meter
  276. out.writeInt (0); // y pixels per meter
  277. out.writeInt (0); // clr used
  278. out.writeInt (0); // clr important
  279. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  280. const int alphaThreshold = 5;
  281. int y;
  282. for (y = h; --y >= 0;)
  283. {
  284. for (int x = 0; x < w; ++x)
  285. {
  286. const Colour pixel (bitmap.getPixelColour (x, y));
  287. if (pixel.getAlpha() <= alphaThreshold)
  288. {
  289. out.writeInt (0);
  290. }
  291. else
  292. {
  293. out.writeByte ((char) pixel.getBlue());
  294. out.writeByte ((char) pixel.getGreen());
  295. out.writeByte ((char) pixel.getRed());
  296. out.writeByte ((char) pixel.getAlpha());
  297. }
  298. }
  299. }
  300. for (y = h; --y >= 0;)
  301. {
  302. int mask = 0, count = 0;
  303. for (int x = 0; x < w; ++x)
  304. {
  305. const Colour pixel (bitmap.getPixelColour (x, y));
  306. mask <<= 1;
  307. if (pixel.getAlpha() <= alphaThreshold)
  308. mask |= 1;
  309. if (++count == 8)
  310. {
  311. out.writeByte ((char) mask);
  312. count = 0;
  313. mask = 0;
  314. }
  315. }
  316. if (mask != 0)
  317. out.writeByte ((char) mask);
  318. for (int i = maskStride - w / 8; --i >= 0;)
  319. out.writeByte (0);
  320. }
  321. }
  322. static void writeIconFile (const Array<Image>& images, MemoryOutputStream& out)
  323. {
  324. out.writeShort (0); // reserved
  325. out.writeShort (1); // .ico tag
  326. out.writeShort ((short) images.size());
  327. MemoryOutputStream dataBlock;
  328. const int imageDirEntrySize = 16;
  329. const int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  330. for (int i = 0; i < images.size(); ++i)
  331. {
  332. const size_t oldDataSize = dataBlock.getDataSize();
  333. const Image& image = images.getReference (i);
  334. const int w = image.getWidth();
  335. const int h = image.getHeight();
  336. if (w >= 256 || h >= 256)
  337. {
  338. PNGImageFormat pngFormat;
  339. pngFormat.writeImageToStream (image, dataBlock);
  340. }
  341. else
  342. {
  343. writeBMPImage (image, w, h, dataBlock);
  344. }
  345. out.writeByte ((char) w);
  346. out.writeByte ((char) h);
  347. out.writeByte (0);
  348. out.writeByte (0);
  349. out.writeShort (1); // colour planes
  350. out.writeShort (32); // bits per pixel
  351. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  352. out.writeInt (dataBlockStart + (int) oldDataSize);
  353. }
  354. jassert (out.getPosition() == dataBlockStart);
  355. out << dataBlock;
  356. }
  357. bool hasResourceFile() const
  358. {
  359. return ! projectType.isStaticLibrary();
  360. }
  361. void createResourcesAndIcon() const
  362. {
  363. if (hasResourceFile())
  364. {
  365. Array<Image> images;
  366. const int sizes[] = { 16, 32, 48, 256 };
  367. for (int i = 0; i < numElementsInArray (sizes); ++i)
  368. {
  369. Image im (getBestIconForSize (sizes[i], true));
  370. if (im.isValid())
  371. images.add (im);
  372. }
  373. if (images.size() > 0)
  374. {
  375. iconFile = getTargetFolder().getChildFile ("icon.ico");
  376. MemoryOutputStream mo;
  377. writeIconFile (images, mo);
  378. overwriteFileIfDifferentOrThrow (iconFile, mo);
  379. }
  380. createRCFile();
  381. }
  382. }
  383. void createRCFile() const
  384. {
  385. rcFile = getTargetFolder().getChildFile ("resources.rc");
  386. const String version (project.getVersionString());
  387. MemoryOutputStream mo;
  388. mo << "#ifdef JUCE_USER_DEFINED_RC_FILE" << newLine
  389. << " #include JUCE_USER_DEFINED_RC_FILE" << newLine
  390. << "#else" << newLine
  391. << newLine
  392. << "#undef WIN32_LEAN_AND_MEAN" << newLine
  393. << "#define WIN32_LEAN_AND_MEAN" << newLine
  394. << "#include <windows.h>" << newLine
  395. << newLine
  396. << "VS_VERSION_INFO VERSIONINFO" << newLine
  397. << "FILEVERSION " << getCommaSeparatedVersionNumber (version) << newLine
  398. << "BEGIN" << newLine
  399. << " BLOCK \"StringFileInfo\"" << newLine
  400. << " BEGIN" << newLine
  401. << " BLOCK \"040904E4\"" << newLine
  402. << " BEGIN" << newLine;
  403. writeRCValue (mo, "CompanyName", project.getCompanyName().toString());
  404. writeRCValue (mo, "FileDescription", project.getTitle());
  405. writeRCValue (mo, "FileVersion", version);
  406. writeRCValue (mo, "ProductName", project.getTitle());
  407. writeRCValue (mo, "ProductVersion", version);
  408. mo << " END" << newLine
  409. << " END" << newLine
  410. << newLine
  411. << " BLOCK \"VarFileInfo\"" << newLine
  412. << " BEGIN" << newLine
  413. << " VALUE \"Translation\", 0x409, 65001" << newLine
  414. << " END" << newLine
  415. << "END" << newLine
  416. << newLine
  417. << "#endif" << newLine;
  418. if (iconFile != File::nonexistent)
  419. mo << newLine
  420. << "IDI_ICON1 ICON DISCARDABLE " << iconFile.getFileName().quoted()
  421. << newLine
  422. << "IDI_ICON2 ICON DISCARDABLE " << iconFile.getFileName().quoted();
  423. overwriteFileIfDifferentOrThrow (rcFile, mo);
  424. }
  425. static void writeRCValue (MemoryOutputStream& mo, const String& name, const String& value)
  426. {
  427. if (value.isNotEmpty())
  428. mo << " VALUE \"" << name << "\", \""
  429. << CppTokeniserFunctions::addEscapeChars (value) << "\\0\"" << newLine;
  430. }
  431. static String getCommaSeparatedVersionNumber (const String& version)
  432. {
  433. StringArray versionParts;
  434. versionParts.addTokens (version, ",.", "");
  435. versionParts.trim();
  436. versionParts.removeEmptyStrings();
  437. while (versionParts.size() < 4)
  438. versionParts.add ("0");
  439. return versionParts.joinIntoString (",");
  440. }
  441. static String prependDot (const String& filename)
  442. {
  443. return FileHelpers::isAbsolutePath (filename) ? filename
  444. : (".\\" + filename);
  445. }
  446. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase)
  447. };
  448. //==============================================================================
  449. class MSVCProjectExporterVC2008 : public MSVCProjectExporterBase
  450. {
  451. public:
  452. //==============================================================================
  453. MSVCProjectExporterVC2008 (Project& p, const ValueTree& s,
  454. const char* folderName = "VisualStudio2008")
  455. : MSVCProjectExporterBase (p, s, folderName)
  456. {
  457. name = getName();
  458. }
  459. static const char* getName() { return "Visual Studio 2008"; }
  460. static const char* getValueTreeTypeName() { return "VS2008"; }
  461. int getVisualStudioVersion() const override { return 9; }
  462. static MSVCProjectExporterVC2008* createForSettings (Project& project, const ValueTree& settings)
  463. {
  464. if (settings.hasType (getValueTreeTypeName()))
  465. return new MSVCProjectExporterVC2008 (project, settings);
  466. return nullptr;
  467. }
  468. //==============================================================================
  469. void create (const OwnedArray<LibraryModule>&) const
  470. {
  471. createResourcesAndIcon();
  472. if (hasResourceFile())
  473. {
  474. for (int i = 0; i < getAllGroups().size(); ++i)
  475. {
  476. Project::Item& group = getAllGroups().getReference(i);
  477. if (group.getID() == ProjectSaver::getGeneratedGroupID())
  478. {
  479. if (iconFile != File::nonexistent)
  480. {
  481. group.addFile (iconFile, -1, true);
  482. group.findItemForFile (iconFile).getShouldAddToResourceValue() = false;
  483. }
  484. group.addFile (rcFile, -1, true);
  485. group.findItemForFile (rcFile).getShouldAddToResourceValue() = false;
  486. break;
  487. }
  488. }
  489. }
  490. {
  491. XmlElement projectXml ("VisualStudioProject");
  492. fillInProjectXml (projectXml);
  493. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  494. }
  495. {
  496. MemoryOutputStream mo;
  497. writeSolutionFile (mo, getSolutionVersionString(), String::empty, getVCProjFile());
  498. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  499. }
  500. }
  501. protected:
  502. virtual String getProjectVersionString() const { return "9.00"; }
  503. virtual String getSolutionVersionString() const { return String ("10.00") + newLine + "# Visual C++ Express 2008"; }
  504. File getVCProjFile() const { return getProjectFile (".vcproj"); }
  505. //==============================================================================
  506. void fillInProjectXml (XmlElement& projectXml) const
  507. {
  508. projectXml.setAttribute ("ProjectType", "Visual C++");
  509. projectXml.setAttribute ("Version", getProjectVersionString());
  510. projectXml.setAttribute ("Name", projectName);
  511. projectXml.setAttribute ("ProjectGUID", projectGUID);
  512. projectXml.setAttribute ("TargetFrameworkVersion", "131072");
  513. {
  514. XmlElement* platforms = projectXml.createNewChildElement ("Platforms");
  515. XmlElement* platform = platforms->createNewChildElement ("Platform");
  516. platform->setAttribute ("Name", "Win32");
  517. }
  518. projectXml.createNewChildElement ("ToolFiles");
  519. createConfigs (*projectXml.createNewChildElement ("Configurations"));
  520. projectXml.createNewChildElement ("References");
  521. createFiles (*projectXml.createNewChildElement ("Files"));
  522. projectXml.createNewChildElement ("Globals");
  523. }
  524. //==============================================================================
  525. void addFile (const RelativePath& file, XmlElement& parent, const bool excludeFromBuild, const bool useStdcall) const
  526. {
  527. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  528. XmlElement* fileXml = parent.createNewChildElement ("File");
  529. fileXml->setAttribute ("RelativePath", file.toWindowsStyle());
  530. if (excludeFromBuild || useStdcall)
  531. {
  532. for (ConstConfigIterator i (*this); i.next();)
  533. {
  534. XmlElement* fileConfig = fileXml->createNewChildElement ("FileConfiguration");
  535. fileConfig->setAttribute ("Name", createConfigName (*i));
  536. if (excludeFromBuild)
  537. fileConfig->setAttribute ("ExcludedFromBuild", "true");
  538. XmlElement* tool = createToolElement (*fileConfig, "VCCLCompilerTool");
  539. if (useStdcall)
  540. tool->setAttribute ("CallingConvention", "2");
  541. }
  542. }
  543. }
  544. XmlElement* createGroup (const String& groupName, XmlElement& parent) const
  545. {
  546. XmlElement* filter = parent.createNewChildElement ("Filter");
  547. filter->setAttribute ("Name", groupName);
  548. return filter;
  549. }
  550. void addFiles (const Project::Item& projectItem, XmlElement& parent) const
  551. {
  552. if (projectItem.isGroup())
  553. {
  554. XmlElement* filter = createGroup (projectItem.getName(), parent);
  555. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  556. addFiles (projectItem.getChild(i), *filter);
  557. }
  558. else if (projectItem.shouldBeAddedToTargetProject())
  559. {
  560. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  561. addFile (path, parent,
  562. projectItem.shouldBeAddedToBinaryResources()
  563. || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()),
  564. shouldFileBeCompiledByDefault (path) && (bool) projectItem.shouldUseStdCall());
  565. }
  566. }
  567. void createFiles (XmlElement& files) const
  568. {
  569. for (int i = 0; i < getAllGroups().size(); ++i)
  570. {
  571. const Project::Item& group = getAllGroups().getReference(i);
  572. if (group.getNumChildren() > 0)
  573. addFiles (group, files);
  574. }
  575. }
  576. //==============================================================================
  577. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  578. {
  579. XmlElement* const e = parent.createNewChildElement ("Tool");
  580. e->setAttribute ("Name", toolName);
  581. return e;
  582. }
  583. void createConfig (XmlElement& xml, const MSVCBuildConfiguration& config) const
  584. {
  585. const bool isDebug = config.isDebug();
  586. xml.setAttribute ("Name", createConfigName (config));
  587. if (getConfigTargetPath (config).isNotEmpty())
  588. xml.setAttribute ("OutputDirectory", FileHelpers::windowsStylePath (getConfigTargetPath (config)));
  589. if (config.getIntermediatesPath().isNotEmpty())
  590. xml.setAttribute ("IntermediateDirectory", FileHelpers::windowsStylePath (config.getIntermediatesPath()));
  591. xml.setAttribute ("ConfigurationType", isLibraryDLL() ? "2" : (projectType.isStaticLibrary() ? "4" : "1"));
  592. xml.setAttribute ("UseOfMFC", "0");
  593. xml.setAttribute ("ATLMinimizesCRunTimeLibraryUsage", "false");
  594. xml.setAttribute ("CharacterSet", "2");
  595. if (! (isDebug || config.shouldDisableWholeProgramOpt()))
  596. xml.setAttribute ("WholeProgramOptimization", "1");
  597. XmlElement* preBuildEvent = createToolElement (xml, "VCPreBuildEventTool");
  598. if (config.getPrebuildCommandString().isNotEmpty())
  599. {
  600. preBuildEvent->setAttribute ("Description", "Pre-build");
  601. preBuildEvent->setAttribute ("CommandLine", config.getPrebuildCommandString());
  602. }
  603. createToolElement (xml, "VCCustomBuildTool");
  604. createToolElement (xml, "VCXMLDataGeneratorTool");
  605. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  606. if (! projectType.isStaticLibrary())
  607. {
  608. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  609. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  610. midl->setAttribute ("MkTypLibCompatible", "true");
  611. midl->setAttribute ("SuppressStartupBanner", "true");
  612. midl->setAttribute ("TargetEnvironment", "1");
  613. midl->setAttribute ("TypeLibraryName", getIntDirFile (config, config.getOutputFilename (".tlb", true)));
  614. midl->setAttribute ("HeaderFileName", "");
  615. }
  616. {
  617. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  618. compiler->setAttribute ("Optimization", getOptimisationLevelString (config.getOptimisationLevelInt()));
  619. if (isDebug)
  620. {
  621. compiler->setAttribute ("BufferSecurityCheck", "");
  622. compiler->setAttribute ("DebugInformationFormat", projectType.isStaticLibrary() ? "3" : "4");
  623. }
  624. else
  625. {
  626. compiler->setAttribute ("InlineFunctionExpansion", "1");
  627. compiler->setAttribute ("StringPooling", "true");
  628. }
  629. compiler->setAttribute ("AdditionalIncludeDirectories", replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (";")));
  630. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  631. compiler->setAttribute ("RuntimeLibrary", config.isUsingRuntimeLibDLL() ? (isDebug ? 3 : 2) // MT DLL
  632. : (isDebug ? 1 : 0)); // MT static
  633. compiler->setAttribute ("RuntimeTypeInfo", "true");
  634. compiler->setAttribute ("UsePrecompiledHeader", "0");
  635. compiler->setAttribute ("PrecompiledHeaderFile", getIntDirFile (config, config.getOutputFilename (".pch", true)));
  636. compiler->setAttribute ("AssemblerListingLocation", "$(IntDir)\\");
  637. compiler->setAttribute ("ObjectFile", "$(IntDir)\\");
  638. compiler->setAttribute ("ProgramDataBaseFileName", "$(IntDir)\\");
  639. compiler->setAttribute ("WarningLevel", String (config.getWarningLevel()));
  640. compiler->setAttribute ("SuppressStartupBanner", "true");
  641. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  642. if (extraFlags.isNotEmpty())
  643. compiler->setAttribute ("AdditionalOptions", extraFlags);
  644. }
  645. createToolElement (xml, "VCManagedResourceCompilerTool");
  646. {
  647. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  648. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  649. }
  650. createToolElement (xml, "VCPreLinkEventTool");
  651. if (! projectType.isStaticLibrary())
  652. {
  653. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  654. linker->setAttribute ("OutputFile", getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  655. linker->setAttribute ("SuppressStartupBanner", "true");
  656. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  657. linker->setAttribute ("GenerateDebugInformation", (isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  658. linker->setAttribute ("ProgramDatabaseFile", getIntDirFile (config, config.getOutputFilename (".pdb", true)));
  659. linker->setAttribute ("SubSystem", msvcIsWindowsSubsystem ? "2" : "1");
  660. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  661. if (librarySearchPaths.size() > 0)
  662. linker->setAttribute ("AdditionalLibraryDirectories", librarySearchPaths.joinIntoString (";"));
  663. linker->setAttribute ("GenerateManifest", config.shouldGenerateManifest() ? "true" : "false");
  664. if (! isDebug)
  665. {
  666. linker->setAttribute ("OptimizeReferences", "2");
  667. linker->setAttribute ("EnableCOMDATFolding", "2");
  668. }
  669. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  670. if (msvcDelayLoadedDLLs.isNotEmpty())
  671. linker->setAttribute ("DelayLoadDLLs", msvcDelayLoadedDLLs);
  672. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  673. linker->setAttribute ("ModuleDefinitionFile", config.config [Ids::msvcModuleDefinitionFile].toString());
  674. String externalLibraries (getExternalLibrariesString());
  675. if (externalLibraries.isNotEmpty())
  676. linker->setAttribute ("AdditionalDependencies", replacePreprocessorTokens (config, externalLibraries).trim());
  677. String extraLinkerOptions (getExtraLinkerFlagsString());
  678. if (extraLinkerOptions.isNotEmpty())
  679. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  680. }
  681. else
  682. {
  683. if (isLibraryDLL())
  684. {
  685. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  686. String extraLinkerOptions (getExtraLinkerFlagsString());
  687. extraLinkerOptions << " /IMPLIB:" << getOutDirFile (config, config.getOutputFilename (".lib", true));
  688. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  689. String externalLibraries (getExternalLibrariesString());
  690. if (externalLibraries.isNotEmpty())
  691. linker->setAttribute ("AdditionalDependencies", replacePreprocessorTokens (config, externalLibraries).trim());
  692. linker->setAttribute ("OutputFile", getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  693. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  694. }
  695. else
  696. {
  697. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  698. librarian->setAttribute ("OutputFile", getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  699. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  700. }
  701. }
  702. createToolElement (xml, "VCALinkTool");
  703. createToolElement (xml, "VCManifestTool");
  704. createToolElement (xml, "VCXDCMakeTool");
  705. {
  706. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  707. bscMake->setAttribute ("SuppressStartupBanner", "true");
  708. bscMake->setAttribute ("OutputFile", getIntDirFile (config, config.getOutputFilename (".bsc", true)));
  709. }
  710. createToolElement (xml, "VCFxCopTool");
  711. if (! projectType.isStaticLibrary())
  712. createToolElement (xml, "VCAppVerifierTool");
  713. XmlElement* postBuildEvent = createToolElement (xml, "VCPostBuildEventTool");
  714. if (config.getPostbuildCommandString().isNotEmpty())
  715. {
  716. postBuildEvent->setAttribute ("Description", "Post-build");
  717. postBuildEvent->setAttribute ("CommandLine", config.getPostbuildCommandString());
  718. }
  719. }
  720. void createConfigs (XmlElement& xml) const
  721. {
  722. for (ConstConfigIterator config (*this); config.next();)
  723. createConfig (*xml.createNewChildElement ("Configuration"),
  724. dynamic_cast<const MSVCBuildConfiguration&> (*config));
  725. }
  726. static const char* getOptimisationLevelString (int level)
  727. {
  728. switch (level)
  729. {
  730. case optimiseMaxSpeed: return "3";
  731. case optimiseMinSize: return "1";
  732. default: return "0";
  733. }
  734. }
  735. //==============================================================================
  736. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008)
  737. };
  738. //==============================================================================
  739. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  740. {
  741. public:
  742. MSVCProjectExporterVC2005 (Project& p, const ValueTree& t)
  743. : MSVCProjectExporterVC2008 (p, t, "VisualStudio2005")
  744. {
  745. name = getName();
  746. }
  747. static const char* getName() { return "Visual Studio 2005"; }
  748. static const char* getValueTreeTypeName() { return "VS2005"; }
  749. int getVisualStudioVersion() const override { return 8; }
  750. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  751. {
  752. if (settings.hasType (getValueTreeTypeName()))
  753. return new MSVCProjectExporterVC2005 (project, settings);
  754. return nullptr;
  755. }
  756. protected:
  757. String getProjectVersionString() const { return "8.00"; }
  758. String getSolutionVersionString() const { return String ("9.00") + newLine + "# Visual C++ Express 2005"; }
  759. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005)
  760. };
  761. //==============================================================================
  762. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  763. {
  764. public:
  765. MSVCProjectExporterVC2010 (Project& p, const ValueTree& t, const char* folderName = "VisualStudio2010")
  766. : MSVCProjectExporterBase (p, t, folderName)
  767. {
  768. name = getName();
  769. }
  770. static const char* getName() { return "Visual Studio 2010"; }
  771. static const char* getValueTreeTypeName() { return "VS2010"; }
  772. int getVisualStudioVersion() const override { return 10; }
  773. virtual String getSolutionComment() const { return "# Visual Studio 2010"; }
  774. virtual String getToolsVersion() const { return "4.0"; }
  775. virtual String getDefaultToolset() const { return "Windows7.1SDK"; }
  776. Value getPlatformToolsetValue() { return getSetting (Ids::toolset); }
  777. String getPlatformToolset() const
  778. {
  779. const String s (settings [Ids::toolset].toString());
  780. return s.isNotEmpty() ? s : getDefaultToolset();
  781. }
  782. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  783. {
  784. if (settings.hasType (getValueTreeTypeName()))
  785. return new MSVCProjectExporterVC2010 (project, settings);
  786. return nullptr;
  787. }
  788. void createExporterProperties (PropertyListBuilder& props) override
  789. {
  790. MSVCProjectExporterBase::createExporterProperties (props);
  791. static const char* toolsetNames[] = { "(default)", "v100", "v100_xp", "Windows7.1SDK", "CTP_Nov2013", nullptr };
  792. const var toolsets[] = { var(), "v100", "v100_xp", "Windows7.1SDK", "CTP_Nov2013" };
  793. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  794. StringArray (toolsetNames),
  795. Array<var> (toolsets, numElementsInArray (toolsets))));
  796. }
  797. //==============================================================================
  798. void create (const OwnedArray<LibraryModule>&) const
  799. {
  800. createResourcesAndIcon();
  801. {
  802. XmlElement projectXml ("Project");
  803. fillInProjectXml (projectXml);
  804. addPlatformToolsetToPropertyGroup (projectXml);
  805. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  806. }
  807. {
  808. XmlElement filtersXml ("Project");
  809. fillInFiltersXml (filtersXml);
  810. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  811. }
  812. {
  813. MemoryOutputStream mo;
  814. writeSolutionFile (mo, "11.00", getSolutionComment(), getVCProjFile());
  815. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  816. }
  817. }
  818. protected:
  819. //==============================================================================
  820. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  821. {
  822. public:
  823. VC2010BuildConfiguration (Project& p, const ValueTree& settings)
  824. : MSVCBuildConfiguration (p, settings)
  825. {
  826. if (getArchitectureType().toString().isEmpty())
  827. getArchitectureType() = get32BitArchName();
  828. }
  829. //==============================================================================
  830. static const char* get32BitArchName() { return "32-bit"; }
  831. static const char* get64BitArchName() { return "x64"; }
  832. Value getArchitectureType() { return getValue (Ids::winArchitecture); }
  833. bool is64Bit() const { return config [Ids::winArchitecture].toString() == get64BitArchName(); }
  834. Value getFastMathValue() { return getValue (Ids::fastMath); }
  835. bool isFastMathEnabled() const { return config [Ids::fastMath]; }
  836. //==============================================================================
  837. void createConfigProperties (PropertyListBuilder& props) override
  838. {
  839. MSVCBuildConfiguration::createConfigProperties (props);
  840. const char* const archTypes[] = { get32BitArchName(), get64BitArchName() };
  841. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  842. StringArray (archTypes, numElementsInArray (archTypes)),
  843. Array<var> (archTypes, numElementsInArray (archTypes))));
  844. props.add (new BooleanPropertyComponent (getFastMathValue(), "Relax IEEE compliance", "Enabled"),
  845. "Enable this to use FAST_MATH non-IEEE mode. (Warning: this can have unexpected results!)");
  846. }
  847. };
  848. virtual void addPlatformToolsetToPropertyGroup (XmlElement&) const {}
  849. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const
  850. {
  851. return new VC2010BuildConfiguration (project, v);
  852. }
  853. static bool is64Bit (const BuildConfiguration& config)
  854. {
  855. return dynamic_cast<const VC2010BuildConfiguration&> (config).is64Bit();
  856. }
  857. //==============================================================================
  858. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  859. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  860. String createConfigName (const BuildConfiguration& config) const
  861. {
  862. return config.getName() + (is64Bit (config) ? "|x64"
  863. : "|Win32");
  864. }
  865. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  866. {
  867. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  868. }
  869. //==============================================================================
  870. void fillInProjectXml (XmlElement& projectXml) const
  871. {
  872. projectXml.setAttribute ("DefaultTargets", "Build");
  873. projectXml.setAttribute ("ToolsVersion", getToolsVersion());
  874. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  875. {
  876. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  877. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  878. for (ConstConfigIterator config (*this); config.next();)
  879. {
  880. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  881. e->setAttribute ("Include", createConfigName (*config));
  882. e->createNewChildElement ("Configuration")->addTextElement (config->getName());
  883. e->createNewChildElement ("Platform")->addTextElement (is64Bit (*config) ? "x64" : "Win32");
  884. }
  885. }
  886. {
  887. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  888. globals->setAttribute ("Label", "Globals");
  889. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  890. }
  891. {
  892. XmlElement* imports = projectXml.createNewChildElement ("Import");
  893. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  894. }
  895. for (ConstConfigIterator i (*this); i.next();)
  896. {
  897. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  898. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  899. setConditionAttribute (*e, config);
  900. e->setAttribute ("Label", "Configuration");
  901. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  902. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  903. const String charSet (config.getCharacterSet());
  904. if (charSet.isNotEmpty())
  905. e->createNewChildElement ("CharacterSet")->addTextElement (charSet);
  906. if (! (config.isDebug() || config.shouldDisableWholeProgramOpt()))
  907. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  908. if (config.is64Bit())
  909. e->createNewChildElement ("PlatformToolset")->addTextElement (getPlatformToolset());
  910. }
  911. {
  912. XmlElement* e = projectXml.createNewChildElement ("Import");
  913. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  914. }
  915. {
  916. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  917. e->setAttribute ("Label", "ExtensionSettings");
  918. }
  919. {
  920. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  921. e->setAttribute ("Label", "PropertySheets");
  922. XmlElement* p = e->createNewChildElement ("Import");
  923. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  924. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  925. p->setAttribute ("Label", "LocalAppDataPlatform");
  926. }
  927. {
  928. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  929. e->setAttribute ("Label", "UserMacros");
  930. }
  931. {
  932. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  933. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  934. for (ConstConfigIterator i (*this); i.next();)
  935. {
  936. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  937. if (getConfigTargetPath (config).isNotEmpty())
  938. {
  939. XmlElement* outdir = props->createNewChildElement ("OutDir");
  940. setConditionAttribute (*outdir, config);
  941. outdir->addTextElement (FileHelpers::windowsStylePath (getConfigTargetPath (config)) + "\\");
  942. }
  943. if (config.getIntermediatesPath().isNotEmpty())
  944. {
  945. XmlElement* intdir = props->createNewChildElement ("IntDir");
  946. setConditionAttribute (*intdir, config);
  947. intdir->addTextElement (FileHelpers::windowsStylePath (config.getIntermediatesPath()) + "\\");
  948. }
  949. {
  950. XmlElement* targetName = props->createNewChildElement ("TargetName");
  951. setConditionAttribute (*targetName, config);
  952. targetName->addTextElement (config.getOutputFilename (String::empty, true));
  953. }
  954. {
  955. XmlElement* manifest = props->createNewChildElement ("GenerateManifest");
  956. setConditionAttribute (*manifest, config);
  957. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  958. }
  959. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  960. if (librarySearchPaths.size() > 0)
  961. {
  962. XmlElement* libPath = props->createNewChildElement ("LibraryPath");
  963. setConditionAttribute (*libPath, config);
  964. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  965. }
  966. }
  967. }
  968. for (ConstConfigIterator i (*this); i.next();)
  969. {
  970. const VC2010BuildConfiguration& config = dynamic_cast<const VC2010BuildConfiguration&> (*i);
  971. const bool isDebug = config.isDebug();
  972. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  973. setConditionAttribute (*group, config);
  974. {
  975. XmlElement* midl = group->createNewChildElement ("Midl");
  976. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  977. : "NDEBUG;%(PreprocessorDefinitions)");
  978. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  979. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  980. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  981. midl->createNewChildElement ("HeaderFileName");
  982. }
  983. bool isUsingEditAndContinue = false;
  984. {
  985. XmlElement* cl = group->createNewChildElement ("ClCompile");
  986. cl->createNewChildElement ("Optimization")->addTextElement (getOptimisationLevelString (config.getOptimisationLevelInt()));
  987. if (isDebug && config.getOptimisationLevelInt() <= optimisationOff)
  988. {
  989. isUsingEditAndContinue = ! config.is64Bit();
  990. cl->createNewChildElement ("DebugInformationFormat")
  991. ->addTextElement (isUsingEditAndContinue ? "EditAndContinue"
  992. : "ProgramDatabase");
  993. }
  994. StringArray includePaths (getHeaderSearchPaths (config));
  995. includePaths.add ("%(AdditionalIncludeDirectories)");
  996. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  997. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  998. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (config.isUsingRuntimeLibDLL() ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  999. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  1000. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  1001. cl->createNewChildElement ("PrecompiledHeader");
  1002. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  1003. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  1004. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement ("$(IntDir)\\");
  1005. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (config.getWarningLevel()));
  1006. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1007. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  1008. if (config.isFastMathEnabled())
  1009. cl->createNewChildElement ("FloatingPointModel")->addTextElement ("Fast");
  1010. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim());
  1011. if (extraFlags.isNotEmpty())
  1012. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  1013. if (config.areWarningsTreatedAsErrors())
  1014. cl->createNewChildElement ("TreatWarningAsError")->addTextElement ("true");
  1015. }
  1016. {
  1017. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  1018. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1019. : "NDEBUG;%(PreprocessorDefinitions)");
  1020. }
  1021. {
  1022. XmlElement* link = group->createNewChildElement ("Link");
  1023. link->createNewChildElement ("OutputFile")->addTextElement (getOutDirFile (config, config.getOutputFilename (msvcTargetSuffix, false)));
  1024. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1025. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  1026. : "%(IgnoreSpecificDefaultLibraries)");
  1027. link->createNewChildElement ("GenerateDebugInformation")->addTextElement ((isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  1028. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (getIntDirFile (config, config.getOutputFilename (".pdb", true)));
  1029. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  1030. if (! config.is64Bit())
  1031. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  1032. if (isUsingEditAndContinue)
  1033. link->createNewChildElement ("ImageHasSafeExceptionHandlers")->addTextElement ("false");
  1034. if (! isDebug)
  1035. {
  1036. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  1037. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  1038. }
  1039. const StringArray librarySearchPaths (config.getLibrarySearchPaths());
  1040. if (librarySearchPaths.size() > 0)
  1041. link->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (replacePreprocessorTokens (config, librarySearchPaths.joinIntoString (";"))
  1042. + ";%(AdditionalLibraryDirectories)");
  1043. link->createNewChildElement ("LargeAddressAware")->addTextElement ("true");
  1044. String externalLibraries (getExternalLibrariesString());
  1045. if (externalLibraries.isNotEmpty())
  1046. link->createNewChildElement ("AdditionalDependencies")->addTextElement (replacePreprocessorTokens (config, externalLibraries).trim()
  1047. + ";%(AdditionalDependencies)");
  1048. String extraLinkerOptions (getExtraLinkerFlagsString());
  1049. if (extraLinkerOptions.isNotEmpty())
  1050. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (config, extraLinkerOptions).trim()
  1051. + " %(AdditionalOptions)");
  1052. if (msvcDelayLoadedDLLs.isNotEmpty())
  1053. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (msvcDelayLoadedDLLs);
  1054. if (config.config [Ids::msvcModuleDefinitionFile].toString().isNotEmpty())
  1055. link->createNewChildElement ("ModuleDefinitionFile")
  1056. ->addTextElement (config.config [Ids::msvcModuleDefinitionFile].toString());
  1057. }
  1058. {
  1059. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  1060. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1061. bsc->createNewChildElement ("OutputFile")->addTextElement (getIntDirFile (config, config.getOutputFilename (".bsc", true)));
  1062. }
  1063. if (config.getPrebuildCommandString().isNotEmpty())
  1064. group->createNewChildElement ("PreBuildEvent")
  1065. ->createNewChildElement ("Command")
  1066. ->addTextElement (config.getPrebuildCommandString());
  1067. if (config.getPostbuildCommandString().isNotEmpty())
  1068. group->createNewChildElement ("PostBuildEvent")
  1069. ->createNewChildElement ("Command")
  1070. ->addTextElement (config.getPostbuildCommandString());
  1071. }
  1072. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1073. {
  1074. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1075. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1076. for (int i = 0; i < getAllGroups().size(); ++i)
  1077. {
  1078. const Project::Item& group = getAllGroups().getReference(i);
  1079. if (group.getNumChildren() > 0)
  1080. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  1081. }
  1082. }
  1083. if (iconFile != File::nonexistent)
  1084. {
  1085. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1086. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1087. }
  1088. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1089. projectXml.addChildElement (otherFilesGroup.release());
  1090. if (hasResourceFile())
  1091. {
  1092. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1093. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1094. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1095. }
  1096. {
  1097. XmlElement* e = projectXml.createNewChildElement ("Import");
  1098. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1099. }
  1100. {
  1101. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1102. e->setAttribute ("Label", "ExtensionTargets");
  1103. }
  1104. }
  1105. String getProjectType() const
  1106. {
  1107. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1108. if (isLibraryDLL()) return "DynamicLibrary";
  1109. if (projectType.isStaticLibrary()) return "StaticLibrary";
  1110. jassertfalse;
  1111. return String::empty;
  1112. }
  1113. static const char* getOptimisationLevelString (int level)
  1114. {
  1115. switch (level)
  1116. {
  1117. case optimiseMaxSpeed: return "Full";
  1118. case optimiseMinSize: return "MinSpace";
  1119. default: return "Disabled";
  1120. }
  1121. }
  1122. //==============================================================================
  1123. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1124. {
  1125. if (projectItem.isGroup())
  1126. {
  1127. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1128. addFilesToCompile (projectItem.getChild(i), cpps, headers, otherFiles);
  1129. }
  1130. else if (projectItem.shouldBeAddedToTargetProject())
  1131. {
  1132. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1133. jassert (path.getRoot() == RelativePath::buildTargetFolder);
  1134. if (path.hasFileExtension (cOrCppFileExtensions))
  1135. {
  1136. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1137. e->setAttribute ("Include", path.toWindowsStyle());
  1138. if (! projectItem.shouldBeCompiled())
  1139. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1140. if (projectItem.shouldUseStdCall())
  1141. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  1142. }
  1143. else if (path.hasFileExtension (headerFileExtensions))
  1144. {
  1145. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  1146. }
  1147. else if (! path.hasFileExtension (objCFileExtensions))
  1148. {
  1149. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  1150. }
  1151. }
  1152. }
  1153. //==============================================================================
  1154. void addFilterGroup (XmlElement& groups, const String& path) const
  1155. {
  1156. XmlElement* e = groups.createNewChildElement ("Filter");
  1157. e->setAttribute ("Include", path);
  1158. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1159. }
  1160. void addFileToFilter (const RelativePath& file, const String& groupPath,
  1161. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  1162. {
  1163. XmlElement* e;
  1164. if (file.hasFileExtension (headerFileExtensions))
  1165. e = headers.createNewChildElement ("ClInclude");
  1166. else if (file.hasFileExtension (sourceFileExtensions))
  1167. e = cpps.createNewChildElement ("ClCompile");
  1168. else
  1169. e = otherFiles.createNewChildElement ("None");
  1170. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1171. e->setAttribute ("Include", file.toWindowsStyle());
  1172. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1173. }
  1174. void addFilesToFilter (const Project::Item& projectItem, const String& path,
  1175. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  1176. {
  1177. if (projectItem.isGroup())
  1178. {
  1179. addFilterGroup (groups, path);
  1180. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1181. addFilesToFilter (projectItem.getChild(i),
  1182. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName(),
  1183. cpps, headers, otherFiles, groups);
  1184. }
  1185. else if (projectItem.shouldBeAddedToTargetProject())
  1186. {
  1187. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1188. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers, otherFiles);
  1189. }
  1190. }
  1191. void addFilesToFilter (const Array<RelativePath>& files, const String& path,
  1192. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups)
  1193. {
  1194. if (files.size() > 0)
  1195. {
  1196. addFilterGroup (groups, path);
  1197. for (int i = 0; i < files.size(); ++i)
  1198. addFileToFilter (files.getReference(i), path, cpps, headers, otherFiles);
  1199. }
  1200. }
  1201. void fillInFiltersXml (XmlElement& filterXml) const
  1202. {
  1203. filterXml.setAttribute ("ToolsVersion", getToolsVersion());
  1204. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1205. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1206. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1207. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1208. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  1209. for (int i = 0; i < getAllGroups().size(); ++i)
  1210. {
  1211. const Project::Item& group = getAllGroups().getReference(i);
  1212. if (group.getNumChildren() > 0)
  1213. addFilesToFilter (group, group.getName(), *cpps, *headers, *otherFilesGroup, *groupsXml);
  1214. }
  1215. if (iconFile.exists())
  1216. {
  1217. XmlElement* e = otherFilesGroup->createNewChildElement ("None");
  1218. e->setAttribute ("Include", prependDot (iconFile.getFileName()));
  1219. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1220. }
  1221. if (otherFilesGroup->getFirstChildElement() != nullptr)
  1222. filterXml.addChildElement (otherFilesGroup.release());
  1223. if (hasResourceFile())
  1224. {
  1225. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1226. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1227. e->setAttribute ("Include", prependDot (rcFile.getFileName()));
  1228. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1229. }
  1230. }
  1231. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010)
  1232. };
  1233. //==============================================================================
  1234. class MSVCProjectExporterVC2012 : public MSVCProjectExporterVC2010
  1235. {
  1236. public:
  1237. MSVCProjectExporterVC2012 (Project& p, const ValueTree& t,
  1238. const char* folderName = "VisualStudio2012")
  1239. : MSVCProjectExporterVC2010 (p, t, folderName)
  1240. {
  1241. name = getName();
  1242. }
  1243. static const char* getName() { return "Visual Studio 2012"; }
  1244. static const char* getValueTreeTypeName() { return "VS2012"; }
  1245. int getVisualStudioVersion() const override { return 11; }
  1246. String getSolutionComment() const override { return "# Visual Studio 2012"; }
  1247. virtual String getDefaultToolset() const { return "v110"; }
  1248. static MSVCProjectExporterVC2012* createForSettings (Project& project, const ValueTree& settings)
  1249. {
  1250. if (settings.hasType (getValueTreeTypeName()))
  1251. return new MSVCProjectExporterVC2012 (project, settings);
  1252. return nullptr;
  1253. }
  1254. void createExporterProperties (PropertyListBuilder& props) override
  1255. {
  1256. MSVCProjectExporterBase::createExporterProperties (props);
  1257. static const char* toolsetNames[] = { "(default)", "v110", "v110_xp", "Windows7.1SDK", "CTP_Nov2013", nullptr };
  1258. const var toolsets[] = { var(), "v110", "v110_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1259. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1260. StringArray (toolsetNames),
  1261. Array<var> (toolsets, numElementsInArray (toolsets))));
  1262. }
  1263. private:
  1264. void addPlatformToolsetToPropertyGroup (XmlElement& p) const override
  1265. {
  1266. forEachXmlChildElementWithTagName (p, e, "PropertyGroup")
  1267. {
  1268. XmlElement* platformToolset (new XmlElement ("PlatformToolset"));
  1269. platformToolset->addTextElement (getPlatformToolset());
  1270. e->addChildElement (platformToolset);
  1271. }
  1272. }
  1273. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2012)
  1274. };
  1275. //==============================================================================
  1276. class MSVCProjectExporterVC2013 : public MSVCProjectExporterVC2012
  1277. {
  1278. public:
  1279. MSVCProjectExporterVC2013 (Project& p, const ValueTree& t)
  1280. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2013")
  1281. {
  1282. name = getName();
  1283. }
  1284. static const char* getName() { return "Visual Studio 2013"; }
  1285. static const char* getValueTreeTypeName() { return "VS2013"; }
  1286. int getVisualStudioVersion() const override { return 12; }
  1287. String getSolutionComment() const override { return "# Visual Studio 2013"; }
  1288. String getToolsVersion() const override { return "12.0"; }
  1289. String getDefaultToolset() const override { return "v120"; }
  1290. static MSVCProjectExporterVC2013* createForSettings (Project& project, const ValueTree& settings)
  1291. {
  1292. if (settings.hasType (getValueTreeTypeName()))
  1293. return new MSVCProjectExporterVC2013 (project, settings);
  1294. return nullptr;
  1295. }
  1296. void createExporterProperties (PropertyListBuilder& props) override
  1297. {
  1298. MSVCProjectExporterBase::createExporterProperties (props);
  1299. static const char* toolsetNames[] = { "(default)", "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013", nullptr };
  1300. const var toolsets[] = { var(), "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1301. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1302. StringArray (toolsetNames),
  1303. Array<var> (toolsets, numElementsInArray (toolsets))));
  1304. }
  1305. private:
  1306. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2013)
  1307. };
  1308. //==============================================================================
  1309. class MSVCProjectExporterVC2015 : public MSVCProjectExporterVC2012
  1310. {
  1311. public:
  1312. MSVCProjectExporterVC2015 (Project& p, const ValueTree& t)
  1313. : MSVCProjectExporterVC2012 (p, t, "VisualStudio2015")
  1314. {
  1315. name = getName();
  1316. }
  1317. static const char* getName() { return "Visual Studio 2015"; }
  1318. static const char* getValueTreeTypeName() { return "VS2015"; }
  1319. int getVisualStudioVersion() const override { return 14; }
  1320. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1321. String getToolsVersion() const override { return "14.0"; }
  1322. String getDefaultToolset() const override { return "v140"; }
  1323. static MSVCProjectExporterVC2015* createForSettings (Project& project, const ValueTree& settings)
  1324. {
  1325. if (settings.hasType (getValueTreeTypeName()))
  1326. return new MSVCProjectExporterVC2015 (project, settings);
  1327. return nullptr;
  1328. }
  1329. void createExporterProperties (PropertyListBuilder& props) override
  1330. {
  1331. MSVCProjectExporterBase::createExporterProperties (props);
  1332. static const char* toolsetNames[] = { "(default)", "v140", "v140_xp", nullptr };
  1333. const var toolsets[] = { var(), "v140", "v140_xp" };
  1334. props.add (new ChoicePropertyComponent (getPlatformToolsetValue(), "Platform Toolset",
  1335. StringArray (toolsetNames),
  1336. Array<var> (toolsets, numElementsInArray (toolsets))));
  1337. }
  1338. private:
  1339. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1340. };