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.

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