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.

1960 lines
91KB

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