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.

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