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.

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