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.

1947 lines
90KB

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