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.

1957 lines
91KB

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