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.

1981 lines
92KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. //==============================================================================
  21. class MSVCProjectExporterBase : public ProjectExporter
  22. {
  23. public:
  24. MSVCProjectExporterBase (Project& p, const ValueTree& t, String folderName)
  25. : ProjectExporter (p, t),
  26. IPPLibraryValue (settings, Ids::IPPLibrary, getUndoManager()),
  27. platformToolsetValue (settings, Ids::toolset, getUndoManager()),
  28. targetPlatformVersion (settings, Ids::windowsTargetPlatformVersion, getUndoManager()),
  29. manifestFileValue (settings, Ids::msvcManifestFile, getUndoManager())
  30. {
  31. targetLocationValue.setDefault (getDefaultBuildsRootFolder() + folderName);
  32. updateOldSettings();
  33. }
  34. virtual int getVisualStudioVersion() const = 0;
  35. virtual String getSolutionComment() const = 0;
  36. virtual String getToolsVersion() const = 0;
  37. virtual String getDefaultToolset() const = 0;
  38. virtual String getDefaultWindowsTargetPlatformVersion() const = 0;
  39. //==============================================================================
  40. String getIPPLibrary() const { return IPPLibraryValue.get(); }
  41. String getPlatformToolset() const { return platformToolsetValue.get(); }
  42. String getWindowsTargetPlatformVersion() const { return targetPlatformVersion.get(); }
  43. //==============================================================================
  44. void addToolsetProperty (PropertyListBuilder& props, const char** names, const var* values, int num)
  45. {
  46. props.add (new ChoicePropertyComponent (platformToolsetValue, "Platform Toolset",
  47. StringArray (names, num), { values, num }),
  48. "Specifies the version of the platform toolset that will be used when building this project.");
  49. }
  50. void addIPPLibraryProperty (PropertyListBuilder& props)
  51. {
  52. props.add (new ChoicePropertyComponent (IPPLibraryValue, "Use IPP Library",
  53. { "No", "Yes (Default Linking)", "Multi-Threaded Static Library", "Single-Threaded Static Library", "Multi-Threaded DLL", "Single-Threaded DLL" },
  54. { var(), "true", "Parallel_Static", "Sequential", "Parallel_Dynamic", "Sequential_Dynamic" }),
  55. "Enable this to use Intel's Integrated Performance Primitives library.");
  56. }
  57. void addWindowsTargetPlatformProperties (PropertyListBuilder& props)
  58. {
  59. auto isWindows10SDK = getVisualStudioVersion() > 14;
  60. props.add (new TextPropertyComponent (targetPlatformVersion, "Windows Target Platform", 20, false),
  61. String ("Specifies the version of the Windows SDK that will be used when building this project. ")
  62. + (isWindows10SDK ? "You can see which SDKs you have installed on your machine by going to \"Program Files (x86)\\Windows Kits\\10\\Lib\". " : "")
  63. + "The default value for this exporter is " + getDefaultWindowsTargetPlatformVersion());
  64. }
  65. void addPlatformToolsetToPropertyGroup (XmlElement& p) const
  66. {
  67. forEachXmlChildElementWithTagName (p, e, "PropertyGroup")
  68. e->createNewChildElement ("PlatformToolset")->addTextElement (getPlatformToolset());
  69. }
  70. void addWindowsTargetPlatformVersionToPropertyGroup (XmlElement& p) const
  71. {
  72. forEachXmlChildElementWithTagName (p, e, "PropertyGroup")
  73. e->createNewChildElement ("WindowsTargetPlatformVersion")->addTextElement (getWindowsTargetPlatformVersion());
  74. }
  75. void addIPPSettingToPropertyGroup (XmlElement& p) const
  76. {
  77. auto ippLibrary = getIPPLibrary();
  78. if (ippLibrary.isNotEmpty())
  79. forEachXmlChildElementWithTagName (p, e, "PropertyGroup")
  80. e->createNewChildElement ("UseIntelIPP")->addTextElement (ippLibrary);
  81. }
  82. void create (const OwnedArray<LibraryModule>&) const override
  83. {
  84. createResourcesAndIcon();
  85. for (int i = 0; i < targets.size(); ++i)
  86. if (auto* target = targets[i])
  87. target->writeProjectFile();
  88. {
  89. MemoryOutputStream mo;
  90. writeSolutionFile (mo, "11.00", getSolutionComment());
  91. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  92. }
  93. }
  94. //==============================================================================
  95. void initialiseDependencyPathValues() override
  96. {
  97. vst3Path.referTo (Value (new DependencyPathValueSource (getSetting (Ids::vst3Folder),
  98. Ids::vst3Path,
  99. TargetOS::windows)));
  100. aaxPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::aaxFolder),
  101. Ids::aaxPath,
  102. TargetOS::windows)));
  103. rtasPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::rtasFolder),
  104. Ids::rtasPath,
  105. TargetOS::windows)));
  106. }
  107. //==============================================================================
  108. class MSVCBuildConfiguration : public BuildConfiguration,
  109. private Value::Listener
  110. {
  111. public:
  112. MSVCBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  113. : BuildConfiguration (p, settings, e),
  114. warningLevelValue (config, Ids::winWarningLevel, getUndoManager(), 4),
  115. warningsAreErrorsValue (config, Ids::warningsAreErrors, getUndoManager(), false),
  116. prebuildCommandValue (config, Ids::prebuildCommand, getUndoManager()),
  117. postbuildCommandValue (config, Ids::postbuildCommand, getUndoManager()),
  118. generateDebugSymbolsValue (config, Ids::alwaysGenerateDebugSymbols, getUndoManager(), false),
  119. generateManifestValue (config, Ids::generateManifest, getUndoManager(), true),
  120. enableIncrementalLinkingValue (config, Ids::enableIncrementalLinking, getUndoManager(), false),
  121. useRuntimeLibDLLValue (config, Ids::useRuntimeLibDLL, getUndoManager(), true),
  122. intermediatesPathValue (config, Ids::intermediatesPath, getUndoManager()),
  123. characterSetValue (config, Ids::characterSet, getUndoManager()),
  124. architectureTypeValue (config, Ids::winArchitecture, getUndoManager(), get64BitArchName()),
  125. fastMathValue (config, Ids::fastMath, getUndoManager()),
  126. debugInformationFormatValue (config, Ids::debugInformationFormat, getUndoManager(), isDebug() ? "ProgramDatabase" : "None"),
  127. pluginBinaryCopyStepValue (config, Ids::enablePluginBinaryCopyStep, getUndoManager(), false),
  128. vstBinaryLocation (config, Ids::vstBinaryLocation, getUndoManager()),
  129. vst3BinaryLocation (config, Ids::vst3BinaryLocation, getUndoManager()),
  130. rtasBinaryLocation (config, Ids::rtasBinaryLocation, getUndoManager()),
  131. aaxBinaryLocation (config, Ids::aaxBinaryLocation, getUndoManager()),
  132. unityPluginBinaryLocation (config, Ids::unityPluginBinaryLocation, getUndoManager(), {})
  133. {
  134. if (! isDebug())
  135. updateOldLTOSetting();
  136. setPluginBinaryCopyLocationDefaults();
  137. optimisationLevelValue.setDefault (isDebug() ? optimisationOff : optimiseFull);
  138. architectureValueToListenTo = architectureTypeValue.getPropertyAsValue();
  139. architectureValueToListenTo.addListener (this);
  140. }
  141. //==============================================================================
  142. int getWarningLevel() const { return warningLevelValue.get(); }
  143. bool areWarningsTreatedAsErrors() const { return warningsAreErrorsValue.get(); }
  144. String getPrebuildCommandString() const { return prebuildCommandValue.get(); }
  145. String getPostbuildCommandString() const { return postbuildCommandValue.get(); }
  146. bool shouldGenerateDebugSymbols() const { return generateDebugSymbolsValue.get(); }
  147. bool shouldGenerateManifest() const { return generateManifestValue.get(); }
  148. bool shouldLinkIncremental() const { return enableIncrementalLinkingValue.get(); }
  149. bool isUsingRuntimeLibDLL() const { return useRuntimeLibDLLValue.get(); }
  150. String getIntermediatesPathString() const { return intermediatesPathValue.get(); }
  151. String getCharacterSetString() const { return characterSetValue.get(); }
  152. String get64BitArchName() const { return "x64"; }
  153. String get32BitArchName() const { return "Win32"; }
  154. String getArchitectureString() const { return architectureTypeValue.get(); }
  155. bool is64Bit() const { return getArchitectureString() == get64BitArchName(); }
  156. bool isFastMathEnabled() const { return fastMathValue.get(); }
  157. String getDebugInformationFormatString() const { return debugInformationFormatValue.get(); }
  158. bool isPluginBinaryCopyStepEnabled() const { return pluginBinaryCopyStepValue.get(); }
  159. String getVSTBinaryLocationString() const { return vstBinaryLocation.get(); }
  160. String getVST3BinaryLocationString() const { return vst3BinaryLocation.get(); }
  161. String getRTASBinaryLocationString() const { return rtasBinaryLocation.get();}
  162. String getAAXBinaryLocationString() const { return aaxBinaryLocation.get();}
  163. String getUnityPluginBinaryLocationString() const { return unityPluginBinaryLocation.get(); }
  164. //==============================================================================
  165. String createMSVCConfigName() const
  166. {
  167. return getName() + "|" + (is64Bit() ? "x64" : "Win32");
  168. }
  169. String getOutputFilename (const String& suffix, bool forceSuffix, bool forceUnityPrefix) const
  170. {
  171. auto target = File::createLegalFileName (getTargetBinaryNameString (forceUnityPrefix).trim());
  172. if (forceSuffix || ! target.containsChar ('.'))
  173. return target.upToLastOccurrenceOf (".", false, false) + suffix;
  174. return target;
  175. }
  176. void createConfigProperties (PropertyListBuilder& props) override
  177. {
  178. addVisualStudioPluginInstallPathProperties (props);
  179. props.add (new ChoicePropertyComponent (architectureTypeValue, "Architecture",
  180. { get32BitArchName(), get64BitArchName() },
  181. { get32BitArchName(), get64BitArchName() }),
  182. "Whether to use a 32-bit or 64-bit architecture.");
  183. props.add (new ChoicePropertyComponentWithEnablement (debugInformationFormatValue,
  184. isDebug() ? isDebugValue : generateDebugSymbolsValue,
  185. "Debug Information Format",
  186. { "None", "C7 Compatible (/Z7)", "Program Database (/Zi)", "Program Database for Edit And Continue (/ZI)" },
  187. { "None", "OldStyle", "ProgramDatabase", "EditAndContinue" }),
  188. "The type of debugging information created for your program for this configuration."
  189. " This will always be used in a debug configuration and will be used in a release configuration"
  190. " with forced generation of debug symbols.");
  191. props.add (new ChoicePropertyComponent (fastMathValue, "Relax IEEE Compliance"),
  192. "Enable this to use FAST_MATH non-IEEE mode. (Warning: this can have unexpected results!)");
  193. props.add (new ChoicePropertyComponent (optimisationLevelValue, "Optimisation",
  194. { "Disabled (/Od)", "Minimise size (/O1)", "Maximise speed (/O2)", "Full optimisation (/Ox)" },
  195. { optimisationOff, optimiseMinSize, optimiseMaxSpeed, optimiseFull }),
  196. "The optimisation level for this configuration");
  197. props.add (new TextPropertyComponent (intermediatesPathValue, "Intermediates Path", 2048, false),
  198. "An optional path to a folder to use for the intermediate build files. Note that Visual Studio allows "
  199. "you to use macros in this path, e.g. \"$(TEMP)\\MyAppBuildFiles\\$(Configuration)\", which is a handy way to "
  200. "send them to the user's temp folder.");
  201. props.add (new ChoicePropertyComponent (warningLevelValue, "Warning Level",
  202. { "Low", "Medium", "High" },
  203. { 2, 3, 4 }),
  204. "The compilation warning level to use.");
  205. props.add (new ChoicePropertyComponent (warningsAreErrorsValue, "Treat Warnings as Errors"),
  206. "Enable this to treat compilation warnings as errors.");
  207. props.add (new ChoicePropertyComponent (useRuntimeLibDLLValue, "Runtime Library",
  208. { "Use static runtime", "Use DLL runtime" },
  209. { false, true }),
  210. "If the static runtime is selected then your app/plug-in will not be dependent upon users having Microsoft's redistributable "
  211. "C++ runtime installed. However, if you are linking libraries from different sources you must select the same type of runtime "
  212. "used by the libraries.");
  213. props.add (new ChoicePropertyComponent (enableIncrementalLinkingValue, "Incremental Linking"),
  214. "Enable to avoid linking from scratch for every new build. "
  215. "Disable to ensure that your final release build does not contain padding or thunks.");
  216. if (! isDebug())
  217. {
  218. props.add (new ChoicePropertyComponent (generateDebugSymbolsValue, "Force Generation of Debug Symbols"),
  219. "Enable this to force generation of debug symbols in a release configuration.");
  220. }
  221. props.add (new TextPropertyComponent (prebuildCommandValue, "Pre-build Command", 2048, true),
  222. "Some command that will be run before a build starts.");
  223. props.add (new TextPropertyComponent (postbuildCommandValue, "Post-build Command", 2048, true),
  224. "Some command that will be run after a build starts.");
  225. props.add (new ChoicePropertyComponent (generateManifestValue, "Generate Manifest"),
  226. "Enable this to generate a Manifest file.");
  227. props.add (new ChoicePropertyComponent (characterSetValue, "Character Set",
  228. { "MultiByte", "Unicode" },
  229. { "MultiByte", "Unicode" }),
  230. "Specifies the character set used when building.");
  231. }
  232. String getModuleLibraryArchName() const override
  233. {
  234. String result ("$(Platform)\\");
  235. result += isUsingRuntimeLibDLL() ? "MD" : "MT";
  236. if (isDebug())
  237. result += "d";
  238. return result;
  239. }
  240. private:
  241. ValueWithDefault warningLevelValue, warningsAreErrorsValue, prebuildCommandValue, postbuildCommandValue, generateDebugSymbolsValue,
  242. generateManifestValue, enableIncrementalLinkingValue, useRuntimeLibDLLValue, intermediatesPathValue,
  243. characterSetValue, architectureTypeValue, fastMathValue, debugInformationFormatValue, pluginBinaryCopyStepValue;
  244. ValueWithDefault vstBinaryLocation, vst3BinaryLocation, rtasBinaryLocation, aaxBinaryLocation, unityPluginBinaryLocation;
  245. Value architectureValueToListenTo;
  246. //==============================================================================
  247. void updateOldLTOSetting()
  248. {
  249. if (config.getPropertyAsValue ("wholeProgramOptimisation", nullptr) != Value())
  250. linkTimeOptimisationValue = (static_cast<int> (config ["wholeProgramOptimisation"]) == 0);
  251. }
  252. void addVisualStudioPluginInstallPathProperties (PropertyListBuilder& props)
  253. {
  254. auto isBuildingAnyPlugins = (project.shouldBuildVST() || project.shouldBuildVST3() || project.shouldBuildRTAS()
  255. || project.shouldBuildAAX() || project.shouldBuildUnityPlugin());
  256. if (isBuildingAnyPlugins)
  257. props.add (new ChoicePropertyComponent (pluginBinaryCopyStepValue, "Enable Plugin Copy Step"),
  258. "Enable this to copy plugin binaries to a specified folder after building.");
  259. if (project.shouldBuildVST3())
  260. props.add (new TextPropertyComponentWithEnablement (vst3BinaryLocation, pluginBinaryCopyStepValue, "VST3 Binary Location",
  261. 1024, false),
  262. "The folder in which the compiled VST3 binary should be placed.");
  263. if (project.shouldBuildRTAS())
  264. props.add (new TextPropertyComponentWithEnablement (rtasBinaryLocation, pluginBinaryCopyStepValue, "RTAS Binary Location",
  265. 1024, false),
  266. "The folder in which the compiled RTAS binary should be placed.");
  267. if (project.shouldBuildAAX())
  268. props.add (new TextPropertyComponentWithEnablement (aaxBinaryLocation, pluginBinaryCopyStepValue, "AAX Binary Location",
  269. 1024, false),
  270. "The folder in which the compiled AAX binary should be placed.");
  271. if (project.shouldBuildUnityPlugin())
  272. props.add (new TextPropertyComponentWithEnablement (unityPluginBinaryLocation, pluginBinaryCopyStepValue, "Unity Binary Location",
  273. 1024, false),
  274. "The folder in which the compiled Unity plugin binary and associated C# GUI script should be placed.");
  275. if (project.shouldBuildVST())
  276. props.add (new TextPropertyComponentWithEnablement (vstBinaryLocation, pluginBinaryCopyStepValue, "VST (legacy) Binary Location",
  277. 1024, false),
  278. "The folder in which the compiled lehacy VST binary should be placed.");
  279. }
  280. void setPluginBinaryCopyLocationDefaults()
  281. {
  282. vstBinaryLocation.setDefault ((is64Bit() ? "%ProgramW6432%" : "%programfiles(x86)%") + String ("\\Steinberg\\Vstplugins"));
  283. auto prefix = is64Bit() ? "%CommonProgramW6432%"
  284. : "%CommonProgramFiles(x86)%";
  285. vst3BinaryLocation.setDefault (prefix + String ("\\VST3"));
  286. rtasBinaryLocation.setDefault (prefix + String ("\\Digidesign\\DAE\\Plug-Ins"));
  287. aaxBinaryLocation.setDefault (prefix + String ("\\Avid\\Audio\\Plug-Ins"));
  288. }
  289. void valueChanged (Value&) override
  290. {
  291. setPluginBinaryCopyLocationDefaults();
  292. }
  293. };
  294. //==============================================================================
  295. class MSVCTargetBase : public ProjectType::Target
  296. {
  297. public:
  298. MSVCTargetBase (ProjectType::Target::Type targetType, const MSVCProjectExporterBase& exporter)
  299. : ProjectType::Target (targetType), owner (exporter)
  300. {
  301. projectGuid = createGUID (owner.getProject().getProjectUIDString() + getName());
  302. }
  303. virtual ~MSVCTargetBase() {}
  304. String getProjectVersionString() const { return "10.00"; }
  305. String getProjectFileSuffix() const { return ".vcxproj"; }
  306. String getFiltersFileSuffix() const { return ".vcxproj.filters"; }
  307. String getTopLevelXmlEntity() const { return "Project"; }
  308. //==============================================================================
  309. void fillInProjectXml (XmlElement& projectXml) const
  310. {
  311. projectXml.setAttribute ("DefaultTargets", "Build");
  312. projectXml.setAttribute ("ToolsVersion", getOwner().getToolsVersion());
  313. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  314. {
  315. auto* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  316. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  317. for (ConstConfigIterator i (owner); i.next();)
  318. {
  319. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  320. auto* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  321. e->setAttribute ("Include", config.createMSVCConfigName());
  322. e->createNewChildElement ("Configuration")->addTextElement (config.getName());
  323. e->createNewChildElement ("Platform")->addTextElement (config.is64Bit() ? config.get64BitArchName()
  324. : config.get32BitArchName());
  325. }
  326. }
  327. {
  328. auto* globals = projectXml.createNewChildElement ("PropertyGroup");
  329. globals->setAttribute ("Label", "Globals");
  330. globals->createNewChildElement ("ProjectGuid")->addTextElement (getProjectGuid());
  331. }
  332. {
  333. auto* imports = projectXml.createNewChildElement ("Import");
  334. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  335. }
  336. for (ConstConfigIterator i (owner); i.next();)
  337. {
  338. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  339. auto* e = projectXml.createNewChildElement ("PropertyGroup");
  340. setConditionAttribute (*e, config);
  341. e->setAttribute ("Label", "Configuration");
  342. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  343. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  344. e->createNewChildElement ("WholeProgramOptimization")->addTextElement (config.isLinkTimeOptimisationEnabled() ? "true"
  345. : "false");
  346. auto charSet = config.getCharacterSetString();
  347. if (charSet.isNotEmpty())
  348. e->createNewChildElement ("CharacterSet")->addTextElement (charSet);
  349. if (config.shouldLinkIncremental())
  350. e->createNewChildElement ("LinkIncremental")->addTextElement ("true");
  351. }
  352. {
  353. auto* e = projectXml.createNewChildElement ("Import");
  354. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  355. }
  356. {
  357. auto* e = projectXml.createNewChildElement ("ImportGroup");
  358. e->setAttribute ("Label", "ExtensionSettings");
  359. }
  360. {
  361. auto* e = projectXml.createNewChildElement ("ImportGroup");
  362. e->setAttribute ("Label", "PropertySheets");
  363. auto* p = e->createNewChildElement ("Import");
  364. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  365. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  366. p->setAttribute ("Label", "LocalAppDataPlatform");
  367. }
  368. {
  369. auto* e = projectXml.createNewChildElement ("PropertyGroup");
  370. e->setAttribute ("Label", "UserMacros");
  371. }
  372. {
  373. auto* props = projectXml.createNewChildElement ("PropertyGroup");
  374. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  375. props->createNewChildElement ("TargetExt")->addTextElement (getTargetSuffix());
  376. for (ConstConfigIterator i (owner); i.next();)
  377. {
  378. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  379. if (getConfigTargetPath (config).isNotEmpty())
  380. {
  381. auto* outdir = props->createNewChildElement ("OutDir");
  382. setConditionAttribute (*outdir, config);
  383. outdir->addTextElement (FileHelpers::windowsStylePath (getConfigTargetPath (config)) + "\\");
  384. }
  385. {
  386. auto* intdir = props->createNewChildElement("IntDir");
  387. setConditionAttribute (*intdir, config);
  388. auto intermediatesPath = getIntermediatesPath (config);
  389. if (! intermediatesPath.endsWithChar (L'\\'))
  390. intermediatesPath += L'\\';
  391. intdir->addTextElement (FileHelpers::windowsStylePath (intermediatesPath));
  392. }
  393. {
  394. auto* targetName = props->createNewChildElement ("TargetName");
  395. setConditionAttribute (*targetName, config);
  396. targetName->addTextElement (config.getOutputFilename ("", false, type == UnityPlugIn));
  397. }
  398. {
  399. auto* manifest = props->createNewChildElement ("GenerateManifest");
  400. setConditionAttribute (*manifest, config);
  401. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  402. }
  403. if (type != SharedCodeTarget)
  404. {
  405. auto librarySearchPaths = getLibrarySearchPaths (config);
  406. if (librarySearchPaths.size() > 0)
  407. {
  408. auto* libPath = props->createNewChildElement ("LibraryPath");
  409. setConditionAttribute (*libPath, config);
  410. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  411. }
  412. }
  413. }
  414. }
  415. for (ConstConfigIterator i (owner); i.next();)
  416. {
  417. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  418. bool isDebug = config.isDebug();
  419. auto* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  420. setConditionAttribute (*group, config);
  421. {
  422. auto* midl = group->createNewChildElement ("Midl");
  423. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  424. : "NDEBUG;%(PreprocessorDefinitions)");
  425. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  426. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  427. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  428. midl->createNewChildElement ("HeaderFileName");
  429. }
  430. bool isUsingEditAndContinue = false;
  431. {
  432. auto* cl = group->createNewChildElement ("ClCompile");
  433. cl->createNewChildElement ("Optimization")->addTextElement (getOptimisationLevelString (config.getOptimisationLevelInt()));
  434. if (isDebug || config.shouldGenerateDebugSymbols())
  435. {
  436. cl->createNewChildElement ("DebugInformationFormat")
  437. ->addTextElement (config.getDebugInformationFormatString());
  438. }
  439. auto includePaths = getOwner().getHeaderSearchPaths (config);
  440. includePaths.addArray (getExtraSearchPaths());
  441. includePaths.add ("%(AdditionalIncludeDirectories)");
  442. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  443. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  444. bool runtimeDLL = config.isUsingRuntimeLibDLL();
  445. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (runtimeDLL ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  446. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  447. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  448. cl->createNewChildElement ("PrecompiledHeader");
  449. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  450. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  451. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement ("$(IntDir)\\");
  452. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (config.getWarningLevel()));
  453. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  454. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  455. if (config.isFastMathEnabled())
  456. cl->createNewChildElement ("FloatingPointModel")->addTextElement ("Fast");
  457. auto extraFlags = getOwner().replacePreprocessorTokens (config, getOwner().getExtraCompilerFlagsString()).trim();
  458. if (extraFlags.isNotEmpty())
  459. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  460. if (config.areWarningsTreatedAsErrors())
  461. cl->createNewChildElement ("TreatWarningAsError")->addTextElement ("true");
  462. auto cppStandard = owner.project.getCppStandardString();
  463. if (cppStandard == "11") // VS doesn't support the C++11 flag so we have to bump it to C++14
  464. cppStandard = "14";
  465. else if (cppStandard == "17") // nor does it support the C++17 flag, so we'll just use latest for now until it's added
  466. cppStandard = "latest";
  467. cl->createNewChildElement ("LanguageStandard")->addTextElement ("stdcpp" + cppStandard);
  468. }
  469. {
  470. auto* res = group->createNewChildElement ("ResourceCompile");
  471. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  472. : "NDEBUG;%(PreprocessorDefinitions)");
  473. }
  474. auto externalLibraries = getExternalLibraries (config, getOwner().getExternalLibrariesString());
  475. auto additionalDependencies = type != SharedCodeTarget && externalLibraries.isNotEmpty()
  476. ? getOwner().replacePreprocessorTokens (config, externalLibraries).trim() + ";%(AdditionalDependencies)"
  477. : String();
  478. auto librarySearchPaths = config.getLibrarySearchPaths();
  479. auto additionalLibraryDirs = type != SharedCodeTarget && librarySearchPaths.size() > 0
  480. ? getOwner().replacePreprocessorTokens (config, librarySearchPaths.joinIntoString (";")) + ";%(AdditionalLibraryDirectories)"
  481. : String();
  482. {
  483. auto* link = group->createNewChildElement ("Link");
  484. link->createNewChildElement ("OutputFile")->addTextElement (getOutputFilePath (config, type == UnityPlugIn));
  485. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  486. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  487. : "%(IgnoreSpecificDefaultLibraries)");
  488. link->createNewChildElement ("GenerateDebugInformation")->addTextElement ((isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  489. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (getOwner().getIntDirFile (config, config.getOutputFilename (".pdb", true, type == UnityPlugIn)));
  490. link->createNewChildElement ("SubSystem")->addTextElement (type == ConsoleApp ? "Console" : "Windows");
  491. if (! config.is64Bit())
  492. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  493. if (isUsingEditAndContinue)
  494. link->createNewChildElement ("ImageHasSafeExceptionHandlers")->addTextElement ("false");
  495. if (! isDebug)
  496. {
  497. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  498. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  499. }
  500. if (additionalLibraryDirs.isNotEmpty())
  501. link->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (additionalLibraryDirs);
  502. link->createNewChildElement ("LargeAddressAware")->addTextElement ("true");
  503. if (additionalDependencies.isNotEmpty())
  504. link->createNewChildElement ("AdditionalDependencies")->addTextElement (additionalDependencies);
  505. auto extraLinkerOptions = getOwner().getExtraLinkerFlagsString();
  506. if (extraLinkerOptions.isNotEmpty())
  507. link->createNewChildElement ("AdditionalOptions")->addTextElement (getOwner().replacePreprocessorTokens (config, extraLinkerOptions).trim()
  508. + " %(AdditionalOptions)");
  509. auto delayLoadedDLLs = getDelayLoadedDLLs();
  510. if (delayLoadedDLLs.isNotEmpty())
  511. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (delayLoadedDLLs);
  512. auto moduleDefinitionsFile = getModuleDefinitions (config);
  513. if (moduleDefinitionsFile.isNotEmpty())
  514. link->createNewChildElement ("ModuleDefinitionFile")
  515. ->addTextElement (moduleDefinitionsFile);
  516. }
  517. {
  518. auto* bsc = group->createNewChildElement ("Bscmake");
  519. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  520. bsc->createNewChildElement ("OutputFile")->addTextElement (getOwner().getIntDirFile (config, config.getOutputFilename (".bsc", true, type == UnityPlugIn)));
  521. }
  522. if (type != SharedCodeTarget)
  523. {
  524. auto* lib = group->createNewChildElement ("Lib");
  525. if (additionalDependencies.isNotEmpty())
  526. lib->createNewChildElement ("AdditionalDependencies")->addTextElement (additionalDependencies);
  527. if (additionalLibraryDirs.isNotEmpty())
  528. lib->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (additionalLibraryDirs);
  529. }
  530. auto manifestFile = getOwner().getManifestPath();
  531. if (manifestFile.getRoot() != RelativePath::unknown)
  532. {
  533. auto* bsc = group->createNewChildElement ("Manifest");
  534. bsc->createNewChildElement ("AdditionalManifestFiles")
  535. ->addTextElement (manifestFile.rebased (getOwner().getProject().getFile().getParentDirectory(),
  536. getOwner().getTargetFolder(),
  537. RelativePath::buildTargetFolder).toWindowsStyle());
  538. }
  539. if (getTargetFileType() == staticLibrary && ! config.is64Bit())
  540. {
  541. auto* lib = group->createNewChildElement ("Lib");
  542. lib->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  543. }
  544. auto preBuild = getPreBuildSteps (config);
  545. if (preBuild.isNotEmpty())
  546. group->createNewChildElement ("PreBuildEvent")
  547. ->createNewChildElement ("Command")
  548. ->addTextElement (preBuild);
  549. auto postBuild = getPostBuildSteps (config);
  550. if (postBuild.isNotEmpty())
  551. group->createNewChildElement ("PostBuildEvent")
  552. ->createNewChildElement ("Command")
  553. ->addTextElement (postBuild);
  554. }
  555. std::unique_ptr<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  556. {
  557. auto* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  558. auto* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  559. for (int i = 0; i < getOwner().getAllGroups().size(); ++i)
  560. {
  561. auto& group = getOwner().getAllGroups().getReference (i);
  562. if (group.getNumChildren() > 0)
  563. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  564. }
  565. }
  566. if (getOwner().iconFile != File())
  567. {
  568. auto* e = otherFilesGroup->createNewChildElement ("None");
  569. e->setAttribute ("Include", prependDot (getOwner().iconFile.getFileName()));
  570. }
  571. if (otherFilesGroup->getFirstChildElement() != nullptr)
  572. projectXml.addChildElement (otherFilesGroup.release());
  573. if (type != SharedCodeTarget && getOwner().hasResourceFile())
  574. {
  575. auto* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  576. auto* e = rcGroup->createNewChildElement ("ResourceCompile");
  577. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  578. }
  579. {
  580. auto* e = projectXml.createNewChildElement ("Import");
  581. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  582. }
  583. {
  584. auto* e = projectXml.createNewChildElement ("ImportGroup");
  585. e->setAttribute ("Label", "ExtensionTargets");
  586. }
  587. getOwner().addPlatformToolsetToPropertyGroup (projectXml);
  588. getOwner().addWindowsTargetPlatformVersionToPropertyGroup (projectXml);
  589. getOwner().addIPPSettingToPropertyGroup (projectXml);
  590. }
  591. String getProjectType() const
  592. {
  593. switch (getTargetFileType())
  594. {
  595. case executable:
  596. return "Application";
  597. case staticLibrary:
  598. return "StaticLibrary";
  599. default:
  600. break;
  601. }
  602. return "DynamicLibrary";
  603. }
  604. //==============================================================================
  605. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  606. {
  607. auto targetType = (getOwner().getProject().getProjectType().isAudioPlugin() ? type : SharedCodeTarget);
  608. if (projectItem.isGroup())
  609. {
  610. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  611. addFilesToCompile (projectItem.getChild (i), cpps, headers, otherFiles);
  612. }
  613. else if (projectItem.shouldBeAddedToTargetProject()
  614. && getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType)
  615. {
  616. RelativePath path (projectItem.getFile(), getOwner().getTargetFolder(), RelativePath::buildTargetFolder);
  617. jassert (path.getRoot() == RelativePath::buildTargetFolder);
  618. if (path.hasFileExtension (cOrCppFileExtensions) || path.hasFileExtension (asmFileExtensions))
  619. {
  620. if (targetType == SharedCodeTarget || projectItem.shouldBeCompiled())
  621. {
  622. auto* e = cpps.createNewChildElement ("ClCompile");
  623. e->setAttribute ("Include", path.toWindowsStyle());
  624. if (shouldUseStdCall (path))
  625. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  626. if (! projectItem.shouldBeCompiled())
  627. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  628. }
  629. }
  630. else if (path.hasFileExtension (headerFileExtensions))
  631. {
  632. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  633. }
  634. else if (! path.hasFileExtension (objCFileExtensions))
  635. {
  636. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  637. }
  638. }
  639. }
  640. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  641. {
  642. auto& msvcConfig = dynamic_cast<const MSVCBuildConfiguration&> (config);
  643. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + msvcConfig.createMSVCConfigName() + "'");
  644. }
  645. //==============================================================================
  646. void addFilterGroup (XmlElement& groups, const String& path) const
  647. {
  648. auto* e = groups.createNewChildElement ("Filter");
  649. e->setAttribute ("Include", path);
  650. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  651. }
  652. void addFileToFilter (const RelativePath& file, const String& groupPath,
  653. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  654. {
  655. XmlElement* e = nullptr;
  656. if (file.hasFileExtension (headerFileExtensions))
  657. e = headers.createNewChildElement ("ClInclude");
  658. else if (file.hasFileExtension (sourceFileExtensions))
  659. e = cpps.createNewChildElement ("ClCompile");
  660. else
  661. e = otherFiles.createNewChildElement ("None");
  662. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  663. e->setAttribute ("Include", file.toWindowsStyle());
  664. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  665. }
  666. bool addFilesToFilter (const Project::Item& projectItem, const String& path,
  667. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  668. {
  669. auto targetType = (getOwner().getProject().getProjectType().isAudioPlugin() ? type : SharedCodeTarget);
  670. if (projectItem.isGroup())
  671. {
  672. bool filesWereAdded = false;
  673. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  674. if (addFilesToFilter (projectItem.getChild(i),
  675. (path.isEmpty() ? String() : (path + "\\")) + projectItem.getChild(i).getName(),
  676. cpps, headers, otherFiles, groups))
  677. filesWereAdded = true;
  678. if (filesWereAdded)
  679. addFilterGroup (groups, path);
  680. return filesWereAdded;
  681. }
  682. else if (projectItem.shouldBeAddedToTargetProject())
  683. {
  684. RelativePath relativePath (projectItem.getFile(), getOwner().getTargetFolder(), RelativePath::buildTargetFolder);
  685. jassert (relativePath.getRoot() == RelativePath::buildTargetFolder);
  686. if (getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType
  687. && (targetType == SharedCodeTarget || projectItem.shouldBeCompiled()))
  688. {
  689. addFileToFilter (relativePath, path.upToLastOccurrenceOf ("\\", false, false), cpps, headers, otherFiles);
  690. return true;
  691. }
  692. }
  693. return false;
  694. }
  695. bool addFilesToFilter (const Array<RelativePath>& files, const String& path,
  696. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups)
  697. {
  698. if (files.size() > 0)
  699. {
  700. addFilterGroup (groups, path);
  701. for (int i = 0; i < files.size(); ++i)
  702. addFileToFilter (files.getReference(i), path, cpps, headers, otherFiles);
  703. return true;
  704. }
  705. return false;
  706. }
  707. void fillInFiltersXml (XmlElement& filterXml) const
  708. {
  709. filterXml.setAttribute ("ToolsVersion", getOwner().getToolsVersion());
  710. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  711. auto* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  712. auto* cpps = filterXml.createNewChildElement ("ItemGroup");
  713. auto* headers = filterXml.createNewChildElement ("ItemGroup");
  714. std::unique_ptr<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  715. for (int i = 0; i < getOwner().getAllGroups().size(); ++i)
  716. {
  717. auto& group = getOwner().getAllGroups().getReference(i);
  718. if (group.getNumChildren() > 0)
  719. addFilesToFilter (group, group.getName(), *cpps, *headers, *otherFilesGroup, *groupsXml);
  720. }
  721. if (getOwner().iconFile.exists())
  722. {
  723. auto* e = otherFilesGroup->createNewChildElement ("None");
  724. e->setAttribute ("Include", prependDot (getOwner().iconFile.getFileName()));
  725. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  726. }
  727. if (otherFilesGroup->getFirstChildElement() != nullptr)
  728. filterXml.addChildElement (otherFilesGroup.release());
  729. if (type != SharedCodeTarget && getOwner().hasResourceFile())
  730. {
  731. auto* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  732. auto* e = rcGroup->createNewChildElement ("ResourceCompile");
  733. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  734. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  735. }
  736. }
  737. const MSVCProjectExporterBase& getOwner() const { return owner; }
  738. const String& getProjectGuid() const { return projectGuid; }
  739. //==============================================================================
  740. void writeProjectFile()
  741. {
  742. {
  743. XmlElement projectXml (getTopLevelXmlEntity());
  744. fillInProjectXml (projectXml);
  745. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  746. }
  747. {
  748. XmlElement filtersXml (getTopLevelXmlEntity());
  749. fillInFiltersXml (filtersXml);
  750. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "UTF-8", 100);
  751. }
  752. }
  753. String getSolutionTargetPath (const BuildConfiguration& config) const
  754. {
  755. auto binaryPath = config.getTargetBinaryRelativePathString().trim();
  756. if (binaryPath.isEmpty())
  757. return "$(SolutionDir)$(Platform)\\$(Configuration)";
  758. RelativePath binaryRelPath (binaryPath, RelativePath::projectFolder);
  759. if (binaryRelPath.isAbsolute())
  760. return binaryRelPath.toWindowsStyle();
  761. return prependDot (binaryRelPath.rebased (getOwner().projectFolder, getOwner().getTargetFolder(), RelativePath::buildTargetFolder)
  762. .toWindowsStyle());
  763. }
  764. String getConfigTargetPath (const BuildConfiguration& config) const
  765. {
  766. auto solutionTargetFolder = getSolutionTargetPath (config);
  767. return solutionTargetFolder + "\\" + getName();
  768. }
  769. String getIntermediatesPath (const MSVCBuildConfiguration& config) const
  770. {
  771. auto intDir = (config.getIntermediatesPathString().isNotEmpty() ? config.getIntermediatesPathString()
  772. : "$(Platform)\\$(Configuration)");
  773. if (! intDir.endsWithChar (L'\\'))
  774. intDir += L'\\';
  775. return intDir + getName();
  776. }
  777. static const char* getOptimisationLevelString (int level)
  778. {
  779. switch (level)
  780. {
  781. case optimiseMinSize: return "MinSpace";
  782. case optimiseMaxSpeed: return "MaxSpeed";
  783. case optimiseFull: return "Full";
  784. default: return "Disabled";
  785. }
  786. }
  787. String getTargetSuffix() const
  788. {
  789. auto fileType = getTargetFileType();
  790. switch (fileType)
  791. {
  792. case executable: return ".exe";
  793. case staticLibrary: return ".lib";
  794. case sharedLibraryOrDLL: return ".dll";
  795. case pluginBundle:
  796. switch (type)
  797. {
  798. case VST3PlugIn: return ".vst3";
  799. case AAXPlugIn: return ".aaxdll";
  800. case RTASPlugIn: return ".dpm";
  801. default: break;
  802. }
  803. return ".dll";
  804. default:
  805. break;
  806. }
  807. return {};
  808. }
  809. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  810. {
  811. auto* e = parent.createNewChildElement ("Tool");
  812. e->setAttribute ("Name", toolName);
  813. return e;
  814. }
  815. String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const
  816. {
  817. auto defines = getOwner().msvcExtraPreprocessorDefs;
  818. defines.set ("WIN32", "");
  819. defines.set ("_WINDOWS", "");
  820. if (config.isDebug())
  821. {
  822. defines.set ("DEBUG", "");
  823. defines.set ("_DEBUG", "");
  824. }
  825. else
  826. {
  827. defines.set ("NDEBUG", "");
  828. }
  829. defines = mergePreprocessorDefs (defines, getOwner().getAllPreprocessorDefs (config, type));
  830. addExtraPreprocessorDefines (defines);
  831. if (getTargetFileType() == staticLibrary || getTargetFileType() == sharedLibraryOrDLL)
  832. defines.set("_LIB", "");
  833. StringArray result;
  834. for (int i = 0; i < defines.size(); ++i)
  835. {
  836. auto def = defines.getAllKeys()[i];
  837. auto value = defines.getAllValues()[i];
  838. if (value.isNotEmpty())
  839. def << "=" << value;
  840. result.add (def);
  841. }
  842. return result.joinIntoString (joinString);
  843. }
  844. //==============================================================================
  845. RelativePath getAAXIconFile() const
  846. {
  847. RelativePath aaxSDK (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder);
  848. RelativePath projectIcon ("icon.ico", RelativePath::buildTargetFolder);
  849. if (getOwner().getTargetFolder().getChildFile ("icon.ico").existsAsFile())
  850. return projectIcon.rebased (getOwner().getTargetFolder(),
  851. getOwner().getProject().getProjectFolder(),
  852. RelativePath::projectFolder);
  853. return aaxSDK.getChildFile ("Utilities").getChildFile ("PlugIn.ico");
  854. }
  855. String getExtraPostBuildSteps (const MSVCBuildConfiguration& config) const
  856. {
  857. if (type == AAXPlugIn)
  858. {
  859. RelativePath aaxSDK (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder);
  860. RelativePath aaxLibsFolder = aaxSDK.getChildFile ("Libs");
  861. RelativePath bundleScript = aaxSDK.getChildFile ("Utilities").getChildFile ("CreatePackage.bat");
  862. RelativePath iconFilePath = getAAXIconFile();
  863. auto outputFilename = config.getOutputFilename (".aaxplugin", true, false);
  864. auto bundleDir = getOwner().getOutDirFile (config, outputFilename);
  865. auto bundleContents = bundleDir + "\\Contents";
  866. auto archDir = bundleContents + String ("\\") + (config.is64Bit() ? "x64" : "Win32");
  867. auto executable = archDir + String ("\\") + outputFilename;
  868. auto pkgScript = String ("copy /Y ") + getOutputFilePath (config, false).quoted() + String (" ") + executable.quoted() + String ("\r\ncall ")
  869. + createRebasedPath (bundleScript) + String (" ") + archDir.quoted() + String (" ") + createRebasedPath (iconFilePath);
  870. if (config.isPluginBinaryCopyStepEnabled())
  871. return pkgScript + "\r\n" + "xcopy " + bundleDir.quoted() + " "
  872. + String (config.getAAXBinaryLocationString() + "\\" + outputFilename + "\\").quoted() + " /E /H /K /R /Y";
  873. return pkgScript;
  874. }
  875. else if (type == UnityPlugIn)
  876. {
  877. RelativePath scriptPath (config.project.getGeneratedCodeFolder().getChildFile (config.project.getUnityScriptName()),
  878. getOwner().getTargetFolder(),
  879. RelativePath::projectFolder);
  880. auto pkgScript = String ("copy /Y ") + scriptPath.toWindowsStyle().quoted() + " \"$(OutDir)\"";
  881. if (config.isPluginBinaryCopyStepEnabled())
  882. {
  883. auto copyLocation = config.getUnityPluginBinaryLocationString();
  884. pkgScript += "\r\ncopy /Y \"$(OutDir)$(TargetFileName)\" " + String (copyLocation + "\\$(TargetFileName)").quoted();
  885. pkgScript += "\r\ncopy /Y " + String ("$(OutDir)" + config.project.getUnityScriptName()).quoted() + " " + String (copyLocation + "\\" + config.project.getUnityScriptName()).quoted();
  886. }
  887. return pkgScript;
  888. }
  889. else if (config.isPluginBinaryCopyStepEnabled())
  890. {
  891. auto copyScript = String ("copy /Y \"$(OutDir)$(TargetFileName)\"") + String (" \"$COPYDIR$\\$(TargetFileName)\"");
  892. if (type == VSTPlugIn) return copyScript.replace ("$COPYDIR$", config.getVSTBinaryLocationString());
  893. if (type == VST3PlugIn) return copyScript.replace ("$COPYDIR$", config.getVST3BinaryLocationString());
  894. if (type == RTASPlugIn) return copyScript.replace ("$COPYDIR$", config.getRTASBinaryLocationString());
  895. }
  896. return {};
  897. }
  898. String getExtraPreBuildSteps (const MSVCBuildConfiguration& config) const
  899. {
  900. if (type == AAXPlugIn)
  901. {
  902. String script;
  903. auto bundleDir = getOwner().getOutDirFile (config, config.getOutputFilename (".aaxplugin", false, false));
  904. auto bundleContents = bundleDir + "\\Contents";
  905. auto archDir = bundleContents + String ("\\") + (config.is64Bit() ? "x64" : "Win32");
  906. for (auto& folder : StringArray { bundleDir, bundleContents, archDir })
  907. script += String ("if not exist \"") + folder + String ("\" mkdir \"") + folder + String ("\"\r\n");
  908. return script;
  909. }
  910. return {};
  911. }
  912. String getPostBuildSteps (const MSVCBuildConfiguration& config) const
  913. {
  914. auto postBuild = config.getPostbuildCommandString();
  915. auto extraPostBuild = getExtraPostBuildSteps (config);
  916. return postBuild + String (postBuild.isNotEmpty() && extraPostBuild.isNotEmpty() ? "\r\n" : "") + extraPostBuild;
  917. }
  918. String getPreBuildSteps (const MSVCBuildConfiguration& config) const
  919. {
  920. auto preBuild = config.getPrebuildCommandString();
  921. auto extraPreBuild = getExtraPreBuildSteps (config);
  922. return preBuild + String (preBuild.isNotEmpty() && extraPreBuild.isNotEmpty() ? "\r\n" : "") + extraPreBuild;
  923. }
  924. void addExtraPreprocessorDefines (StringPairArray& defines) const
  925. {
  926. switch (type)
  927. {
  928. case AAXPlugIn:
  929. {
  930. auto aaxLibsFolder = RelativePath (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder).getChildFile ("Libs");
  931. defines.set ("JucePlugin_AAXLibs_path", createRebasedPath (aaxLibsFolder));
  932. }
  933. break;
  934. case RTASPlugIn:
  935. {
  936. RelativePath rtasFolder (getOwner().getRTASPathValue().toString(), RelativePath::projectFolder);
  937. defines.set ("JucePlugin_WinBag_path", createRebasedPath (rtasFolder.getChildFile ("WinBag")));
  938. }
  939. break;
  940. default:
  941. break;
  942. }
  943. }
  944. String getExtraLinkerFlags() const
  945. {
  946. if (type == RTASPlugIn)
  947. return "/FORCE:multiple";
  948. return {};
  949. }
  950. StringArray getExtraSearchPaths() const
  951. {
  952. StringArray searchPaths;
  953. if (type == RTASPlugIn)
  954. {
  955. RelativePath rtasFolder (getOwner().getRTASPathValue().toString(), RelativePath::projectFolder);
  956. static const char* p[] = { "AlturaPorts/TDMPlugins/PluginLibrary/EffectClasses",
  957. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses",
  958. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses/Interfaces",
  959. "AlturaPorts/TDMPlugins/PluginLibrary/Utilities",
  960. "AlturaPorts/TDMPlugins/PluginLibrary/RTASP_Adapt",
  961. "AlturaPorts/TDMPlugins/PluginLibrary/CoreClasses",
  962. "AlturaPorts/TDMPlugins/PluginLibrary/Controls",
  963. "AlturaPorts/TDMPlugins/PluginLibrary/Meters",
  964. "AlturaPorts/TDMPlugins/PluginLibrary/ViewClasses",
  965. "AlturaPorts/TDMPlugins/PluginLibrary/DSPClasses",
  966. "AlturaPorts/TDMPlugins/PluginLibrary/Interfaces",
  967. "AlturaPorts/TDMPlugins/common",
  968. "AlturaPorts/TDMPlugins/common/Platform",
  969. "AlturaPorts/TDMPlugins/common/Macros",
  970. "AlturaPorts/TDMPlugins/SignalProcessing/Public",
  971. "AlturaPorts/TDMPlugIns/DSPManager/Interfaces",
  972. "AlturaPorts/SADriver/Interfaces",
  973. "AlturaPorts/DigiPublic/Interfaces",
  974. "AlturaPorts/DigiPublic",
  975. "AlturaPorts/Fic/Interfaces/DAEClient",
  976. "AlturaPorts/NewFileLibs/Cmn",
  977. "AlturaPorts/NewFileLibs/DOA",
  978. "AlturaPorts/AlturaSource/PPC_H",
  979. "AlturaPorts/AlturaSource/AppSupport",
  980. "AvidCode/AVX2sdk/AVX/avx2/avx2sdk/inc",
  981. "xplat/AVX/avx2/avx2sdk/inc" };
  982. for (auto* path : p)
  983. searchPaths.add (createRebasedPath (rtasFolder.getChildFile (path)));
  984. }
  985. return searchPaths;
  986. }
  987. String getBinaryNameWithSuffix (const MSVCBuildConfiguration& config, bool forceUnityPrefix) const
  988. {
  989. return config.getOutputFilename (getTargetSuffix(), true, forceUnityPrefix);
  990. }
  991. String getOutputFilePath (const MSVCBuildConfiguration& config, bool forceUnityPrefix) const
  992. {
  993. return getOwner().getOutDirFile (config, getBinaryNameWithSuffix (config, forceUnityPrefix));
  994. }
  995. StringArray getLibrarySearchPaths (const BuildConfiguration& config) const
  996. {
  997. auto librarySearchPaths = config.getLibrarySearchPaths();
  998. if (type != SharedCodeTarget)
  999. if (auto* shared = getOwner().getSharedCodeTarget())
  1000. librarySearchPaths.add (shared->getConfigTargetPath (config));
  1001. return librarySearchPaths;
  1002. }
  1003. String getExternalLibraries (const MSVCBuildConfiguration& config, const String& otherLibs) const
  1004. {
  1005. StringArray libraries;
  1006. if (otherLibs.isNotEmpty())
  1007. libraries.add (otherLibs);
  1008. auto moduleLibs = getOwner().getModuleLibs();
  1009. if (! moduleLibs.isEmpty())
  1010. libraries.addArray (moduleLibs);
  1011. if (type != SharedCodeTarget)
  1012. if (auto* shared = getOwner().getSharedCodeTarget())
  1013. libraries.add (shared->getBinaryNameWithSuffix (config, false));
  1014. return libraries.joinIntoString (";");
  1015. }
  1016. String getDelayLoadedDLLs() const
  1017. {
  1018. auto delayLoadedDLLs = getOwner().msvcDelayLoadedDLLs;
  1019. if (type == RTASPlugIn)
  1020. delayLoadedDLLs += "DAE.dll; DigiExt.dll; DSI.dll; PluginLib.dll; "
  1021. "DSPManager.dll; DSPManager.dll; DSPManagerClientLib.dll; RTASClientLib.dll";
  1022. return delayLoadedDLLs;
  1023. }
  1024. String getModuleDefinitions (const MSVCBuildConfiguration& config) const
  1025. {
  1026. auto moduleDefinitions = config.config [Ids::msvcModuleDefinitionFile].toString();
  1027. if (moduleDefinitions.isNotEmpty())
  1028. return moduleDefinitions;
  1029. if (type == RTASPlugIn)
  1030. {
  1031. auto& exp = getOwner();
  1032. auto moduleDefPath
  1033. = RelativePath (exp.getPathForModuleString ("juce_audio_plugin_client"), RelativePath::projectFolder)
  1034. .getChildFile ("juce_audio_plugin_client").getChildFile ("RTAS").getChildFile ("juce_RTAS_WinExports.def");
  1035. return prependDot (moduleDefPath.rebased (exp.getProject().getProjectFolder(),
  1036. exp.getTargetFolder(),
  1037. RelativePath::buildTargetFolder).toWindowsStyle());
  1038. }
  1039. return {};
  1040. }
  1041. File getVCProjFile() const { return getOwner().getProjectFile (getProjectFileSuffix(), getName()); }
  1042. File getVCProjFiltersFile() const { return getOwner().getProjectFile (getFiltersFileSuffix(), getName()); }
  1043. String createRebasedPath (const RelativePath& path) const { return getOwner().createRebasedPath (path); }
  1044. protected:
  1045. const MSVCProjectExporterBase& owner;
  1046. String projectGuid;
  1047. };
  1048. //==============================================================================
  1049. bool usesMMFiles() const override { return false; }
  1050. bool canCopeWithDuplicateFiles() override { return false; }
  1051. bool supportsUserDefinedConfigurations() const override { return true; }
  1052. bool isXcode() const override { return false; }
  1053. bool isVisualStudio() const override { return true; }
  1054. bool isCodeBlocks() const override { return false; }
  1055. bool isMakefile() const override { return false; }
  1056. bool isAndroidStudio() const override { return false; }
  1057. bool isCLion() const override { return false; }
  1058. bool isAndroid() const override { return false; }
  1059. bool isWindows() const override { return true; }
  1060. bool isLinux() const override { return false; }
  1061. bool isOSX() const override { return false; }
  1062. bool isiOS() const override { return false; }
  1063. bool supportsTargetType (ProjectType::Target::Type type) const override
  1064. {
  1065. switch (type)
  1066. {
  1067. case ProjectType::Target::StandalonePlugIn:
  1068. case ProjectType::Target::GUIApp:
  1069. case ProjectType::Target::ConsoleApp:
  1070. case ProjectType::Target::StaticLibrary:
  1071. case ProjectType::Target::SharedCodeTarget:
  1072. case ProjectType::Target::AggregateTarget:
  1073. case ProjectType::Target::VSTPlugIn:
  1074. case ProjectType::Target::VST3PlugIn:
  1075. case ProjectType::Target::AAXPlugIn:
  1076. case ProjectType::Target::RTASPlugIn:
  1077. case ProjectType::Target::UnityPlugIn:
  1078. case ProjectType::Target::DynamicLibrary:
  1079. return true;
  1080. default:
  1081. break;
  1082. }
  1083. return false;
  1084. }
  1085. //==============================================================================
  1086. RelativePath getManifestPath() const
  1087. {
  1088. auto path = manifestFileValue.get().toString();
  1089. return path.isEmpty() ? RelativePath()
  1090. : RelativePath (path, RelativePath::projectFolder);
  1091. }
  1092. //==============================================================================
  1093. bool launchProject() override
  1094. {
  1095. #if JUCE_WINDOWS
  1096. return getSLNFile().startAsProcess();
  1097. #else
  1098. return false;
  1099. #endif
  1100. }
  1101. bool canLaunchProject() override
  1102. {
  1103. #if JUCE_WINDOWS
  1104. return true;
  1105. #else
  1106. return false;
  1107. #endif
  1108. }
  1109. void createExporterProperties (PropertyListBuilder& props) override
  1110. {
  1111. props.add (new TextPropertyComponent (manifestFileValue, "Manifest file", 8192, false),
  1112. "Path to a manifest input file which should be linked into your binary (path is relative to jucer file).");
  1113. }
  1114. enum OptimisationLevel
  1115. {
  1116. optimisationOff = 1,
  1117. optimiseMinSize = 2,
  1118. optimiseFull = 3,
  1119. optimiseMaxSpeed = 4
  1120. };
  1121. //==============================================================================
  1122. void addPlatformSpecificSettingsForProjectType (const ProjectType& type) override
  1123. {
  1124. msvcExtraPreprocessorDefs.set ("_CRT_SECURE_NO_WARNINGS", "");
  1125. if (type.isCommandLineApp())
  1126. msvcExtraPreprocessorDefs.set("_CONSOLE", "");
  1127. callForAllSupportedTargets ([this] (ProjectType::Target::Type targetType)
  1128. {
  1129. if (MSVCTargetBase* target = new MSVCTargetBase (targetType, *this))
  1130. {
  1131. if (targetType != ProjectType::Target::AggregateTarget)
  1132. targets.add (target);
  1133. }
  1134. });
  1135. // If you hit this assert, you tried to generate a project for an exporter
  1136. // that does not support any of your targets!
  1137. jassert (targets.size() > 0);
  1138. }
  1139. const MSVCTargetBase* getSharedCodeTarget() const
  1140. {
  1141. for (auto target : targets)
  1142. if (target->type == ProjectType::Target::SharedCodeTarget)
  1143. return target;
  1144. return nullptr;
  1145. }
  1146. bool hasTarget (ProjectType::Target::Type type) const
  1147. {
  1148. for (auto target : targets)
  1149. if (target->type == type)
  1150. return true;
  1151. return false;
  1152. }
  1153. private:
  1154. //==============================================================================
  1155. String createRebasedPath (const RelativePath& path) const
  1156. {
  1157. auto rebasedPath = rebaseFromProjectFolderToBuildTarget (path).toWindowsStyle();
  1158. return getVisualStudioVersion() < 10 // (VS10 automatically adds escape characters to the quotes for this definition)
  1159. ? CppTokeniserFunctions::addEscapeChars (rebasedPath.quoted())
  1160. : CppTokeniserFunctions::addEscapeChars (rebasedPath).quoted();
  1161. }
  1162. protected:
  1163. //==============================================================================
  1164. mutable File rcFile, iconFile;
  1165. OwnedArray<MSVCTargetBase> targets;
  1166. ValueWithDefault IPPLibraryValue, platformToolsetValue, targetPlatformVersion, manifestFileValue;
  1167. File getProjectFile (const String& extension, const String& target) const
  1168. {
  1169. auto filename = project.getProjectFilenameRootString();
  1170. if (target.isNotEmpty())
  1171. filename += String ("_") + target.removeCharacters (" ");
  1172. return getTargetFolder().getChildFile (filename).withFileExtension (extension);
  1173. }
  1174. File getSLNFile() const { return getProjectFile (".sln", String()); }
  1175. static String prependIfNotAbsolute (const String& file, const char* prefix)
  1176. {
  1177. if (File::isAbsolutePath (file) || file.startsWithChar ('$'))
  1178. prefix = "";
  1179. return prefix + FileHelpers::windowsStylePath (file);
  1180. }
  1181. String getIntDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(IntDir)\\"); }
  1182. String getOutDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(OutDir)\\"); }
  1183. void updateOldSettings()
  1184. {
  1185. {
  1186. auto oldStylePrebuildCommand = getSettingString (Ids::prebuildCommand);
  1187. settings.removeProperty (Ids::prebuildCommand, nullptr);
  1188. if (oldStylePrebuildCommand.isNotEmpty())
  1189. for (ConfigIterator config (*this); config.next();)
  1190. dynamic_cast<MSVCBuildConfiguration&> (*config).getValue (Ids::prebuildCommand) = oldStylePrebuildCommand;
  1191. }
  1192. {
  1193. auto oldStyleLibName = getSettingString ("libraryName_Debug");
  1194. settings.removeProperty ("libraryName_Debug", nullptr);
  1195. if (oldStyleLibName.isNotEmpty())
  1196. for (ConfigIterator config (*this); config.next();)
  1197. if (config->isDebug())
  1198. config->getValue (Ids::targetName) = oldStyleLibName;
  1199. }
  1200. {
  1201. auto oldStyleLibName = getSettingString ("libraryName_Release");
  1202. settings.removeProperty ("libraryName_Release", nullptr);
  1203. if (oldStyleLibName.isNotEmpty())
  1204. for (ConfigIterator config (*this); config.next();)
  1205. if (! config->isDebug())
  1206. config->getValue (Ids::targetName) = oldStyleLibName;
  1207. }
  1208. }
  1209. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  1210. {
  1211. return *new MSVCBuildConfiguration (project, v, *this);
  1212. }
  1213. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  1214. {
  1215. auto searchPaths = extraSearchPaths;
  1216. searchPaths.addArray (config.getHeaderSearchPaths());
  1217. return getCleanedStringArray (searchPaths);
  1218. }
  1219. String getSharedCodeGuid() const
  1220. {
  1221. String sharedCodeGuid;
  1222. for (int i = 0; i < targets.size(); ++i)
  1223. if (auto* target = targets[i])
  1224. if (target->type == ProjectType::Target::SharedCodeTarget)
  1225. return target->getProjectGuid();
  1226. return {};
  1227. }
  1228. //==============================================================================
  1229. void writeProjectDependencies (OutputStream& out) const
  1230. {
  1231. auto sharedCodeGuid = getSharedCodeGuid();
  1232. for (int addingOtherTargets = 0; addingOtherTargets < (sharedCodeGuid.isNotEmpty() ? 2 : 1); ++addingOtherTargets)
  1233. {
  1234. for (int i = 0; i < targets.size(); ++i)
  1235. {
  1236. if (auto* target = targets[i])
  1237. {
  1238. if (sharedCodeGuid.isEmpty() || (addingOtherTargets != 0) == (target->type != ProjectType::Target::StandalonePlugIn))
  1239. {
  1240. out << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" << projectName << " - "
  1241. << target->getName() << "\", \""
  1242. << target->getVCProjFile().getFileName() << "\", \"" << target->getProjectGuid() << '"' << newLine;
  1243. if (sharedCodeGuid.isNotEmpty() && target->type != ProjectType::Target::SharedCodeTarget)
  1244. out << "\tProjectSection(ProjectDependencies) = postProject" << newLine
  1245. << "\t\t" << sharedCodeGuid << " = " << sharedCodeGuid << newLine
  1246. << "\tEndProjectSection" << newLine;
  1247. out << "EndProject" << newLine;
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString) const
  1254. {
  1255. if (commentString.isNotEmpty())
  1256. commentString += newLine;
  1257. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  1258. << commentString << newLine;
  1259. writeProjectDependencies (out);
  1260. out << "Global" << newLine
  1261. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  1262. for (ConstConfigIterator i (*this); i.next();)
  1263. {
  1264. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1265. auto configName = config.createMSVCConfigName();
  1266. out << "\t\t" << configName << " = " << configName << newLine;
  1267. }
  1268. out << "\tEndGlobalSection" << newLine
  1269. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  1270. for (auto& target : targets)
  1271. for (ConstConfigIterator i (*this); i.next();)
  1272. {
  1273. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1274. auto configName = config.createMSVCConfigName();
  1275. for (auto& suffix : { "ActiveCfg", "Build.0" })
  1276. out << "\t\t" << target->getProjectGuid() << "." << configName << "." << suffix << " = " << configName << newLine;
  1277. }
  1278. out << "\tEndGlobalSection" << newLine
  1279. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  1280. << "\t\tHideSolutionNode = FALSE" << newLine
  1281. << "\tEndGlobalSection" << newLine;
  1282. out << "EndGlobal" << newLine;
  1283. }
  1284. //==============================================================================
  1285. static void writeBMPImage (const Image& image, const int w, const int h, MemoryOutputStream& out)
  1286. {
  1287. int maskStride = (w / 8 + 3) & ~3;
  1288. out.writeInt (40); // bitmapinfoheader size
  1289. out.writeInt (w);
  1290. out.writeInt (h * 2);
  1291. out.writeShort (1); // planes
  1292. out.writeShort (32); // bits
  1293. out.writeInt (0); // compression
  1294. out.writeInt ((h * w * 4) + (h * maskStride)); // size image
  1295. out.writeInt (0); // x pixels per meter
  1296. out.writeInt (0); // y pixels per meter
  1297. out.writeInt (0); // clr used
  1298. out.writeInt (0); // clr important
  1299. Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  1300. int alphaThreshold = 5;
  1301. int y;
  1302. for (y = h; --y >= 0;)
  1303. {
  1304. for (int x = 0; x < w; ++x)
  1305. {
  1306. auto pixel = bitmap.getPixelColour (x, y);
  1307. if (pixel.getAlpha() <= alphaThreshold)
  1308. {
  1309. out.writeInt (0);
  1310. }
  1311. else
  1312. {
  1313. out.writeByte ((char) pixel.getBlue());
  1314. out.writeByte ((char) pixel.getGreen());
  1315. out.writeByte ((char) pixel.getRed());
  1316. out.writeByte ((char) pixel.getAlpha());
  1317. }
  1318. }
  1319. }
  1320. for (y = h; --y >= 0;)
  1321. {
  1322. int mask = 0, count = 0;
  1323. for (int x = 0; x < w; ++x)
  1324. {
  1325. auto pixel = bitmap.getPixelColour (x, y);
  1326. mask <<= 1;
  1327. if (pixel.getAlpha() <= alphaThreshold)
  1328. mask |= 1;
  1329. if (++count == 8)
  1330. {
  1331. out.writeByte ((char) mask);
  1332. count = 0;
  1333. mask = 0;
  1334. }
  1335. }
  1336. if (mask != 0)
  1337. out.writeByte ((char) mask);
  1338. for (int i = maskStride - w / 8; --i >= 0;)
  1339. out.writeByte (0);
  1340. }
  1341. }
  1342. static void writeIconFile (const Array<Image>& images, MemoryOutputStream& out)
  1343. {
  1344. out.writeShort (0); // reserved
  1345. out.writeShort (1); // .ico tag
  1346. out.writeShort ((short) images.size());
  1347. MemoryOutputStream dataBlock;
  1348. int imageDirEntrySize = 16;
  1349. int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  1350. for (int i = 0; i < images.size(); ++i)
  1351. {
  1352. auto oldDataSize = dataBlock.getDataSize();
  1353. auto& image = images.getReference (i);
  1354. auto w = image.getWidth();
  1355. auto h = image.getHeight();
  1356. if (w >= 256 || h >= 256)
  1357. {
  1358. PNGImageFormat pngFormat;
  1359. pngFormat.writeImageToStream (image, dataBlock);
  1360. }
  1361. else
  1362. {
  1363. writeBMPImage (image, w, h, dataBlock);
  1364. }
  1365. out.writeByte ((char) w);
  1366. out.writeByte ((char) h);
  1367. out.writeByte (0);
  1368. out.writeByte (0);
  1369. out.writeShort (1); // colour planes
  1370. out.writeShort (32); // bits per pixel
  1371. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  1372. out.writeInt (dataBlockStart + (int) oldDataSize);
  1373. }
  1374. jassert (out.getPosition() == dataBlockStart);
  1375. out << dataBlock;
  1376. }
  1377. bool hasResourceFile() const
  1378. {
  1379. return ! projectType.isStaticLibrary();
  1380. }
  1381. void createResourcesAndIcon() const
  1382. {
  1383. if (hasResourceFile())
  1384. {
  1385. Array<Image> images;
  1386. int sizes[] = { 16, 32, 48, 256 };
  1387. for (int i = 0; i < numElementsInArray (sizes); ++i)
  1388. {
  1389. auto im = getBestIconForSize (sizes[i], true);
  1390. if (im.isValid())
  1391. images.add (im);
  1392. }
  1393. if (images.size() > 0)
  1394. {
  1395. iconFile = getTargetFolder().getChildFile ("icon.ico");
  1396. MemoryOutputStream mo;
  1397. writeIconFile (images, mo);
  1398. overwriteFileIfDifferentOrThrow (iconFile, mo);
  1399. }
  1400. createRCFile();
  1401. }
  1402. }
  1403. void createRCFile() const
  1404. {
  1405. rcFile = getTargetFolder().getChildFile ("resources.rc");
  1406. auto version = project.getVersionString();
  1407. MemoryOutputStream mo;
  1408. mo << "#ifdef JUCE_USER_DEFINED_RC_FILE" << newLine
  1409. << " #include JUCE_USER_DEFINED_RC_FILE" << newLine
  1410. << "#else" << newLine
  1411. << newLine
  1412. << "#undef WIN32_LEAN_AND_MEAN" << newLine
  1413. << "#define WIN32_LEAN_AND_MEAN" << newLine
  1414. << "#include <windows.h>" << newLine
  1415. << newLine
  1416. << "VS_VERSION_INFO VERSIONINFO" << newLine
  1417. << "FILEVERSION " << getCommaSeparatedVersionNumber (version) << newLine
  1418. << "BEGIN" << newLine
  1419. << " BLOCK \"StringFileInfo\"" << newLine
  1420. << " BEGIN" << newLine
  1421. << " BLOCK \"040904E4\"" << newLine
  1422. << " BEGIN" << newLine;
  1423. writeRCValue (mo, "CompanyName", project.getCompanyNameString());
  1424. writeRCValue (mo, "LegalCopyright", project.getCompanyCopyrightString());
  1425. writeRCValue (mo, "FileDescription", project.getProjectNameString());
  1426. writeRCValue (mo, "FileVersion", version);
  1427. writeRCValue (mo, "ProductName", project.getProjectNameString());
  1428. writeRCValue (mo, "ProductVersion", version);
  1429. mo << " END" << newLine
  1430. << " END" << newLine
  1431. << newLine
  1432. << " BLOCK \"VarFileInfo\"" << newLine
  1433. << " BEGIN" << newLine
  1434. << " VALUE \"Translation\", 0x409, 1252" << newLine
  1435. << " END" << newLine
  1436. << "END" << newLine
  1437. << newLine
  1438. << "#endif" << newLine;
  1439. if (iconFile != File())
  1440. mo << newLine
  1441. << "IDI_ICON1 ICON DISCARDABLE " << iconFile.getFileName().quoted()
  1442. << newLine
  1443. << "IDI_ICON2 ICON DISCARDABLE " << iconFile.getFileName().quoted();
  1444. overwriteFileIfDifferentOrThrow (rcFile, mo);
  1445. }
  1446. static void writeRCValue (MemoryOutputStream& mo, const String& name, const String& value)
  1447. {
  1448. if (value.isNotEmpty())
  1449. mo << " VALUE \"" << name << "\", \""
  1450. << CppTokeniserFunctions::addEscapeChars (value) << "\\0\"" << newLine;
  1451. }
  1452. static String getCommaSeparatedVersionNumber (const String& version)
  1453. {
  1454. auto versionParts = StringArray::fromTokens (version, ",.", "");
  1455. versionParts.trim();
  1456. versionParts.removeEmptyStrings();
  1457. while (versionParts.size() < 4)
  1458. versionParts.add ("0");
  1459. return versionParts.joinIntoString (",");
  1460. }
  1461. static String prependDot (const String& filename)
  1462. {
  1463. return FileHelpers::isAbsolutePath (filename) ? filename
  1464. : (".\\" + filename);
  1465. }
  1466. static bool shouldUseStdCall (const RelativePath& path)
  1467. {
  1468. return path.getFileNameWithoutExtension().startsWithIgnoreCase ("include_juce_audio_plugin_client_RTAS_");
  1469. }
  1470. StringArray getModuleLibs() const
  1471. {
  1472. StringArray result;
  1473. for (auto& lib : windowsLibs)
  1474. result.add (lib + ".lib");
  1475. return result;
  1476. }
  1477. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase)
  1478. };
  1479. //==============================================================================
  1480. class MSVCProjectExporterVC2013 : public MSVCProjectExporterBase
  1481. {
  1482. public:
  1483. MSVCProjectExporterVC2013 (Project& p, const ValueTree& t)
  1484. : MSVCProjectExporterBase (p, t, getTargetFolderForExporter (getValueTreeTypeName()))
  1485. {
  1486. name = getName();
  1487. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1488. platformToolsetValue.setDefault (getDefaultToolset());
  1489. }
  1490. static const char* getName() { return "Visual Studio 2013"; }
  1491. static const char* getValueTreeTypeName() { return "VS2013"; }
  1492. int getVisualStudioVersion() const override { return 12; }
  1493. String getSolutionComment() const override { return "# Visual Studio 2013"; }
  1494. String getToolsVersion() const override { return "12.0"; }
  1495. String getDefaultToolset() const override { return "v120"; }
  1496. String getDefaultWindowsTargetPlatformVersion() const override { return "8.1"; }
  1497. static MSVCProjectExporterVC2013* createForSettings (Project& project, const ValueTree& settings)
  1498. {
  1499. if (settings.hasType (getValueTreeTypeName()))
  1500. return new MSVCProjectExporterVC2013 (project, settings);
  1501. return nullptr;
  1502. }
  1503. void createExporterProperties (PropertyListBuilder& props) override
  1504. {
  1505. MSVCProjectExporterBase::createExporterProperties (props);
  1506. static const char* toolsetNames[] = { "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1507. const var toolsets[] = { "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1508. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1509. addIPPLibraryProperty (props);
  1510. addWindowsTargetPlatformProperties (props);
  1511. }
  1512. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2013)
  1513. };
  1514. //==============================================================================
  1515. class MSVCProjectExporterVC2015 : public MSVCProjectExporterBase
  1516. {
  1517. public:
  1518. MSVCProjectExporterVC2015 (Project& p, const ValueTree& t)
  1519. : MSVCProjectExporterBase (p, t, getTargetFolderForExporter (getValueTreeTypeName()))
  1520. {
  1521. name = getName();
  1522. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1523. platformToolsetValue.setDefault (getDefaultToolset());
  1524. }
  1525. static const char* getName() { return "Visual Studio 2015"; }
  1526. static const char* getValueTreeTypeName() { return "VS2015"; }
  1527. int getVisualStudioVersion() const override { return 14; }
  1528. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1529. String getToolsVersion() const override { return "14.0"; }
  1530. String getDefaultToolset() const override { return "v140"; }
  1531. String getDefaultWindowsTargetPlatformVersion() const override { return "8.1"; }
  1532. static MSVCProjectExporterVC2015* createForSettings (Project& project, const ValueTree& settings)
  1533. {
  1534. if (settings.hasType (getValueTreeTypeName()))
  1535. return new MSVCProjectExporterVC2015 (project, settings);
  1536. return nullptr;
  1537. }
  1538. void createExporterProperties (PropertyListBuilder& props) override
  1539. {
  1540. MSVCProjectExporterBase::createExporterProperties (props);
  1541. static const char* toolsetNames[] = { "v140", "v140_xp", "CTP_Nov2013" };
  1542. const var toolsets[] = { "v140", "v140_xp", "CTP_Nov2013" };
  1543. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1544. addIPPLibraryProperty (props);
  1545. addWindowsTargetPlatformProperties (props);
  1546. }
  1547. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1548. };
  1549. //==============================================================================
  1550. class MSVCProjectExporterVC2017 : public MSVCProjectExporterBase
  1551. {
  1552. public:
  1553. MSVCProjectExporterVC2017 (Project& p, const ValueTree& t)
  1554. : MSVCProjectExporterBase (p, t, getTargetFolderForExporter (getValueTreeTypeName()))
  1555. {
  1556. name = getName();
  1557. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1558. platformToolsetValue.setDefault (getDefaultToolset());
  1559. }
  1560. static const char* getName() { return "Visual Studio 2017"; }
  1561. static const char* getValueTreeTypeName() { return "VS2017"; }
  1562. int getVisualStudioVersion() const override { return 15; }
  1563. String getSolutionComment() const override { return "# Visual Studio 2017"; }
  1564. String getToolsVersion() const override { return "15.0"; }
  1565. String getDefaultToolset() const override { return "v141"; }
  1566. String getDefaultWindowsTargetPlatformVersion() const override { return "10.0.16299.0"; }
  1567. static MSVCProjectExporterVC2017* createForSettings (Project& project, const ValueTree& settings)
  1568. {
  1569. if (settings.hasType (getValueTreeTypeName()))
  1570. return new MSVCProjectExporterVC2017 (project, settings);
  1571. return nullptr;
  1572. }
  1573. void createExporterProperties (PropertyListBuilder& props) override
  1574. {
  1575. MSVCProjectExporterBase::createExporterProperties (props);
  1576. static const char* toolsetNames[] = { "v140", "v140_xp", "v141", "v141_xp" };
  1577. const var toolsets[] = { "v140", "v140_xp", "v141", "v141_xp" };
  1578. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1579. addIPPLibraryProperty (props);
  1580. addWindowsTargetPlatformProperties (props);
  1581. }
  1582. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2017)
  1583. };