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.

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