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.

1964 lines
91KB

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