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.

1984 lines
93KB

  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. if (config.is64Bit())
  352. e->createNewChildElement ("PlatformToolset")->addTextElement (getOwner().getPlatformToolset());
  353. }
  354. {
  355. auto* e = projectXml.createNewChildElement ("Import");
  356. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  357. }
  358. {
  359. auto* e = projectXml.createNewChildElement ("ImportGroup");
  360. e->setAttribute ("Label", "ExtensionSettings");
  361. }
  362. {
  363. auto* e = projectXml.createNewChildElement ("ImportGroup");
  364. e->setAttribute ("Label", "PropertySheets");
  365. auto* p = e->createNewChildElement ("Import");
  366. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  367. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  368. p->setAttribute ("Label", "LocalAppDataPlatform");
  369. }
  370. {
  371. auto* e = projectXml.createNewChildElement ("PropertyGroup");
  372. e->setAttribute ("Label", "UserMacros");
  373. }
  374. {
  375. auto* props = projectXml.createNewChildElement ("PropertyGroup");
  376. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  377. props->createNewChildElement ("TargetExt")->addTextElement (getTargetSuffix());
  378. for (ConstConfigIterator i (owner); i.next();)
  379. {
  380. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  381. if (getConfigTargetPath (config).isNotEmpty())
  382. {
  383. auto* outdir = props->createNewChildElement ("OutDir");
  384. setConditionAttribute (*outdir, config);
  385. outdir->addTextElement (FileHelpers::windowsStylePath (getConfigTargetPath (config)) + "\\");
  386. }
  387. {
  388. auto* intdir = props->createNewChildElement("IntDir");
  389. setConditionAttribute (*intdir, config);
  390. auto intermediatesPath = getIntermediatesPath (config);
  391. if (! intermediatesPath.endsWithChar (L'\\'))
  392. intermediatesPath += L'\\';
  393. intdir->addTextElement (FileHelpers::windowsStylePath (intermediatesPath));
  394. }
  395. {
  396. auto* targetName = props->createNewChildElement ("TargetName");
  397. setConditionAttribute (*targetName, config);
  398. targetName->addTextElement (config.getOutputFilename ("", false, type == UnityPlugIn));
  399. }
  400. {
  401. auto* manifest = props->createNewChildElement ("GenerateManifest");
  402. setConditionAttribute (*manifest, config);
  403. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  404. }
  405. if (type != SharedCodeTarget)
  406. {
  407. auto librarySearchPaths = getLibrarySearchPaths (config);
  408. if (librarySearchPaths.size() > 0)
  409. {
  410. auto* libPath = props->createNewChildElement ("LibraryPath");
  411. setConditionAttribute (*libPath, config);
  412. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  413. }
  414. }
  415. }
  416. }
  417. for (ConstConfigIterator i (owner); i.next();)
  418. {
  419. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  420. bool isDebug = config.isDebug();
  421. auto* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  422. setConditionAttribute (*group, config);
  423. {
  424. auto* midl = group->createNewChildElement ("Midl");
  425. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  426. : "NDEBUG;%(PreprocessorDefinitions)");
  427. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  428. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  429. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  430. midl->createNewChildElement ("HeaderFileName");
  431. }
  432. bool isUsingEditAndContinue = false;
  433. {
  434. auto* cl = group->createNewChildElement ("ClCompile");
  435. cl->createNewChildElement ("Optimization")->addTextElement (getOptimisationLevelString (config.getOptimisationLevelInt()));
  436. if (isDebug || config.shouldGenerateDebugSymbols())
  437. {
  438. cl->createNewChildElement ("DebugInformationFormat")
  439. ->addTextElement (config.getDebugInformationFormatString());
  440. }
  441. auto includePaths = getOwner().getHeaderSearchPaths (config);
  442. includePaths.addArray (getExtraSearchPaths());
  443. includePaths.add ("%(AdditionalIncludeDirectories)");
  444. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  445. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  446. bool runtimeDLL = config.isUsingRuntimeLibDLL();
  447. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (runtimeDLL ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  448. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  449. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  450. cl->createNewChildElement ("PrecompiledHeader");
  451. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  452. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  453. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement ("$(IntDir)\\");
  454. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (config.getWarningLevel()));
  455. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  456. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  457. if (config.isFastMathEnabled())
  458. cl->createNewChildElement ("FloatingPointModel")->addTextElement ("Fast");
  459. auto extraFlags = getOwner().replacePreprocessorTokens (config, getOwner().getExtraCompilerFlagsString()).trim();
  460. if (extraFlags.isNotEmpty())
  461. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  462. if (config.areWarningsTreatedAsErrors())
  463. cl->createNewChildElement ("TreatWarningAsError")->addTextElement ("true");
  464. auto cppStandard = owner.project.getCppStandardString();
  465. if (cppStandard == "11") // VS doesn't support the C++11 flag so we have to bump it to C++14
  466. cppStandard = "14";
  467. else if (cppStandard == "17") // nor does it support the C++17 flag, so we'll just use latest for now until it's added
  468. cppStandard = "latest";
  469. cl->createNewChildElement ("LanguageStandard")->addTextElement ("stdcpp" + cppStandard);
  470. }
  471. {
  472. auto* res = group->createNewChildElement ("ResourceCompile");
  473. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  474. : "NDEBUG;%(PreprocessorDefinitions)");
  475. }
  476. auto externalLibraries = getExternalLibraries (config, getOwner().getExternalLibrariesString());
  477. auto additionalDependencies = type != SharedCodeTarget && externalLibraries.isNotEmpty()
  478. ? getOwner().replacePreprocessorTokens (config, externalLibraries).trim() + ";%(AdditionalDependencies)"
  479. : String();
  480. auto librarySearchPaths = config.getLibrarySearchPaths();
  481. auto additionalLibraryDirs = type != SharedCodeTarget && librarySearchPaths.size() > 0
  482. ? getOwner().replacePreprocessorTokens (config, librarySearchPaths.joinIntoString (";")) + ";%(AdditionalLibraryDirectories)"
  483. : String();
  484. {
  485. auto* link = group->createNewChildElement ("Link");
  486. link->createNewChildElement ("OutputFile")->addTextElement (getOutputFilePath (config, type == UnityPlugIn));
  487. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  488. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  489. : "%(IgnoreSpecificDefaultLibraries)");
  490. link->createNewChildElement ("GenerateDebugInformation")->addTextElement ((isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  491. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (getOwner().getIntDirFile (config, config.getOutputFilename (".pdb", true, type == UnityPlugIn)));
  492. link->createNewChildElement ("SubSystem")->addTextElement (type == ConsoleApp ? "Console" : "Windows");
  493. if (! config.is64Bit())
  494. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  495. if (isUsingEditAndContinue)
  496. link->createNewChildElement ("ImageHasSafeExceptionHandlers")->addTextElement ("false");
  497. if (! isDebug)
  498. {
  499. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  500. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  501. }
  502. if (additionalLibraryDirs.isNotEmpty())
  503. link->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (additionalLibraryDirs);
  504. link->createNewChildElement ("LargeAddressAware")->addTextElement ("true");
  505. if (additionalDependencies.isNotEmpty())
  506. link->createNewChildElement ("AdditionalDependencies")->addTextElement (additionalDependencies);
  507. auto extraLinkerOptions = getOwner().getExtraLinkerFlagsString();
  508. if (extraLinkerOptions.isNotEmpty())
  509. link->createNewChildElement ("AdditionalOptions")->addTextElement (getOwner().replacePreprocessorTokens (config, extraLinkerOptions).trim()
  510. + " %(AdditionalOptions)");
  511. auto delayLoadedDLLs = getDelayLoadedDLLs();
  512. if (delayLoadedDLLs.isNotEmpty())
  513. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (delayLoadedDLLs);
  514. auto moduleDefinitionsFile = getModuleDefinitions (config);
  515. if (moduleDefinitionsFile.isNotEmpty())
  516. link->createNewChildElement ("ModuleDefinitionFile")
  517. ->addTextElement (moduleDefinitionsFile);
  518. }
  519. {
  520. auto* bsc = group->createNewChildElement ("Bscmake");
  521. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  522. bsc->createNewChildElement ("OutputFile")->addTextElement (getOwner().getIntDirFile (config, config.getOutputFilename (".bsc", true, type == UnityPlugIn)));
  523. }
  524. if (type != SharedCodeTarget)
  525. {
  526. auto* lib = group->createNewChildElement ("Lib");
  527. if (additionalDependencies.isNotEmpty())
  528. lib->createNewChildElement ("AdditionalDependencies")->addTextElement (additionalDependencies);
  529. if (additionalLibraryDirs.isNotEmpty())
  530. lib->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (additionalLibraryDirs);
  531. }
  532. auto manifestFile = getOwner().getManifestPath();
  533. if (manifestFile.getRoot() != RelativePath::unknown)
  534. {
  535. auto* bsc = group->createNewChildElement ("Manifest");
  536. bsc->createNewChildElement ("AdditionalManifestFiles")
  537. ->addTextElement (manifestFile.rebased (getOwner().getProject().getFile().getParentDirectory(),
  538. getOwner().getTargetFolder(),
  539. RelativePath::buildTargetFolder).toWindowsStyle());
  540. }
  541. if (getTargetFileType() == staticLibrary && ! config.is64Bit())
  542. {
  543. auto* lib = group->createNewChildElement ("Lib");
  544. lib->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  545. }
  546. auto preBuild = getPreBuildSteps (config);
  547. if (preBuild.isNotEmpty())
  548. group->createNewChildElement ("PreBuildEvent")
  549. ->createNewChildElement ("Command")
  550. ->addTextElement (preBuild);
  551. auto postBuild = getPostBuildSteps (config);
  552. if (postBuild.isNotEmpty())
  553. group->createNewChildElement ("PostBuildEvent")
  554. ->createNewChildElement ("Command")
  555. ->addTextElement (postBuild);
  556. }
  557. std::unique_ptr<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  558. {
  559. auto* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  560. auto* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  561. for (int i = 0; i < getOwner().getAllGroups().size(); ++i)
  562. {
  563. auto& group = getOwner().getAllGroups().getReference (i);
  564. if (group.getNumChildren() > 0)
  565. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  566. }
  567. }
  568. if (getOwner().iconFile != File())
  569. {
  570. auto* e = otherFilesGroup->createNewChildElement ("None");
  571. e->setAttribute ("Include", prependDot (getOwner().iconFile.getFileName()));
  572. }
  573. if (otherFilesGroup->getFirstChildElement() != nullptr)
  574. projectXml.addChildElement (otherFilesGroup.release());
  575. if (type != SharedCodeTarget && getOwner().hasResourceFile())
  576. {
  577. auto* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  578. auto* e = rcGroup->createNewChildElement ("ResourceCompile");
  579. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  580. }
  581. {
  582. auto* e = projectXml.createNewChildElement ("Import");
  583. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  584. }
  585. {
  586. auto* e = projectXml.createNewChildElement ("ImportGroup");
  587. e->setAttribute ("Label", "ExtensionTargets");
  588. }
  589. getOwner().addPlatformToolsetToPropertyGroup (projectXml);
  590. getOwner().addWindowsTargetPlatformVersionToPropertyGroup (projectXml);
  591. getOwner().addIPPSettingToPropertyGroup (projectXml);
  592. }
  593. String getProjectType() const
  594. {
  595. switch (getTargetFileType())
  596. {
  597. case executable:
  598. return "Application";
  599. case staticLibrary:
  600. return "StaticLibrary";
  601. default:
  602. break;
  603. }
  604. return "DynamicLibrary";
  605. }
  606. //==============================================================================
  607. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  608. {
  609. auto targetType = (getOwner().getProject().getProjectType().isAudioPlugin() ? type : SharedCodeTarget);
  610. if (projectItem.isGroup())
  611. {
  612. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  613. addFilesToCompile (projectItem.getChild (i), cpps, headers, otherFiles);
  614. }
  615. else if (projectItem.shouldBeAddedToTargetProject()
  616. && getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType)
  617. {
  618. RelativePath path (projectItem.getFile(), getOwner().getTargetFolder(), RelativePath::buildTargetFolder);
  619. jassert (path.getRoot() == RelativePath::buildTargetFolder);
  620. if (path.hasFileExtension (cOrCppFileExtensions) || path.hasFileExtension (asmFileExtensions))
  621. {
  622. if (targetType == SharedCodeTarget || projectItem.shouldBeCompiled())
  623. {
  624. auto* e = cpps.createNewChildElement ("ClCompile");
  625. e->setAttribute ("Include", path.toWindowsStyle());
  626. if (shouldUseStdCall (path))
  627. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  628. if (! projectItem.shouldBeCompiled())
  629. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  630. }
  631. }
  632. else if (path.hasFileExtension (headerFileExtensions))
  633. {
  634. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  635. }
  636. else if (! path.hasFileExtension (objCFileExtensions))
  637. {
  638. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  639. }
  640. }
  641. }
  642. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  643. {
  644. auto& msvcConfig = dynamic_cast<const MSVCBuildConfiguration&> (config);
  645. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + msvcConfig.createMSVCConfigName() + "'");
  646. }
  647. //==============================================================================
  648. void addFilterGroup (XmlElement& groups, const String& path) const
  649. {
  650. auto* e = groups.createNewChildElement ("Filter");
  651. e->setAttribute ("Include", path);
  652. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  653. }
  654. void addFileToFilter (const RelativePath& file, const String& groupPath,
  655. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  656. {
  657. XmlElement* e = nullptr;
  658. if (file.hasFileExtension (headerFileExtensions))
  659. e = headers.createNewChildElement ("ClInclude");
  660. else if (file.hasFileExtension (sourceFileExtensions))
  661. e = cpps.createNewChildElement ("ClCompile");
  662. else
  663. e = otherFiles.createNewChildElement ("None");
  664. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  665. e->setAttribute ("Include", file.toWindowsStyle());
  666. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  667. }
  668. bool addFilesToFilter (const Project::Item& projectItem, const String& path,
  669. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  670. {
  671. auto targetType = (getOwner().getProject().getProjectType().isAudioPlugin() ? type : SharedCodeTarget);
  672. if (projectItem.isGroup())
  673. {
  674. bool filesWereAdded = false;
  675. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  676. if (addFilesToFilter (projectItem.getChild(i),
  677. (path.isEmpty() ? String() : (path + "\\")) + projectItem.getChild(i).getName(),
  678. cpps, headers, otherFiles, groups))
  679. filesWereAdded = true;
  680. if (filesWereAdded)
  681. addFilterGroup (groups, path);
  682. return filesWereAdded;
  683. }
  684. else if (projectItem.shouldBeAddedToTargetProject())
  685. {
  686. RelativePath relativePath (projectItem.getFile(), getOwner().getTargetFolder(), RelativePath::buildTargetFolder);
  687. jassert (relativePath.getRoot() == RelativePath::buildTargetFolder);
  688. if (getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType
  689. && (targetType == SharedCodeTarget || projectItem.shouldBeCompiled()))
  690. {
  691. addFileToFilter (relativePath, path.upToLastOccurrenceOf ("\\", false, false), cpps, headers, otherFiles);
  692. return true;
  693. }
  694. }
  695. return false;
  696. }
  697. bool addFilesToFilter (const Array<RelativePath>& files, const String& path,
  698. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups)
  699. {
  700. if (files.size() > 0)
  701. {
  702. addFilterGroup (groups, path);
  703. for (int i = 0; i < files.size(); ++i)
  704. addFileToFilter (files.getReference(i), path, cpps, headers, otherFiles);
  705. return true;
  706. }
  707. return false;
  708. }
  709. void fillInFiltersXml (XmlElement& filterXml) const
  710. {
  711. filterXml.setAttribute ("ToolsVersion", getOwner().getToolsVersion());
  712. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  713. auto* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  714. auto* cpps = filterXml.createNewChildElement ("ItemGroup");
  715. auto* headers = filterXml.createNewChildElement ("ItemGroup");
  716. std::unique_ptr<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  717. for (int i = 0; i < getOwner().getAllGroups().size(); ++i)
  718. {
  719. auto& group = getOwner().getAllGroups().getReference(i);
  720. if (group.getNumChildren() > 0)
  721. addFilesToFilter (group, group.getName(), *cpps, *headers, *otherFilesGroup, *groupsXml);
  722. }
  723. if (getOwner().iconFile.exists())
  724. {
  725. auto* e = otherFilesGroup->createNewChildElement ("None");
  726. e->setAttribute ("Include", prependDot (getOwner().iconFile.getFileName()));
  727. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  728. }
  729. if (otherFilesGroup->getFirstChildElement() != nullptr)
  730. filterXml.addChildElement (otherFilesGroup.release());
  731. if (type != SharedCodeTarget && getOwner().hasResourceFile())
  732. {
  733. auto* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  734. auto* e = rcGroup->createNewChildElement ("ResourceCompile");
  735. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  736. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  737. }
  738. }
  739. const MSVCProjectExporterBase& getOwner() const { return owner; }
  740. const String& getProjectGuid() const { return projectGuid; }
  741. //==============================================================================
  742. void writeProjectFile()
  743. {
  744. {
  745. XmlElement projectXml (getTopLevelXmlEntity());
  746. fillInProjectXml (projectXml);
  747. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  748. }
  749. {
  750. XmlElement filtersXml (getTopLevelXmlEntity());
  751. fillInFiltersXml (filtersXml);
  752. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "UTF-8", 100);
  753. }
  754. }
  755. String getSolutionTargetPath (const BuildConfiguration& config) const
  756. {
  757. auto binaryPath = config.getTargetBinaryRelativePathString().trim();
  758. if (binaryPath.isEmpty())
  759. return "$(SolutionDir)$(Platform)\\$(Configuration)";
  760. RelativePath binaryRelPath (binaryPath, RelativePath::projectFolder);
  761. if (binaryRelPath.isAbsolute())
  762. return binaryRelPath.toWindowsStyle();
  763. return prependDot (binaryRelPath.rebased (getOwner().projectFolder, getOwner().getTargetFolder(), RelativePath::buildTargetFolder)
  764. .toWindowsStyle());
  765. }
  766. String getConfigTargetPath (const BuildConfiguration& config) const
  767. {
  768. auto solutionTargetFolder = getSolutionTargetPath (config);
  769. return solutionTargetFolder + "\\" + getName();
  770. }
  771. String getIntermediatesPath (const MSVCBuildConfiguration& config) const
  772. {
  773. auto intDir = (config.getIntermediatesPathString().isNotEmpty() ? config.getIntermediatesPathString()
  774. : "$(Platform)\\$(Configuration)");
  775. if (! intDir.endsWithChar (L'\\'))
  776. intDir += L'\\';
  777. return intDir + getName();
  778. }
  779. static const char* getOptimisationLevelString (int level)
  780. {
  781. switch (level)
  782. {
  783. case optimiseMinSize: return "MinSpace";
  784. case optimiseMaxSpeed: return "MaxSpeed";
  785. case optimiseFull: return "Full";
  786. default: return "Disabled";
  787. }
  788. }
  789. String getTargetSuffix() const
  790. {
  791. auto fileType = getTargetFileType();
  792. switch (fileType)
  793. {
  794. case executable: return ".exe";
  795. case staticLibrary: return ".lib";
  796. case sharedLibraryOrDLL: return ".dll";
  797. case pluginBundle:
  798. switch (type)
  799. {
  800. case VST3PlugIn: return ".vst3";
  801. case AAXPlugIn: return ".aaxdll";
  802. case RTASPlugIn: return ".dpm";
  803. default: break;
  804. }
  805. return ".dll";
  806. default:
  807. break;
  808. }
  809. return {};
  810. }
  811. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  812. {
  813. auto* e = parent.createNewChildElement ("Tool");
  814. e->setAttribute ("Name", toolName);
  815. return e;
  816. }
  817. String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const
  818. {
  819. auto defines = getOwner().msvcExtraPreprocessorDefs;
  820. defines.set ("WIN32", "");
  821. defines.set ("_WINDOWS", "");
  822. if (config.isDebug())
  823. {
  824. defines.set ("DEBUG", "");
  825. defines.set ("_DEBUG", "");
  826. }
  827. else
  828. {
  829. defines.set ("NDEBUG", "");
  830. }
  831. defines = mergePreprocessorDefs (defines, getOwner().getAllPreprocessorDefs (config, type));
  832. addExtraPreprocessorDefines (defines);
  833. if (getTargetFileType() == staticLibrary || getTargetFileType() == sharedLibraryOrDLL)
  834. defines.set("_LIB", "");
  835. StringArray result;
  836. for (int i = 0; i < defines.size(); ++i)
  837. {
  838. auto def = defines.getAllKeys()[i];
  839. auto value = defines.getAllValues()[i];
  840. if (value.isNotEmpty())
  841. def << "=" << value;
  842. result.add (def);
  843. }
  844. return result.joinIntoString (joinString);
  845. }
  846. //==============================================================================
  847. RelativePath getAAXIconFile() const
  848. {
  849. RelativePath aaxSDK (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder);
  850. RelativePath projectIcon ("icon.ico", RelativePath::buildTargetFolder);
  851. if (getOwner().getTargetFolder().getChildFile ("icon.ico").existsAsFile())
  852. return projectIcon.rebased (getOwner().getTargetFolder(),
  853. getOwner().getProject().getProjectFolder(),
  854. RelativePath::projectFolder);
  855. return aaxSDK.getChildFile ("Utilities").getChildFile ("PlugIn.ico");
  856. }
  857. String getExtraPostBuildSteps (const MSVCBuildConfiguration& config) const
  858. {
  859. if (type == AAXPlugIn)
  860. {
  861. RelativePath aaxSDK (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder);
  862. RelativePath aaxLibsFolder = aaxSDK.getChildFile ("Libs");
  863. RelativePath bundleScript = aaxSDK.getChildFile ("Utilities").getChildFile ("CreatePackage.bat");
  864. RelativePath iconFilePath = getAAXIconFile();
  865. auto outputFilename = config.getOutputFilename (".aaxplugin", true, false);
  866. auto bundleDir = getOwner().getOutDirFile (config, outputFilename);
  867. auto bundleContents = bundleDir + "\\Contents";
  868. auto archDir = bundleContents + String ("\\") + (config.is64Bit() ? "x64" : "Win32");
  869. auto executable = archDir + String ("\\") + outputFilename;
  870. auto pkgScript = String ("copy /Y ") + getOutputFilePath (config, false).quoted() + String (" ") + executable.quoted() + String ("\r\ncall ")
  871. + createRebasedPath (bundleScript) + String (" ") + archDir.quoted() + String (" ") + createRebasedPath (iconFilePath);
  872. if (config.isPluginBinaryCopyStepEnabled())
  873. return pkgScript + "\r\n" + "xcopy " + bundleDir.quoted() + " "
  874. + String (config.getAAXBinaryLocationString() + "\\" + outputFilename + "\\").quoted() + " /E /H /K /R /Y";
  875. return pkgScript;
  876. }
  877. else if (type == UnityPlugIn)
  878. {
  879. RelativePath scriptPath (config.project.getGeneratedCodeFolder().getChildFile (config.project.getUnityScriptName()),
  880. getOwner().getTargetFolder(),
  881. RelativePath::projectFolder);
  882. auto pkgScript = String ("copy /Y ") + scriptPath.toWindowsStyle().quoted() + " \"$(OutDir)\"";
  883. if (config.isPluginBinaryCopyStepEnabled())
  884. {
  885. auto copyLocation = config.getUnityPluginBinaryLocationString();
  886. pkgScript += "\r\ncopy /Y \"$(OutDir)$(TargetFileName)\" " + String (copyLocation + "\\$(TargetFileName)").quoted();
  887. pkgScript += "\r\ncopy /Y " + String ("$(OutDir)" + config.project.getUnityScriptName()).quoted() + " " + String (copyLocation + "\\" + config.project.getUnityScriptName()).quoted();
  888. }
  889. return pkgScript;
  890. }
  891. else if (config.isPluginBinaryCopyStepEnabled())
  892. {
  893. auto copyScript = String ("copy /Y \"$(OutDir)$(TargetFileName)\"") + String (" \"$COPYDIR$\\$(TargetFileName)\"");
  894. if (type == VSTPlugIn) return copyScript.replace ("$COPYDIR$", config.getVSTBinaryLocationString());
  895. if (type == VST3PlugIn) return copyScript.replace ("$COPYDIR$", config.getVST3BinaryLocationString());
  896. if (type == RTASPlugIn) return copyScript.replace ("$COPYDIR$", config.getRTASBinaryLocationString());
  897. }
  898. return {};
  899. }
  900. String getExtraPreBuildSteps (const MSVCBuildConfiguration& config) const
  901. {
  902. if (type == AAXPlugIn)
  903. {
  904. String script;
  905. auto bundleDir = getOwner().getOutDirFile (config, config.getOutputFilename (".aaxplugin", false, false));
  906. auto bundleContents = bundleDir + "\\Contents";
  907. auto archDir = bundleContents + String ("\\") + (config.is64Bit() ? "x64" : "Win32");
  908. for (auto& folder : StringArray { bundleDir, bundleContents, archDir })
  909. script += String ("if not exist \"") + folder + String ("\" mkdir \"") + folder + String ("\"\r\n");
  910. return script;
  911. }
  912. return {};
  913. }
  914. String getPostBuildSteps (const MSVCBuildConfiguration& config) const
  915. {
  916. auto postBuild = config.getPostbuildCommandString();
  917. auto extraPostBuild = getExtraPostBuildSteps (config);
  918. return postBuild + String (postBuild.isNotEmpty() && extraPostBuild.isNotEmpty() ? "\r\n" : "") + extraPostBuild;
  919. }
  920. String getPreBuildSteps (const MSVCBuildConfiguration& config) const
  921. {
  922. auto preBuild = config.getPrebuildCommandString();
  923. auto extraPreBuild = getExtraPreBuildSteps (config);
  924. return preBuild + String (preBuild.isNotEmpty() && extraPreBuild.isNotEmpty() ? "\r\n" : "") + extraPreBuild;
  925. }
  926. void addExtraPreprocessorDefines (StringPairArray& defines) const
  927. {
  928. switch (type)
  929. {
  930. case AAXPlugIn:
  931. {
  932. auto aaxLibsFolder = RelativePath (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder).getChildFile ("Libs");
  933. defines.set ("JucePlugin_AAXLibs_path", createRebasedPath (aaxLibsFolder));
  934. }
  935. break;
  936. case RTASPlugIn:
  937. {
  938. RelativePath rtasFolder (getOwner().getRTASPathValue().toString(), RelativePath::projectFolder);
  939. defines.set ("JucePlugin_WinBag_path", createRebasedPath (rtasFolder.getChildFile ("WinBag")));
  940. }
  941. break;
  942. default:
  943. break;
  944. }
  945. }
  946. String getExtraLinkerFlags() const
  947. {
  948. if (type == RTASPlugIn)
  949. return "/FORCE:multiple";
  950. return {};
  951. }
  952. StringArray getExtraSearchPaths() const
  953. {
  954. StringArray searchPaths;
  955. if (type == RTASPlugIn)
  956. {
  957. RelativePath rtasFolder (getOwner().getRTASPathValue().toString(), RelativePath::projectFolder);
  958. static const char* p[] = { "AlturaPorts/TDMPlugins/PluginLibrary/EffectClasses",
  959. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses",
  960. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses/Interfaces",
  961. "AlturaPorts/TDMPlugins/PluginLibrary/Utilities",
  962. "AlturaPorts/TDMPlugins/PluginLibrary/RTASP_Adapt",
  963. "AlturaPorts/TDMPlugins/PluginLibrary/CoreClasses",
  964. "AlturaPorts/TDMPlugins/PluginLibrary/Controls",
  965. "AlturaPorts/TDMPlugins/PluginLibrary/Meters",
  966. "AlturaPorts/TDMPlugins/PluginLibrary/ViewClasses",
  967. "AlturaPorts/TDMPlugins/PluginLibrary/DSPClasses",
  968. "AlturaPorts/TDMPlugins/PluginLibrary/Interfaces",
  969. "AlturaPorts/TDMPlugins/common",
  970. "AlturaPorts/TDMPlugins/common/Platform",
  971. "AlturaPorts/TDMPlugins/common/Macros",
  972. "AlturaPorts/TDMPlugins/SignalProcessing/Public",
  973. "AlturaPorts/TDMPlugIns/DSPManager/Interfaces",
  974. "AlturaPorts/SADriver/Interfaces",
  975. "AlturaPorts/DigiPublic/Interfaces",
  976. "AlturaPorts/DigiPublic",
  977. "AlturaPorts/Fic/Interfaces/DAEClient",
  978. "AlturaPorts/NewFileLibs/Cmn",
  979. "AlturaPorts/NewFileLibs/DOA",
  980. "AlturaPorts/AlturaSource/PPC_H",
  981. "AlturaPorts/AlturaSource/AppSupport",
  982. "AvidCode/AVX2sdk/AVX/avx2/avx2sdk/inc",
  983. "xplat/AVX/avx2/avx2sdk/inc" };
  984. for (auto* path : p)
  985. searchPaths.add (createRebasedPath (rtasFolder.getChildFile (path)));
  986. }
  987. return searchPaths;
  988. }
  989. String getBinaryNameWithSuffix (const MSVCBuildConfiguration& config, bool forceUnityPrefix) const
  990. {
  991. return config.getOutputFilename (getTargetSuffix(), true, forceUnityPrefix);
  992. }
  993. String getOutputFilePath (const MSVCBuildConfiguration& config, bool forceUnityPrefix) const
  994. {
  995. return getOwner().getOutDirFile (config, getBinaryNameWithSuffix (config, forceUnityPrefix));
  996. }
  997. StringArray getLibrarySearchPaths (const BuildConfiguration& config) const
  998. {
  999. auto librarySearchPaths = config.getLibrarySearchPaths();
  1000. if (type != SharedCodeTarget)
  1001. if (auto* shared = getOwner().getSharedCodeTarget())
  1002. librarySearchPaths.add (shared->getConfigTargetPath (config));
  1003. return librarySearchPaths;
  1004. }
  1005. String getExternalLibraries (const MSVCBuildConfiguration& config, const String& otherLibs) const
  1006. {
  1007. StringArray libraries;
  1008. if (otherLibs.isNotEmpty())
  1009. libraries.add (otherLibs);
  1010. auto moduleLibs = getOwner().getModuleLibs();
  1011. if (! moduleLibs.isEmpty())
  1012. libraries.addArray (moduleLibs);
  1013. if (type != SharedCodeTarget)
  1014. if (auto* shared = getOwner().getSharedCodeTarget())
  1015. libraries.add (shared->getBinaryNameWithSuffix (config, false));
  1016. return libraries.joinIntoString (";");
  1017. }
  1018. String getDelayLoadedDLLs() const
  1019. {
  1020. auto delayLoadedDLLs = getOwner().msvcDelayLoadedDLLs;
  1021. if (type == RTASPlugIn)
  1022. delayLoadedDLLs += "DAE.dll; DigiExt.dll; DSI.dll; PluginLib.dll; "
  1023. "DSPManager.dll; DSPManager.dll; DSPManagerClientLib.dll; RTASClientLib.dll";
  1024. return delayLoadedDLLs;
  1025. }
  1026. String getModuleDefinitions (const MSVCBuildConfiguration& config) const
  1027. {
  1028. auto moduleDefinitions = config.config [Ids::msvcModuleDefinitionFile].toString();
  1029. if (moduleDefinitions.isNotEmpty())
  1030. return moduleDefinitions;
  1031. if (type == RTASPlugIn)
  1032. {
  1033. auto& exp = getOwner();
  1034. auto moduleDefPath
  1035. = RelativePath (exp.getPathForModuleString ("juce_audio_plugin_client"), RelativePath::projectFolder)
  1036. .getChildFile ("juce_audio_plugin_client").getChildFile ("RTAS").getChildFile ("juce_RTAS_WinExports.def");
  1037. return prependDot (moduleDefPath.rebased (exp.getProject().getProjectFolder(),
  1038. exp.getTargetFolder(),
  1039. RelativePath::buildTargetFolder).toWindowsStyle());
  1040. }
  1041. return {};
  1042. }
  1043. File getVCProjFile() const { return getOwner().getProjectFile (getProjectFileSuffix(), getName()); }
  1044. File getVCProjFiltersFile() const { return getOwner().getProjectFile (getFiltersFileSuffix(), getName()); }
  1045. String createRebasedPath (const RelativePath& path) const { return getOwner().createRebasedPath (path); }
  1046. protected:
  1047. const MSVCProjectExporterBase& owner;
  1048. String projectGuid;
  1049. };
  1050. //==============================================================================
  1051. bool usesMMFiles() const override { return false; }
  1052. bool canCopeWithDuplicateFiles() override { return false; }
  1053. bool supportsUserDefinedConfigurations() const override { return true; }
  1054. bool isXcode() const override { return false; }
  1055. bool isVisualStudio() const override { return true; }
  1056. bool isCodeBlocks() const override { return false; }
  1057. bool isMakefile() const override { return false; }
  1058. bool isAndroidStudio() const override { return false; }
  1059. bool isCLion() const override { return false; }
  1060. bool isAndroid() const override { return false; }
  1061. bool isWindows() const override { return true; }
  1062. bool isLinux() const override { return false; }
  1063. bool isOSX() const override { return false; }
  1064. bool isiOS() const override { return false; }
  1065. bool supportsTargetType (ProjectType::Target::Type type) const override
  1066. {
  1067. switch (type)
  1068. {
  1069. case ProjectType::Target::StandalonePlugIn:
  1070. case ProjectType::Target::GUIApp:
  1071. case ProjectType::Target::ConsoleApp:
  1072. case ProjectType::Target::StaticLibrary:
  1073. case ProjectType::Target::SharedCodeTarget:
  1074. case ProjectType::Target::AggregateTarget:
  1075. case ProjectType::Target::VSTPlugIn:
  1076. case ProjectType::Target::VST3PlugIn:
  1077. case ProjectType::Target::AAXPlugIn:
  1078. case ProjectType::Target::RTASPlugIn:
  1079. case ProjectType::Target::UnityPlugIn:
  1080. case ProjectType::Target::DynamicLibrary:
  1081. return true;
  1082. default:
  1083. break;
  1084. }
  1085. return false;
  1086. }
  1087. //==============================================================================
  1088. RelativePath getManifestPath() const
  1089. {
  1090. auto path = manifestFileValue.get().toString();
  1091. return path.isEmpty() ? RelativePath()
  1092. : RelativePath (path, RelativePath::projectFolder);
  1093. }
  1094. //==============================================================================
  1095. bool launchProject() override
  1096. {
  1097. #if JUCE_WINDOWS
  1098. return getSLNFile().startAsProcess();
  1099. #else
  1100. return false;
  1101. #endif
  1102. }
  1103. bool canLaunchProject() override
  1104. {
  1105. #if JUCE_WINDOWS
  1106. return true;
  1107. #else
  1108. return false;
  1109. #endif
  1110. }
  1111. void createExporterProperties (PropertyListBuilder& props) override
  1112. {
  1113. props.add (new TextPropertyComponent (manifestFileValue, "Manifest file", 8192, false),
  1114. "Path to a manifest input file which should be linked into your binary (path is relative to jucer file).");
  1115. }
  1116. enum OptimisationLevel
  1117. {
  1118. optimisationOff = 1,
  1119. optimiseMinSize = 2,
  1120. optimiseFull = 3,
  1121. optimiseMaxSpeed = 4
  1122. };
  1123. //==============================================================================
  1124. void addPlatformSpecificSettingsForProjectType (const ProjectType& type) override
  1125. {
  1126. msvcExtraPreprocessorDefs.set ("_CRT_SECURE_NO_WARNINGS", "");
  1127. if (type.isCommandLineApp())
  1128. msvcExtraPreprocessorDefs.set("_CONSOLE", "");
  1129. callForAllSupportedTargets ([this] (ProjectType::Target::Type targetType)
  1130. {
  1131. if (MSVCTargetBase* target = new MSVCTargetBase (targetType, *this))
  1132. {
  1133. if (targetType != ProjectType::Target::AggregateTarget)
  1134. targets.add (target);
  1135. }
  1136. });
  1137. // If you hit this assert, you tried to generate a project for an exporter
  1138. // that does not support any of your targets!
  1139. jassert (targets.size() > 0);
  1140. }
  1141. const MSVCTargetBase* getSharedCodeTarget() const
  1142. {
  1143. for (auto target : targets)
  1144. if (target->type == ProjectType::Target::SharedCodeTarget)
  1145. return target;
  1146. return nullptr;
  1147. }
  1148. bool hasTarget (ProjectType::Target::Type type) const
  1149. {
  1150. for (auto target : targets)
  1151. if (target->type == type)
  1152. return true;
  1153. return false;
  1154. }
  1155. private:
  1156. //==============================================================================
  1157. String createRebasedPath (const RelativePath& path) const
  1158. {
  1159. auto rebasedPath = rebaseFromProjectFolderToBuildTarget (path).toWindowsStyle();
  1160. return getVisualStudioVersion() < 10 // (VS10 automatically adds escape characters to the quotes for this definition)
  1161. ? CppTokeniserFunctions::addEscapeChars (rebasedPath.quoted())
  1162. : CppTokeniserFunctions::addEscapeChars (rebasedPath).quoted();
  1163. }
  1164. protected:
  1165. //==============================================================================
  1166. mutable File rcFile, iconFile;
  1167. OwnedArray<MSVCTargetBase> targets;
  1168. ValueWithDefault IPPLibraryValue, platformToolsetValue, targetPlatformVersion, manifestFileValue;
  1169. File getProjectFile (const String& extension, const String& target) const
  1170. {
  1171. auto filename = project.getProjectFilenameRootString();
  1172. if (target.isNotEmpty())
  1173. filename += String ("_") + target.removeCharacters (" ");
  1174. return getTargetFolder().getChildFile (filename).withFileExtension (extension);
  1175. }
  1176. File getSLNFile() const { return getProjectFile (".sln", String()); }
  1177. static String prependIfNotAbsolute (const String& file, const char* prefix)
  1178. {
  1179. if (File::isAbsolutePath (file) || file.startsWithChar ('$'))
  1180. prefix = "";
  1181. return prefix + FileHelpers::windowsStylePath (file);
  1182. }
  1183. String getIntDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(IntDir)\\"); }
  1184. String getOutDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(OutDir)\\"); }
  1185. void updateOldSettings()
  1186. {
  1187. {
  1188. auto oldStylePrebuildCommand = getSettingString (Ids::prebuildCommand);
  1189. settings.removeProperty (Ids::prebuildCommand, nullptr);
  1190. if (oldStylePrebuildCommand.isNotEmpty())
  1191. for (ConfigIterator config (*this); config.next();)
  1192. dynamic_cast<MSVCBuildConfiguration&> (*config).getValue (Ids::prebuildCommand) = oldStylePrebuildCommand;
  1193. }
  1194. {
  1195. auto oldStyleLibName = getSettingString ("libraryName_Debug");
  1196. settings.removeProperty ("libraryName_Debug", nullptr);
  1197. if (oldStyleLibName.isNotEmpty())
  1198. for (ConfigIterator config (*this); config.next();)
  1199. if (config->isDebug())
  1200. config->getValue (Ids::targetName) = oldStyleLibName;
  1201. }
  1202. {
  1203. auto oldStyleLibName = getSettingString ("libraryName_Release");
  1204. settings.removeProperty ("libraryName_Release", nullptr);
  1205. if (oldStyleLibName.isNotEmpty())
  1206. for (ConfigIterator config (*this); config.next();)
  1207. if (! config->isDebug())
  1208. config->getValue (Ids::targetName) = oldStyleLibName;
  1209. }
  1210. }
  1211. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  1212. {
  1213. return new MSVCBuildConfiguration (project, v, *this);
  1214. }
  1215. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  1216. {
  1217. auto searchPaths = extraSearchPaths;
  1218. searchPaths.addArray (config.getHeaderSearchPaths());
  1219. return getCleanedStringArray (searchPaths);
  1220. }
  1221. String getSharedCodeGuid() const
  1222. {
  1223. String sharedCodeGuid;
  1224. for (int i = 0; i < targets.size(); ++i)
  1225. if (auto* target = targets[i])
  1226. if (target->type == ProjectType::Target::SharedCodeTarget)
  1227. return target->getProjectGuid();
  1228. return {};
  1229. }
  1230. //==============================================================================
  1231. void writeProjectDependencies (OutputStream& out) const
  1232. {
  1233. auto sharedCodeGuid = getSharedCodeGuid();
  1234. for (int addingOtherTargets = 0; addingOtherTargets < (sharedCodeGuid.isNotEmpty() ? 2 : 1); ++addingOtherTargets)
  1235. {
  1236. for (int i = 0; i < targets.size(); ++i)
  1237. {
  1238. if (auto* target = targets[i])
  1239. {
  1240. if (sharedCodeGuid.isEmpty() || (addingOtherTargets != 0) == (target->type != ProjectType::Target::StandalonePlugIn))
  1241. {
  1242. out << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" << projectName << " - "
  1243. << target->getName() << "\", \""
  1244. << target->getVCProjFile().getFileName() << "\", \"" << target->getProjectGuid() << '"' << newLine;
  1245. if (sharedCodeGuid.isNotEmpty() && target->type != ProjectType::Target::SharedCodeTarget)
  1246. out << "\tProjectSection(ProjectDependencies) = postProject" << newLine
  1247. << "\t\t" << sharedCodeGuid << " = " << sharedCodeGuid << newLine
  1248. << "\tEndProjectSection" << newLine;
  1249. out << "EndProject" << newLine;
  1250. }
  1251. }
  1252. }
  1253. }
  1254. }
  1255. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString) const
  1256. {
  1257. if (commentString.isNotEmpty())
  1258. commentString += newLine;
  1259. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  1260. << commentString << newLine;
  1261. writeProjectDependencies (out);
  1262. out << "Global" << newLine
  1263. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  1264. for (ConstConfigIterator i (*this); i.next();)
  1265. {
  1266. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1267. auto configName = config.createMSVCConfigName();
  1268. out << "\t\t" << configName << " = " << configName << newLine;
  1269. }
  1270. out << "\tEndGlobalSection" << newLine
  1271. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  1272. for (auto& target : targets)
  1273. for (ConstConfigIterator i (*this); i.next();)
  1274. {
  1275. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1276. auto configName = config.createMSVCConfigName();
  1277. for (auto& suffix : { "ActiveCfg", "Build.0" })
  1278. out << "\t\t" << target->getProjectGuid() << "." << configName << "." << suffix << " = " << configName << newLine;
  1279. }
  1280. out << "\tEndGlobalSection" << newLine
  1281. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  1282. << "\t\tHideSolutionNode = FALSE" << newLine
  1283. << "\tEndGlobalSection" << newLine;
  1284. out << "EndGlobal" << newLine;
  1285. }
  1286. //==============================================================================
  1287. static void writeBMPImage (const Image& image, const int w, const int h, MemoryOutputStream& out)
  1288. {
  1289. int maskStride = (w / 8 + 3) & ~3;
  1290. out.writeInt (40); // bitmapinfoheader size
  1291. out.writeInt (w);
  1292. out.writeInt (h * 2);
  1293. out.writeShort (1); // planes
  1294. out.writeShort (32); // bits
  1295. out.writeInt (0); // compression
  1296. out.writeInt ((h * w * 4) + (h * maskStride)); // size image
  1297. out.writeInt (0); // x pixels per meter
  1298. out.writeInt (0); // y pixels per meter
  1299. out.writeInt (0); // clr used
  1300. out.writeInt (0); // clr important
  1301. Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  1302. int alphaThreshold = 5;
  1303. int y;
  1304. for (y = h; --y >= 0;)
  1305. {
  1306. for (int x = 0; x < w; ++x)
  1307. {
  1308. auto pixel = bitmap.getPixelColour (x, y);
  1309. if (pixel.getAlpha() <= alphaThreshold)
  1310. {
  1311. out.writeInt (0);
  1312. }
  1313. else
  1314. {
  1315. out.writeByte ((char) pixel.getBlue());
  1316. out.writeByte ((char) pixel.getGreen());
  1317. out.writeByte ((char) pixel.getRed());
  1318. out.writeByte ((char) pixel.getAlpha());
  1319. }
  1320. }
  1321. }
  1322. for (y = h; --y >= 0;)
  1323. {
  1324. int mask = 0, count = 0;
  1325. for (int x = 0; x < w; ++x)
  1326. {
  1327. auto pixel = bitmap.getPixelColour (x, y);
  1328. mask <<= 1;
  1329. if (pixel.getAlpha() <= alphaThreshold)
  1330. mask |= 1;
  1331. if (++count == 8)
  1332. {
  1333. out.writeByte ((char) mask);
  1334. count = 0;
  1335. mask = 0;
  1336. }
  1337. }
  1338. if (mask != 0)
  1339. out.writeByte ((char) mask);
  1340. for (int i = maskStride - w / 8; --i >= 0;)
  1341. out.writeByte (0);
  1342. }
  1343. }
  1344. static void writeIconFile (const Array<Image>& images, MemoryOutputStream& out)
  1345. {
  1346. out.writeShort (0); // reserved
  1347. out.writeShort (1); // .ico tag
  1348. out.writeShort ((short) images.size());
  1349. MemoryOutputStream dataBlock;
  1350. int imageDirEntrySize = 16;
  1351. int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  1352. for (int i = 0; i < images.size(); ++i)
  1353. {
  1354. auto oldDataSize = dataBlock.getDataSize();
  1355. auto& image = images.getReference (i);
  1356. auto w = image.getWidth();
  1357. auto h = image.getHeight();
  1358. if (w >= 256 || h >= 256)
  1359. {
  1360. PNGImageFormat pngFormat;
  1361. pngFormat.writeImageToStream (image, dataBlock);
  1362. }
  1363. else
  1364. {
  1365. writeBMPImage (image, w, h, dataBlock);
  1366. }
  1367. out.writeByte ((char) w);
  1368. out.writeByte ((char) h);
  1369. out.writeByte (0);
  1370. out.writeByte (0);
  1371. out.writeShort (1); // colour planes
  1372. out.writeShort (32); // bits per pixel
  1373. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  1374. out.writeInt (dataBlockStart + (int) oldDataSize);
  1375. }
  1376. jassert (out.getPosition() == dataBlockStart);
  1377. out << dataBlock;
  1378. }
  1379. bool hasResourceFile() const
  1380. {
  1381. return ! projectType.isStaticLibrary();
  1382. }
  1383. void createResourcesAndIcon() const
  1384. {
  1385. if (hasResourceFile())
  1386. {
  1387. Array<Image> images;
  1388. int sizes[] = { 16, 32, 48, 256 };
  1389. for (int i = 0; i < numElementsInArray (sizes); ++i)
  1390. {
  1391. auto im = getBestIconForSize (sizes[i], true);
  1392. if (im.isValid())
  1393. images.add (im);
  1394. }
  1395. if (images.size() > 0)
  1396. {
  1397. iconFile = getTargetFolder().getChildFile ("icon.ico");
  1398. MemoryOutputStream mo;
  1399. writeIconFile (images, mo);
  1400. overwriteFileIfDifferentOrThrow (iconFile, mo);
  1401. }
  1402. createRCFile();
  1403. }
  1404. }
  1405. void createRCFile() const
  1406. {
  1407. rcFile = getTargetFolder().getChildFile ("resources.rc");
  1408. auto version = project.getVersionString();
  1409. MemoryOutputStream mo;
  1410. mo << "#ifdef JUCE_USER_DEFINED_RC_FILE" << newLine
  1411. << " #include JUCE_USER_DEFINED_RC_FILE" << newLine
  1412. << "#else" << newLine
  1413. << newLine
  1414. << "#undef WIN32_LEAN_AND_MEAN" << newLine
  1415. << "#define WIN32_LEAN_AND_MEAN" << newLine
  1416. << "#include <windows.h>" << newLine
  1417. << newLine
  1418. << "VS_VERSION_INFO VERSIONINFO" << newLine
  1419. << "FILEVERSION " << getCommaSeparatedVersionNumber (version) << newLine
  1420. << "BEGIN" << newLine
  1421. << " BLOCK \"StringFileInfo\"" << newLine
  1422. << " BEGIN" << newLine
  1423. << " BLOCK \"040904E4\"" << newLine
  1424. << " BEGIN" << newLine;
  1425. writeRCValue (mo, "CompanyName", project.getCompanyNameString());
  1426. writeRCValue (mo, "LegalCopyright", project.getCompanyCopyrightString());
  1427. writeRCValue (mo, "FileDescription", project.getProjectNameString());
  1428. writeRCValue (mo, "FileVersion", version);
  1429. writeRCValue (mo, "ProductName", project.getProjectNameString());
  1430. writeRCValue (mo, "ProductVersion", version);
  1431. mo << " END" << newLine
  1432. << " END" << newLine
  1433. << newLine
  1434. << " BLOCK \"VarFileInfo\"" << newLine
  1435. << " BEGIN" << newLine
  1436. << " VALUE \"Translation\", 0x409, 1252" << newLine
  1437. << " END" << newLine
  1438. << "END" << newLine
  1439. << newLine
  1440. << "#endif" << newLine;
  1441. if (iconFile != File())
  1442. mo << newLine
  1443. << "IDI_ICON1 ICON DISCARDABLE " << iconFile.getFileName().quoted()
  1444. << newLine
  1445. << "IDI_ICON2 ICON DISCARDABLE " << iconFile.getFileName().quoted();
  1446. overwriteFileIfDifferentOrThrow (rcFile, mo);
  1447. }
  1448. static void writeRCValue (MemoryOutputStream& mo, const String& name, const String& value)
  1449. {
  1450. if (value.isNotEmpty())
  1451. mo << " VALUE \"" << name << "\", \""
  1452. << CppTokeniserFunctions::addEscapeChars (value) << "\\0\"" << newLine;
  1453. }
  1454. static String getCommaSeparatedVersionNumber (const String& version)
  1455. {
  1456. auto versionParts = StringArray::fromTokens (version, ",.", "");
  1457. versionParts.trim();
  1458. versionParts.removeEmptyStrings();
  1459. while (versionParts.size() < 4)
  1460. versionParts.add ("0");
  1461. return versionParts.joinIntoString (",");
  1462. }
  1463. static String prependDot (const String& filename)
  1464. {
  1465. return FileHelpers::isAbsolutePath (filename) ? filename
  1466. : (".\\" + filename);
  1467. }
  1468. static bool shouldUseStdCall (const RelativePath& path)
  1469. {
  1470. return path.getFileNameWithoutExtension().startsWithIgnoreCase ("include_juce_audio_plugin_client_RTAS_");
  1471. }
  1472. StringArray getModuleLibs() const
  1473. {
  1474. StringArray result;
  1475. for (auto& lib : windowsLibs)
  1476. result.add (lib + ".lib");
  1477. return result;
  1478. }
  1479. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase)
  1480. };
  1481. //==============================================================================
  1482. class MSVCProjectExporterVC2013 : public MSVCProjectExporterBase
  1483. {
  1484. public:
  1485. MSVCProjectExporterVC2013 (Project& p, const ValueTree& t)
  1486. : MSVCProjectExporterBase (p, t, getTargetFolderForExporter (getValueTreeTypeName()))
  1487. {
  1488. name = getName();
  1489. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1490. platformToolsetValue.setDefault (getDefaultToolset());
  1491. }
  1492. static const char* getName() { return "Visual Studio 2013"; }
  1493. static const char* getValueTreeTypeName() { return "VS2013"; }
  1494. int getVisualStudioVersion() const override { return 12; }
  1495. String getSolutionComment() const override { return "# Visual Studio 2013"; }
  1496. String getToolsVersion() const override { return "12.0"; }
  1497. String getDefaultToolset() const override { return "v120"; }
  1498. String getDefaultWindowsTargetPlatformVersion() const override { return "8.1"; }
  1499. static MSVCProjectExporterVC2013* createForSettings (Project& project, const ValueTree& settings)
  1500. {
  1501. if (settings.hasType (getValueTreeTypeName()))
  1502. return new MSVCProjectExporterVC2013 (project, settings);
  1503. return nullptr;
  1504. }
  1505. void createExporterProperties (PropertyListBuilder& props) override
  1506. {
  1507. MSVCProjectExporterBase::createExporterProperties (props);
  1508. static const char* toolsetNames[] = { "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1509. const var toolsets[] = { "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1510. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1511. addIPPLibraryProperty (props);
  1512. addWindowsTargetPlatformProperties (props);
  1513. }
  1514. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2013)
  1515. };
  1516. //==============================================================================
  1517. class MSVCProjectExporterVC2015 : public MSVCProjectExporterBase
  1518. {
  1519. public:
  1520. MSVCProjectExporterVC2015 (Project& p, const ValueTree& t)
  1521. : MSVCProjectExporterBase (p, t, getTargetFolderForExporter (getValueTreeTypeName()))
  1522. {
  1523. name = getName();
  1524. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1525. platformToolsetValue.setDefault (getDefaultToolset());
  1526. }
  1527. static const char* getName() { return "Visual Studio 2015"; }
  1528. static const char* getValueTreeTypeName() { return "VS2015"; }
  1529. int getVisualStudioVersion() const override { return 14; }
  1530. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1531. String getToolsVersion() const override { return "14.0"; }
  1532. String getDefaultToolset() const override { return "v140"; }
  1533. String getDefaultWindowsTargetPlatformVersion() const override { return "8.1"; }
  1534. static MSVCProjectExporterVC2015* createForSettings (Project& project, const ValueTree& settings)
  1535. {
  1536. if (settings.hasType (getValueTreeTypeName()))
  1537. return new MSVCProjectExporterVC2015 (project, settings);
  1538. return nullptr;
  1539. }
  1540. void createExporterProperties (PropertyListBuilder& props) override
  1541. {
  1542. MSVCProjectExporterBase::createExporterProperties (props);
  1543. static const char* toolsetNames[] = { "v140", "v140_xp", "CTP_Nov2013" };
  1544. const var toolsets[] = { "v140", "v140_xp", "CTP_Nov2013" };
  1545. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1546. addIPPLibraryProperty (props);
  1547. addWindowsTargetPlatformProperties (props);
  1548. }
  1549. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1550. };
  1551. //==============================================================================
  1552. class MSVCProjectExporterVC2017 : public MSVCProjectExporterBase
  1553. {
  1554. public:
  1555. MSVCProjectExporterVC2017 (Project& p, const ValueTree& t)
  1556. : MSVCProjectExporterBase (p, t, getTargetFolderForExporter (getValueTreeTypeName()))
  1557. {
  1558. name = getName();
  1559. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1560. platformToolsetValue.setDefault (getDefaultToolset());
  1561. }
  1562. static const char* getName() { return "Visual Studio 2017"; }
  1563. static const char* getValueTreeTypeName() { return "VS2017"; }
  1564. int getVisualStudioVersion() const override { return 15; }
  1565. String getSolutionComment() const override { return "# Visual Studio 2017"; }
  1566. String getToolsVersion() const override { return "15.0"; }
  1567. String getDefaultToolset() const override { return "v141"; }
  1568. String getDefaultWindowsTargetPlatformVersion() const override { return "10.0.16299.0"; }
  1569. static MSVCProjectExporterVC2017* createForSettings (Project& project, const ValueTree& settings)
  1570. {
  1571. if (settings.hasType (getValueTreeTypeName()))
  1572. return new MSVCProjectExporterVC2017 (project, settings);
  1573. return nullptr;
  1574. }
  1575. void createExporterProperties (PropertyListBuilder& props) override
  1576. {
  1577. MSVCProjectExporterBase::createExporterProperties (props);
  1578. static const char* toolsetNames[] = { "v140", "v140_xp", "v141", "v141_xp" };
  1579. const var toolsets[] = { "v140", "v140_xp", "v141", "v141_xp" };
  1580. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1581. addIPPLibraryProperty (props);
  1582. addWindowsTargetPlatformProperties (props);
  1583. }
  1584. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2017)
  1585. };