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.

1969 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 : optimiseFull)); }
  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[] = { "Disabled (/Od)", "Minimise size (/O1)", "Maximise speed (/O2)", "Full optimisation (/Ox)", 0 };
  204. const int optimisationLevelValues[] = { optimisationOff, optimiseMinSize, optimiseMaxSpeed, optimiseFull, 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 optimiseMinSize: return "MinSpace";
  777. case optimiseMaxSpeed: return "MaxSpeed";
  778. case optimiseFull: return "Full";
  779. default: return "Disabled";
  780. }
  781. }
  782. String getTargetSuffix() const
  783. {
  784. const ProjectType::Target::TargetFileType fileType = getTargetFileType();
  785. switch (fileType)
  786. {
  787. case executable: return ".exe";
  788. case staticLibrary: return ".lib";
  789. case sharedLibraryOrDLL: return ".dll";
  790. case pluginBundle:
  791. switch (type)
  792. {
  793. case VST3PlugIn: return ".vst3";
  794. case AAXPlugIn: return ".aaxdll";
  795. case RTASPlugIn: return ".dpm";
  796. default: break;
  797. }
  798. return ".dll";
  799. default:
  800. break;
  801. }
  802. return {};
  803. }
  804. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  805. {
  806. XmlElement* const e = parent.createNewChildElement ("Tool");
  807. e->setAttribute ("Name", toolName);
  808. return e;
  809. }
  810. String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const
  811. {
  812. StringPairArray defines (getOwner().msvcExtraPreprocessorDefs);
  813. defines.set ("WIN32", "");
  814. defines.set ("_WINDOWS", "");
  815. if (config.isDebug())
  816. {
  817. defines.set ("DEBUG", "");
  818. defines.set ("_DEBUG", "");
  819. }
  820. else
  821. {
  822. defines.set ("NDEBUG", "");
  823. }
  824. defines = mergePreprocessorDefs (defines, getOwner().getAllPreprocessorDefs (config, type));
  825. addExtraPreprocessorDefines (defines);
  826. if (getTargetFileType() == staticLibrary || getTargetFileType() == sharedLibraryOrDLL)
  827. defines.set("_LIB", "");
  828. StringArray result;
  829. for (int i = 0; i < defines.size(); ++i)
  830. {
  831. String def (defines.getAllKeys()[i]);
  832. const String value (defines.getAllValues()[i]);
  833. if (value.isNotEmpty())
  834. def << "=" << value;
  835. result.add (def);
  836. }
  837. return result.joinIntoString (joinString);
  838. }
  839. //==============================================================================
  840. RelativePath getAAXIconFile() const
  841. {
  842. const RelativePath aaxSDK (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder);
  843. const RelativePath projectIcon ("icon.ico", RelativePath::buildTargetFolder);
  844. if (getOwner().getTargetFolder().getChildFile ("icon.ico").existsAsFile())
  845. return projectIcon.rebased (getOwner().getTargetFolder(),
  846. getOwner().getProject().getProjectFolder(),
  847. RelativePath::projectFolder);
  848. return aaxSDK.getChildFile ("Utilities").getChildFile ("PlugIn.ico");
  849. }
  850. String getExtraPostBuildSteps (const MSVCBuildConfiguration& config) const
  851. {
  852. if (type == AAXPlugIn)
  853. {
  854. const RelativePath aaxSDK (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder);
  855. const RelativePath aaxLibsFolder = aaxSDK.getChildFile ("Libs");
  856. const RelativePath bundleScript = aaxSDK.getChildFile ("Utilities").getChildFile ("CreatePackage.bat");
  857. const RelativePath iconFilePath = getAAXIconFile();
  858. auto is64Bit = (config.config [Ids::winArchitecture] == "x64");
  859. auto outputFilename = config.getOutputFilename (".aaxplugin", true);
  860. auto bundleDir = getOwner().getOutDirFile (config, outputFilename);
  861. auto bundleContents = bundleDir + "\\Contents";
  862. auto macOSDir = bundleContents + String ("\\") + (is64Bit ? "x64" : "Win32");
  863. auto executable = macOSDir + String ("\\") + outputFilename;
  864. auto pkgScript = String ("copy /Y ") + getOutputFilePath (config).quoted() + String (" ") + executable.quoted() + String ("\r\ncall ")
  865. + createRebasedPath (bundleScript) + String (" ") + macOSDir.quoted() + String (" ") + createRebasedPath (iconFilePath);
  866. if (config.isPluginBinaryCopyStepEnabled())
  867. return pkgScript + "\r\n" + String ("xcopy ") + bundleDir.quoted() + " "
  868. + String (config.aaxBinaryLocation.get() + "\\" + outputFilename + "\\").quoted() + " /E /Y /H /K";
  869. return pkgScript;
  870. }
  871. else if (config.isPluginBinaryCopyStepEnabled())
  872. {
  873. auto copyScript = String ("copy /Y \"$(OutDir)$(TargetFileName)\"") + String (" \"$COPYDIR$\\$(TargetFileName)\"");
  874. if (type == VSTPlugIn) return copyScript.replace ("$COPYDIR$", config.vstBinaryLocation.get());
  875. if (type == VST3PlugIn) return copyScript.replace ("$COPYDIR$", config.vst3BinaryLocation.get());
  876. if (type == RTASPlugIn) return copyScript.replace ("$COPYDIR$", config.rtasBinaryLocation.get());
  877. }
  878. return {};
  879. }
  880. String getExtraPreBuildSteps (const MSVCBuildConfiguration& config) const
  881. {
  882. if (type == AAXPlugIn)
  883. {
  884. String script;
  885. bool is64Bit = (config.config [Ids::winArchitecture] == "x64");
  886. auto bundleDir = getOwner().getOutDirFile (config, config.getOutputFilename (".aaxplugin", false));
  887. auto bundleContents = bundleDir + "\\Contents";
  888. auto macOSDir = bundleContents + String ("\\") + (is64Bit ? "x64" : "Win32");
  889. for (auto& folder : StringArray { bundleDir, bundleContents, macOSDir })
  890. script += String ("if not exist \"") + folder + String ("\" mkdir \"") + folder + String ("\"\r\n");
  891. return script;
  892. }
  893. return {};
  894. }
  895. String getPostBuildSteps (const MSVCBuildConfiguration& config) const
  896. {
  897. auto postBuild = config.getPostbuildCommandString();
  898. auto extraPostBuild = getExtraPostBuildSteps (config);
  899. return postBuild + String (postBuild.isNotEmpty() && extraPostBuild.isNotEmpty() ? "\r\n" : "") + extraPostBuild;
  900. }
  901. String getPreBuildSteps (const MSVCBuildConfiguration& config) const
  902. {
  903. auto preBuild = config.getPrebuildCommandString();
  904. auto extraPreBuild = getExtraPreBuildSteps (config);
  905. return preBuild + String (preBuild.isNotEmpty() && extraPreBuild.isNotEmpty() ? "\r\n" : "") + extraPreBuild;
  906. }
  907. void addExtraPreprocessorDefines (StringPairArray& defines) const
  908. {
  909. switch (type)
  910. {
  911. case AAXPlugIn:
  912. {
  913. auto aaxLibsFolder = RelativePath (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder).getChildFile ("Libs");
  914. defines.set ("JucePlugin_AAXLibs_path", createRebasedPath (aaxLibsFolder));
  915. }
  916. break;
  917. case RTASPlugIn:
  918. {
  919. const RelativePath rtasFolder (getOwner().getRTASPathValue().toString(), RelativePath::projectFolder);
  920. defines.set ("JucePlugin_WinBag_path", createRebasedPath (rtasFolder.getChildFile ("WinBag")));
  921. }
  922. break;
  923. default:
  924. break;
  925. }
  926. }
  927. String getExtraLinkerFlags() const
  928. {
  929. if (type == RTASPlugIn)
  930. return "/FORCE:multiple";
  931. return {};
  932. }
  933. StringArray getExtraSearchPaths() const
  934. {
  935. StringArray searchPaths;
  936. if (type == RTASPlugIn)
  937. {
  938. const RelativePath rtasFolder (getOwner().getRTASPathValue().toString(), RelativePath::projectFolder);
  939. static const char* p[] = { "AlturaPorts/TDMPlugins/PluginLibrary/EffectClasses",
  940. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses",
  941. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses/Interfaces",
  942. "AlturaPorts/TDMPlugins/PluginLibrary/Utilities",
  943. "AlturaPorts/TDMPlugins/PluginLibrary/RTASP_Adapt",
  944. "AlturaPorts/TDMPlugins/PluginLibrary/CoreClasses",
  945. "AlturaPorts/TDMPlugins/PluginLibrary/Controls",
  946. "AlturaPorts/TDMPlugins/PluginLibrary/Meters",
  947. "AlturaPorts/TDMPlugins/PluginLibrary/ViewClasses",
  948. "AlturaPorts/TDMPlugins/PluginLibrary/DSPClasses",
  949. "AlturaPorts/TDMPlugins/PluginLibrary/Interfaces",
  950. "AlturaPorts/TDMPlugins/common",
  951. "AlturaPorts/TDMPlugins/common/Platform",
  952. "AlturaPorts/TDMPlugins/common/Macros",
  953. "AlturaPorts/TDMPlugins/SignalProcessing/Public",
  954. "AlturaPorts/TDMPlugIns/DSPManager/Interfaces",
  955. "AlturaPorts/SADriver/Interfaces",
  956. "AlturaPorts/DigiPublic/Interfaces",
  957. "AlturaPorts/DigiPublic",
  958. "AlturaPorts/Fic/Interfaces/DAEClient",
  959. "AlturaPorts/NewFileLibs/Cmn",
  960. "AlturaPorts/NewFileLibs/DOA",
  961. "AlturaPorts/AlturaSource/PPC_H",
  962. "AlturaPorts/AlturaSource/AppSupport",
  963. "AvidCode/AVX2sdk/AVX/avx2/avx2sdk/inc",
  964. "xplat/AVX/avx2/avx2sdk/inc" };
  965. for (auto* path : p)
  966. searchPaths.add (createRebasedPath (rtasFolder.getChildFile (path)));
  967. }
  968. return searchPaths;
  969. }
  970. String getBinaryNameWithSuffix (const MSVCBuildConfiguration& config) const
  971. {
  972. return config.getOutputFilename (getTargetSuffix(), true);
  973. }
  974. String getOutputFilePath (const MSVCBuildConfiguration& config) const
  975. {
  976. return getOwner().getOutDirFile (config, getBinaryNameWithSuffix (config));
  977. }
  978. StringArray getLibrarySearchPaths (const BuildConfiguration& config) const
  979. {
  980. StringArray librarySearchPaths (config.getLibrarySearchPaths());
  981. if (type != SharedCodeTarget)
  982. if (const MSVCTargetBase* shared = getOwner().getSharedCodeTarget())
  983. librarySearchPaths.add (shared->getConfigTargetPath (config));
  984. return librarySearchPaths;
  985. }
  986. String getExternalLibraries (const MSVCBuildConfiguration& config, const String& otherLibs) const
  987. {
  988. StringArray libraries;
  989. if (otherLibs.isNotEmpty())
  990. libraries.add (otherLibs);
  991. StringArray moduleLibs = getOwner().getModuleLibs();
  992. if (! moduleLibs.isEmpty())
  993. libraries.addArray (moduleLibs);
  994. if (type != SharedCodeTarget)
  995. if (const MSVCTargetBase* shared = getOwner().getSharedCodeTarget())
  996. libraries.add (shared->getBinaryNameWithSuffix (config));
  997. return libraries.joinIntoString (";");
  998. }
  999. String getDelayLoadedDLLs() const
  1000. {
  1001. String delayLoadedDLLs = getOwner().msvcDelayLoadedDLLs;
  1002. if (type == RTASPlugIn)
  1003. delayLoadedDLLs += "DAE.dll; DigiExt.dll; DSI.dll; PluginLib.dll; "
  1004. "DSPManager.dll; DSPManager.dll; DSPManagerClientLib.dll; RTASClientLib.dll";
  1005. return delayLoadedDLLs;
  1006. }
  1007. String getModuleDefinitions (const MSVCBuildConfiguration& config) const
  1008. {
  1009. const String& moduleDefinitions = config.config [Ids::msvcModuleDefinitionFile].toString();
  1010. if (moduleDefinitions.isNotEmpty())
  1011. return moduleDefinitions;
  1012. if (type == RTASPlugIn)
  1013. {
  1014. const ProjectExporter& exp = getOwner();
  1015. RelativePath moduleDefPath
  1016. = RelativePath (exp.getPathForModuleString ("juce_audio_plugin_client"), RelativePath::projectFolder)
  1017. .getChildFile ("juce_audio_plugin_client").getChildFile ("RTAS").getChildFile ("juce_RTAS_WinExports.def");
  1018. return prependDot (moduleDefPath.rebased (exp.getProject().getProjectFolder(),
  1019. exp.getTargetFolder(),
  1020. RelativePath::buildTargetFolder).toWindowsStyle());
  1021. }
  1022. return {};
  1023. }
  1024. bool shouldUseRuntimeDLL (const MSVCBuildConfiguration& config) const
  1025. {
  1026. return (config.config [Ids::useRuntimeLibDLL].isVoid() ? (getOwner().hasTarget (AAXPlugIn) || getOwner().hasTarget (RTASPlugIn))
  1027. : config.isUsingRuntimeLibDLL());
  1028. }
  1029. File getVCProjFile() const { return getOwner().getProjectFile (getProjectFileSuffix(), getName()); }
  1030. File getVCProjFiltersFile() const { return getOwner().getProjectFile (getFiltersFileSuffix(), getName()); }
  1031. String createRebasedPath (const RelativePath& path) const { return getOwner().createRebasedPath (path); }
  1032. protected:
  1033. const MSVCProjectExporterBase& owner;
  1034. String projectGuid;
  1035. };
  1036. //==============================================================================
  1037. bool usesMMFiles() const override { return false; }
  1038. bool canCopeWithDuplicateFiles() override { return false; }
  1039. bool supportsUserDefinedConfigurations() const override { return true; }
  1040. bool isXcode() const override { return false; }
  1041. bool isVisualStudio() const override { return true; }
  1042. bool isCodeBlocks() const override { return false; }
  1043. bool isMakefile() const override { return false; }
  1044. bool isAndroidStudio() const override { return false; }
  1045. bool isCLion() const override { return false; }
  1046. bool isAndroid() const override { return false; }
  1047. bool isWindows() const override { return true; }
  1048. bool isLinux() const override { return false; }
  1049. bool isOSX() const override { return false; }
  1050. bool isiOS() const override { return false; }
  1051. bool supportsTargetType (ProjectType::Target::Type type) const override
  1052. {
  1053. switch (type)
  1054. {
  1055. case ProjectType::Target::StandalonePlugIn:
  1056. case ProjectType::Target::GUIApp:
  1057. case ProjectType::Target::ConsoleApp:
  1058. case ProjectType::Target::StaticLibrary:
  1059. case ProjectType::Target::SharedCodeTarget:
  1060. case ProjectType::Target::AggregateTarget:
  1061. case ProjectType::Target::VSTPlugIn:
  1062. case ProjectType::Target::VST3PlugIn:
  1063. case ProjectType::Target::AAXPlugIn:
  1064. case ProjectType::Target::RTASPlugIn:
  1065. case ProjectType::Target::DynamicLibrary:
  1066. return true;
  1067. default:
  1068. break;
  1069. }
  1070. return false;
  1071. }
  1072. //==============================================================================
  1073. Value getManifestFile() { return getSetting (Ids::msvcManifestFile); }
  1074. RelativePath getManifestPath() const
  1075. {
  1076. const String& path = settings [Ids::msvcManifestFile].toString();
  1077. return path.isEmpty() ? RelativePath() : RelativePath (settings [Ids::msvcManifestFile], RelativePath::projectFolder);
  1078. }
  1079. //==============================================================================
  1080. const String& getProjectName() const { return projectName; }
  1081. bool launchProject() override
  1082. {
  1083. #if JUCE_WINDOWS
  1084. return getSLNFile().startAsProcess();
  1085. #else
  1086. return false;
  1087. #endif
  1088. }
  1089. bool canLaunchProject() override
  1090. {
  1091. #if JUCE_WINDOWS
  1092. return true;
  1093. #else
  1094. return false;
  1095. #endif
  1096. }
  1097. void createExporterProperties (PropertyListBuilder& props) override
  1098. {
  1099. props.add(new TextPropertyComponent(getManifestFile(), "Manifest file", 8192, false),
  1100. "Path to a manifest input file which should be linked into your binary (path is relative to jucer file).");
  1101. }
  1102. enum OptimisationLevel
  1103. {
  1104. optimisationOff = 1,
  1105. optimiseMinSize = 2,
  1106. optimiseFull = 3,
  1107. optimiseMaxSpeed = 4
  1108. };
  1109. //==============================================================================
  1110. void addPlatformSpecificSettingsForProjectType (const ProjectType& type) override
  1111. {
  1112. msvcExtraPreprocessorDefs.set ("_CRT_SECURE_NO_WARNINGS", "");
  1113. if (type.isCommandLineApp())
  1114. msvcExtraPreprocessorDefs.set("_CONSOLE", "");
  1115. callForAllSupportedTargets ([this] (ProjectType::Target::Type targetType)
  1116. {
  1117. if (MSVCTargetBase* target = new MSVCTargetBase (targetType, *this))
  1118. {
  1119. if (targetType != ProjectType::Target::AggregateTarget)
  1120. targets.add (target);
  1121. }
  1122. });
  1123. // If you hit this assert, you tried to generate a project for an exporter
  1124. // that does not support any of your targets!
  1125. jassert (targets.size() > 0);
  1126. }
  1127. const MSVCTargetBase* getSharedCodeTarget() const
  1128. {
  1129. for (auto target : targets)
  1130. if (target->type == ProjectType::Target::SharedCodeTarget)
  1131. return target;
  1132. return nullptr;
  1133. }
  1134. bool hasTarget (ProjectType::Target::Type type) const
  1135. {
  1136. for (auto target : targets)
  1137. if (target->type == type)
  1138. return true;
  1139. return false;
  1140. }
  1141. private:
  1142. //==============================================================================
  1143. String createRebasedPath (const RelativePath& path) const
  1144. {
  1145. String rebasedPath = rebaseFromProjectFolderToBuildTarget (path).toWindowsStyle();
  1146. return getVisualStudioVersion() < 10 // (VS10 automatically adds escape characters to the quotes for this definition)
  1147. ? CppTokeniserFunctions::addEscapeChars (rebasedPath.quoted())
  1148. : CppTokeniserFunctions::addEscapeChars (rebasedPath).quoted();
  1149. }
  1150. protected:
  1151. //==============================================================================
  1152. mutable File rcFile, iconFile;
  1153. OwnedArray<MSVCTargetBase> targets;
  1154. CachedValue<String> windowsTargetPlatformVersion;
  1155. File getProjectFile (const String& extension, const String& target) const
  1156. {
  1157. String filename = project.getProjectFilenameRoot();
  1158. if (target.isNotEmpty())
  1159. filename += String ("_") + target.removeCharacters (" ");
  1160. return getTargetFolder().getChildFile (filename).withFileExtension (extension);
  1161. }
  1162. File getSLNFile() const { return getProjectFile (".sln", String()); }
  1163. static String prependIfNotAbsolute (const String& file, const char* prefix)
  1164. {
  1165. if (File::isAbsolutePath (file) || file.startsWithChar ('$'))
  1166. prefix = "";
  1167. return prefix + FileHelpers::windowsStylePath (file);
  1168. }
  1169. String getIntDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(IntDir)\\"); }
  1170. String getOutDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(OutDir)\\"); }
  1171. void updateOldSettings()
  1172. {
  1173. {
  1174. const String oldStylePrebuildCommand (getSettingString (Ids::prebuildCommand));
  1175. settings.removeProperty (Ids::prebuildCommand, nullptr);
  1176. if (oldStylePrebuildCommand.isNotEmpty())
  1177. for (ConfigIterator config (*this); config.next();)
  1178. dynamic_cast<MSVCBuildConfiguration&> (*config).getPrebuildCommand() = oldStylePrebuildCommand;
  1179. }
  1180. {
  1181. const String oldStyleLibName (getSettingString ("libraryName_Debug"));
  1182. settings.removeProperty ("libraryName_Debug", nullptr);
  1183. if (oldStyleLibName.isNotEmpty())
  1184. for (ConfigIterator config (*this); config.next();)
  1185. if (config->isDebug())
  1186. config->getTargetBinaryName() = oldStyleLibName;
  1187. }
  1188. {
  1189. const String oldStyleLibName (getSettingString ("libraryName_Release"));
  1190. settings.removeProperty ("libraryName_Release", nullptr);
  1191. if (oldStyleLibName.isNotEmpty())
  1192. for (ConfigIterator config (*this); config.next();)
  1193. if (! config->isDebug())
  1194. config->getTargetBinaryName() = oldStyleLibName;
  1195. }
  1196. }
  1197. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  1198. {
  1199. return new MSVCBuildConfiguration (project, v, *this);
  1200. }
  1201. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  1202. {
  1203. StringArray searchPaths (extraSearchPaths);
  1204. searchPaths.addArray (config.getHeaderSearchPaths());
  1205. return getCleanedStringArray (searchPaths);
  1206. }
  1207. String getSharedCodeGuid() const
  1208. {
  1209. String sharedCodeGuid;
  1210. for (int i = 0; i < targets.size(); ++i)
  1211. if (MSVCTargetBase* target = targets[i])
  1212. if (target->type == ProjectType::Target::SharedCodeTarget)
  1213. return target->getProjectGuid();
  1214. return {};
  1215. }
  1216. //==============================================================================
  1217. void writeProjectDependencies (OutputStream& out) const
  1218. {
  1219. const String sharedCodeGuid = getSharedCodeGuid();
  1220. for (int addingOtherTargets = 0; addingOtherTargets < (sharedCodeGuid.isNotEmpty() ? 2 : 1); ++addingOtherTargets)
  1221. {
  1222. for (int i = 0; i < targets.size(); ++i)
  1223. {
  1224. if (MSVCTargetBase* target = targets[i])
  1225. {
  1226. if (sharedCodeGuid.isEmpty() || (addingOtherTargets != 0) == (target->type != ProjectType::Target::StandalonePlugIn))
  1227. {
  1228. out << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" << projectName << " - "
  1229. << target->getName() << "\", \""
  1230. << target->getVCProjFile().getFileName() << "\", \"" << target->getProjectGuid() << '"' << newLine;
  1231. if (sharedCodeGuid.isNotEmpty() && target->type != ProjectType::Target::SharedCodeTarget)
  1232. out << "\tProjectSection(ProjectDependencies) = postProject" << newLine
  1233. << "\t\t" << sharedCodeGuid << " = " << sharedCodeGuid << newLine
  1234. << "\tEndProjectSection" << newLine;
  1235. out << "EndProject" << newLine;
  1236. }
  1237. }
  1238. }
  1239. }
  1240. }
  1241. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString) const
  1242. {
  1243. if (commentString.isNotEmpty())
  1244. commentString += newLine;
  1245. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  1246. << commentString << newLine;
  1247. writeProjectDependencies (out);
  1248. out << "Global" << newLine
  1249. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  1250. for (ConstConfigIterator i (*this); i.next();)
  1251. {
  1252. const MSVCBuildConfiguration& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1253. const String configName = config.createMSVCConfigName();
  1254. out << "\t\t" << configName << " = " << configName << newLine;
  1255. }
  1256. out << "\tEndGlobalSection" << newLine
  1257. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  1258. for (auto& target : targets)
  1259. for (ConstConfigIterator i (*this); i.next();)
  1260. {
  1261. const MSVCBuildConfiguration& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1262. const String configName = config.createMSVCConfigName();
  1263. for (auto& suffix : { "ActiveCfg", "Build.0" })
  1264. out << "\t\t" << target->getProjectGuid() << "." << configName << "." << suffix << " = " << configName << newLine;
  1265. }
  1266. out << "\tEndGlobalSection" << newLine
  1267. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  1268. << "\t\tHideSolutionNode = FALSE" << newLine
  1269. << "\tEndGlobalSection" << newLine;
  1270. out << "EndGlobal" << newLine;
  1271. }
  1272. //==============================================================================
  1273. static void writeBMPImage (const Image& image, const int w, const int h, MemoryOutputStream& out)
  1274. {
  1275. const int maskStride = (w / 8 + 3) & ~3;
  1276. out.writeInt (40); // bitmapinfoheader size
  1277. out.writeInt (w);
  1278. out.writeInt (h * 2);
  1279. out.writeShort (1); // planes
  1280. out.writeShort (32); // bits
  1281. out.writeInt (0); // compression
  1282. out.writeInt ((h * w * 4) + (h * maskStride)); // size image
  1283. out.writeInt (0); // x pixels per meter
  1284. out.writeInt (0); // y pixels per meter
  1285. out.writeInt (0); // clr used
  1286. out.writeInt (0); // clr important
  1287. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  1288. const int alphaThreshold = 5;
  1289. int y;
  1290. for (y = h; --y >= 0;)
  1291. {
  1292. for (int x = 0; x < w; ++x)
  1293. {
  1294. const Colour pixel (bitmap.getPixelColour (x, y));
  1295. if (pixel.getAlpha() <= alphaThreshold)
  1296. {
  1297. out.writeInt (0);
  1298. }
  1299. else
  1300. {
  1301. out.writeByte ((char) pixel.getBlue());
  1302. out.writeByte ((char) pixel.getGreen());
  1303. out.writeByte ((char) pixel.getRed());
  1304. out.writeByte ((char) pixel.getAlpha());
  1305. }
  1306. }
  1307. }
  1308. for (y = h; --y >= 0;)
  1309. {
  1310. int mask = 0, count = 0;
  1311. for (int x = 0; x < w; ++x)
  1312. {
  1313. const Colour pixel (bitmap.getPixelColour (x, y));
  1314. mask <<= 1;
  1315. if (pixel.getAlpha() <= alphaThreshold)
  1316. mask |= 1;
  1317. if (++count == 8)
  1318. {
  1319. out.writeByte ((char) mask);
  1320. count = 0;
  1321. mask = 0;
  1322. }
  1323. }
  1324. if (mask != 0)
  1325. out.writeByte ((char) mask);
  1326. for (int i = maskStride - w / 8; --i >= 0;)
  1327. out.writeByte (0);
  1328. }
  1329. }
  1330. static void writeIconFile (const Array<Image>& images, MemoryOutputStream& out)
  1331. {
  1332. out.writeShort (0); // reserved
  1333. out.writeShort (1); // .ico tag
  1334. out.writeShort ((short) images.size());
  1335. MemoryOutputStream dataBlock;
  1336. const int imageDirEntrySize = 16;
  1337. const int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  1338. for (int i = 0; i < images.size(); ++i)
  1339. {
  1340. const size_t oldDataSize = dataBlock.getDataSize();
  1341. const Image& image = images.getReference (i);
  1342. const int w = image.getWidth();
  1343. const int h = image.getHeight();
  1344. if (w >= 256 || h >= 256)
  1345. {
  1346. PNGImageFormat pngFormat;
  1347. pngFormat.writeImageToStream (image, dataBlock);
  1348. }
  1349. else
  1350. {
  1351. writeBMPImage (image, w, h, dataBlock);
  1352. }
  1353. out.writeByte ((char) w);
  1354. out.writeByte ((char) h);
  1355. out.writeByte (0);
  1356. out.writeByte (0);
  1357. out.writeShort (1); // colour planes
  1358. out.writeShort (32); // bits per pixel
  1359. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  1360. out.writeInt (dataBlockStart + (int) oldDataSize);
  1361. }
  1362. jassert (out.getPosition() == dataBlockStart);
  1363. out << dataBlock;
  1364. }
  1365. bool hasResourceFile() const
  1366. {
  1367. return ! projectType.isStaticLibrary();
  1368. }
  1369. void createResourcesAndIcon() const
  1370. {
  1371. if (hasResourceFile())
  1372. {
  1373. Array<Image> images;
  1374. const int sizes[] = { 16, 32, 48, 256 };
  1375. for (int i = 0; i < numElementsInArray (sizes); ++i)
  1376. {
  1377. Image im (getBestIconForSize (sizes[i], true));
  1378. if (im.isValid())
  1379. images.add (im);
  1380. }
  1381. if (images.size() > 0)
  1382. {
  1383. iconFile = getTargetFolder().getChildFile ("icon.ico");
  1384. MemoryOutputStream mo;
  1385. writeIconFile (images, mo);
  1386. overwriteFileIfDifferentOrThrow (iconFile, mo);
  1387. }
  1388. createRCFile();
  1389. }
  1390. }
  1391. void createRCFile() const
  1392. {
  1393. rcFile = getTargetFolder().getChildFile ("resources.rc");
  1394. const String version (project.getVersionString());
  1395. MemoryOutputStream mo;
  1396. mo << "#ifdef JUCE_USER_DEFINED_RC_FILE" << newLine
  1397. << " #include JUCE_USER_DEFINED_RC_FILE" << newLine
  1398. << "#else" << newLine
  1399. << newLine
  1400. << "#undef WIN32_LEAN_AND_MEAN" << newLine
  1401. << "#define WIN32_LEAN_AND_MEAN" << newLine
  1402. << "#include <windows.h>" << newLine
  1403. << newLine
  1404. << "VS_VERSION_INFO VERSIONINFO" << newLine
  1405. << "FILEVERSION " << getCommaSeparatedVersionNumber (version) << newLine
  1406. << "BEGIN" << newLine
  1407. << " BLOCK \"StringFileInfo\"" << newLine
  1408. << " BEGIN" << newLine
  1409. << " BLOCK \"040904E4\"" << newLine
  1410. << " BEGIN" << newLine;
  1411. writeRCValue (mo, "CompanyName", project.getCompanyName().toString());
  1412. writeRCValue (mo, "LegalCopyright", project.getCompanyCopyright().toString());
  1413. writeRCValue (mo, "FileDescription", project.getTitle());
  1414. writeRCValue (mo, "FileVersion", version);
  1415. writeRCValue (mo, "ProductName", project.getTitle());
  1416. writeRCValue (mo, "ProductVersion", version);
  1417. mo << " END" << newLine
  1418. << " END" << newLine
  1419. << newLine
  1420. << " BLOCK \"VarFileInfo\"" << newLine
  1421. << " BEGIN" << newLine
  1422. << " VALUE \"Translation\", 0x409, 1252" << newLine
  1423. << " END" << newLine
  1424. << "END" << newLine
  1425. << newLine
  1426. << "#endif" << newLine;
  1427. if (iconFile != File())
  1428. mo << newLine
  1429. << "IDI_ICON1 ICON DISCARDABLE " << iconFile.getFileName().quoted()
  1430. << newLine
  1431. << "IDI_ICON2 ICON DISCARDABLE " << iconFile.getFileName().quoted();
  1432. overwriteFileIfDifferentOrThrow (rcFile, mo);
  1433. }
  1434. static void writeRCValue (MemoryOutputStream& mo, const String& name, const String& value)
  1435. {
  1436. if (value.isNotEmpty())
  1437. mo << " VALUE \"" << name << "\", \""
  1438. << CppTokeniserFunctions::addEscapeChars (value) << "\\0\"" << newLine;
  1439. }
  1440. static String getCommaSeparatedVersionNumber (const String& version)
  1441. {
  1442. StringArray versionParts;
  1443. versionParts.addTokens (version, ",.", "");
  1444. versionParts.trim();
  1445. versionParts.removeEmptyStrings();
  1446. while (versionParts.size() < 4)
  1447. versionParts.add ("0");
  1448. return versionParts.joinIntoString (",");
  1449. }
  1450. static String prependDot (const String& filename)
  1451. {
  1452. return FileHelpers::isAbsolutePath (filename) ? filename
  1453. : (".\\" + filename);
  1454. }
  1455. static bool shouldUseStdCall (const RelativePath& path)
  1456. {
  1457. return path.getFileNameWithoutExtension().startsWithIgnoreCase ("juce_audio_plugin_client_RTAS_");
  1458. }
  1459. StringArray getModuleLibs() const
  1460. {
  1461. StringArray result;
  1462. for (auto& lib : windowsLibs)
  1463. result.add (lib + ".lib");
  1464. return result;
  1465. }
  1466. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase)
  1467. };
  1468. //==============================================================================
  1469. class MSVCProjectExporterVC2013 : public MSVCProjectExporterBase
  1470. {
  1471. public:
  1472. MSVCProjectExporterVC2013 (Project& p, const ValueTree& t)
  1473. : MSVCProjectExporterBase (p, t, "VisualStudio2013")
  1474. {
  1475. name = getName();
  1476. initialiseWindowsTargetPlatformVersion();
  1477. }
  1478. static const char* getName() { return "Visual Studio 2013"; }
  1479. static const char* getValueTreeTypeName() { return "VS2013"; }
  1480. int getVisualStudioVersion() const override { return 12; }
  1481. String getSolutionComment() const override { return "# Visual Studio 2013"; }
  1482. String getToolsVersion() const override { return "12.0"; }
  1483. String getDefaultToolset() const override { return "v120"; }
  1484. String getDefaultWindowsTargetPlatformVersion() const override { return "8.1"; }
  1485. static MSVCProjectExporterVC2013* createForSettings (Project& project, const ValueTree& settings)
  1486. {
  1487. if (settings.hasType (getValueTreeTypeName()))
  1488. return new MSVCProjectExporterVC2013 (project, settings);
  1489. return nullptr;
  1490. }
  1491. void createExporterProperties (PropertyListBuilder& props) override
  1492. {
  1493. MSVCProjectExporterBase::createExporterProperties (props);
  1494. static const char* toolsetNames[] = { "(default)", "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1495. const var toolsets[] = { var(), "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1496. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1497. addIPPLibraryProperty (props);
  1498. addWindowsTargetPlatformProperties (props);
  1499. }
  1500. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2013)
  1501. };
  1502. //==============================================================================
  1503. class MSVCProjectExporterVC2015 : public MSVCProjectExporterBase
  1504. {
  1505. public:
  1506. MSVCProjectExporterVC2015 (Project& p, const ValueTree& t)
  1507. : MSVCProjectExporterBase (p, t, "VisualStudio2015")
  1508. {
  1509. name = getName();
  1510. initialiseWindowsTargetPlatformVersion();
  1511. }
  1512. static const char* getName() { return "Visual Studio 2015"; }
  1513. static const char* getValueTreeTypeName() { return "VS2015"; }
  1514. int getVisualStudioVersion() const override { return 14; }
  1515. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1516. String getToolsVersion() const override { return "14.0"; }
  1517. String getDefaultToolset() const override { return "v140"; }
  1518. String getDefaultWindowsTargetPlatformVersion() const override { return "8.1"; }
  1519. static MSVCProjectExporterVC2015* createForSettings (Project& project, const ValueTree& settings)
  1520. {
  1521. if (settings.hasType (getValueTreeTypeName()))
  1522. return new MSVCProjectExporterVC2015 (project, settings);
  1523. return nullptr;
  1524. }
  1525. void createExporterProperties (PropertyListBuilder& props) override
  1526. {
  1527. MSVCProjectExporterBase::createExporterProperties (props);
  1528. static const char* toolsetNames[] = { "(default)", "v140", "v140_xp", "CTP_Nov2013" };
  1529. const var toolsets[] = { var(), "v140", "v140_xp", "CTP_Nov2013" };
  1530. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1531. addIPPLibraryProperty (props);
  1532. addWindowsTargetPlatformProperties (props);
  1533. }
  1534. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1535. };
  1536. //==============================================================================
  1537. class MSVCProjectExporterVC2017 : public MSVCProjectExporterBase
  1538. {
  1539. public:
  1540. MSVCProjectExporterVC2017 (Project& p, const ValueTree& t)
  1541. : MSVCProjectExporterBase (p, t, "VisualStudio2017")
  1542. {
  1543. name = getName();
  1544. initialiseWindowsTargetPlatformVersion();
  1545. }
  1546. static const char* getName() { return "Visual Studio 2017"; }
  1547. static const char* getValueTreeTypeName() { return "VS2017"; }
  1548. int getVisualStudioVersion() const override { return 15; }
  1549. String getSolutionComment() const override { return "# Visual Studio 2017"; }
  1550. String getToolsVersion() const override { return "15.0"; }
  1551. String getDefaultToolset() const override { return "v141"; }
  1552. String getDefaultWindowsTargetPlatformVersion() const override { return "10.0.16299.0"; }
  1553. static MSVCProjectExporterVC2017* createForSettings (Project& project, const ValueTree& settings)
  1554. {
  1555. if (settings.hasType (getValueTreeTypeName()))
  1556. return new MSVCProjectExporterVC2017 (project, settings);
  1557. return nullptr;
  1558. }
  1559. void createExporterProperties (PropertyListBuilder& props) override
  1560. {
  1561. MSVCProjectExporterBase::createExporterProperties (props);
  1562. static const char* toolsetNames[] = { "(default)", "v140", "v140_xp", "v141", "v141_xp" };
  1563. const var toolsets[] = { var(), "v140", "v140_xp", "v141", "v141_xp" };
  1564. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1565. addIPPLibraryProperty (props);
  1566. addWindowsTargetPlatformProperties (props);
  1567. }
  1568. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2017)
  1569. };