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.

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