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.

1970 lines
88KB

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