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.

1960 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, 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. private Value::Listener
  110. {
  111. public:
  112. MSVCBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  113. : BuildConfiguration (p, settings, e),
  114. warningLevelValue (config, Ids::winWarningLevel, getUndoManager(), 4),
  115. warningsAreErrorsValue (config, Ids::warningsAreErrors, getUndoManager(), false),
  116. prebuildCommandValue (config, Ids::prebuildCommand, getUndoManager()),
  117. postbuildCommandValue (config, Ids::postbuildCommand, getUndoManager()),
  118. generateDebugSymbolsValue (config, Ids::alwaysGenerateDebugSymbols, getUndoManager(), false),
  119. generateManifestValue (config, Ids::generateManifest, getUndoManager(), true),
  120. enableIncrementalLinkingValue (config, Ids::enableIncrementalLinking, getUndoManager(), false),
  121. useRuntimeLibDLLValue (config, Ids::useRuntimeLibDLL, getUndoManager(), true),
  122. intermediatesPathValue (config, Ids::intermediatesPath, getUndoManager()),
  123. characterSetValue (config, Ids::characterSet, getUndoManager()),
  124. architectureTypeValue (config, Ids::winArchitecture, getUndoManager(), get64BitArchName()),
  125. fastMathValue (config, Ids::fastMath, getUndoManager()),
  126. debugInformationFormatValue (config, Ids::debugInformationFormat, getUndoManager(), isDebug() ? "ProgramDatabase" : "None"),
  127. pluginBinaryCopyStepValue (config, Ids::enablePluginBinaryCopyStep, getUndoManager(), false),
  128. vstBinaryLocation (config, Ids::vstBinaryLocation, getUndoManager()),
  129. vst3BinaryLocation (config, Ids::vst3BinaryLocation, getUndoManager()),
  130. rtasBinaryLocation (config, Ids::rtasBinaryLocation, getUndoManager()),
  131. aaxBinaryLocation (config, Ids::aaxBinaryLocation, getUndoManager())
  132. {
  133. if (! isDebug())
  134. updateOldLTOSetting();
  135. setPluginBinaryCopyLocationDefaults();
  136. optimisationLevelValue.setDefault (isDebug() ? optimisationOff : optimiseFull);
  137. architectureValueToListenTo = architectureTypeValue.getPropertyAsValue();
  138. architectureValueToListenTo.addListener (this);
  139. }
  140. //==============================================================================
  141. int getWarningLevel() const { return warningLevelValue.get(); }
  142. bool areWarningsTreatedAsErrors() const { return warningsAreErrorsValue.get(); }
  143. String getPrebuildCommandString() const { return prebuildCommandValue.get(); }
  144. String getPostbuildCommandString() const { return postbuildCommandValue.get(); }
  145. bool shouldGenerateDebugSymbols() const { return generateDebugSymbolsValue.get(); }
  146. bool shouldGenerateManifest() const { return generateManifestValue.get(); }
  147. bool shouldLinkIncremental() const { return enableIncrementalLinkingValue.get(); }
  148. bool isUsingRuntimeLibDLL() const { return useRuntimeLibDLLValue.get(); }
  149. String getIntermediatesPathString() const { return intermediatesPathValue.get(); }
  150. String getCharacterSetString() const { return characterSetValue.get(); }
  151. String get64BitArchName() const { return "x64"; }
  152. String get32BitArchName() const { return "Win32"; }
  153. String getArchitectureString() const { return architectureTypeValue.get(); }
  154. bool is64Bit() const { return getArchitectureString() == get64BitArchName(); }
  155. bool isFastMathEnabled() const { return fastMathValue.get(); }
  156. String getDebugInformationFormatString() const { return debugInformationFormatValue.get(); }
  157. bool isPluginBinaryCopyStepEnabled() const { return pluginBinaryCopyStepValue.get(); }
  158. String getVSTBinaryLocationString() const { return vstBinaryLocation.get(); }
  159. String getVST3BinaryLocationString() const { return vst3BinaryLocation.get(); }
  160. String getRTASBinaryLocationString() const { return rtasBinaryLocation.get();}
  161. String getAAXBinaryLocationString() const { return aaxBinaryLocation.get();}
  162. //==============================================================================
  163. String createMSVCConfigName() const
  164. {
  165. return getName() + "|" + (is64Bit() ? "x64" : "Win32");
  166. }
  167. String getOutputFilename (const String& suffix, bool forceSuffix) const
  168. {
  169. auto target = File::createLegalFileName (getTargetBinaryNameString().trim());
  170. if (forceSuffix || ! target.containsChar ('.'))
  171. return target.upToLastOccurrenceOf (".", false, false) + suffix;
  172. return target;
  173. }
  174. void createConfigProperties (PropertyListBuilder& props) override
  175. {
  176. addVisualStudioPluginInstallPathProperties (props);
  177. props.add (new ChoicePropertyComponent (architectureTypeValue, "Architecture",
  178. { get32BitArchName(), get64BitArchName() },
  179. { get32BitArchName(), get64BitArchName() }),
  180. "Whether to use a 32-bit or 64-bit architecture.");
  181. props.add (new ChoicePropertyComponentWithEnablement (debugInformationFormatValue,
  182. isDebug() ? isDebugValue : generateDebugSymbolsValue,
  183. "Debug Information Format",
  184. { "None", "C7 Compatible (/Z7)", "Program Database (/Zi)", "Program Database for Edit And Continue (/ZI)" },
  185. { "None", "OldStyle", "ProgramDatabase", "EditAndContinue" }),
  186. "The type of debugging information created for your program for this configuration."
  187. " This will always be used in a debug configuration and will be used in a release configuration"
  188. " with forced generation of debug symbols.");
  189. props.add (new ChoicePropertyComponent (fastMathValue, "Relax IEEE Compliance"),
  190. "Enable this to use FAST_MATH non-IEEE mode. (Warning: this can have unexpected results!)");
  191. props.add (new ChoicePropertyComponent (optimisationLevelValue, "Optimisation",
  192. { "Disabled (/Od)", "Minimise size (/O1)", "Maximise speed (/O2)", "Full optimisation (/Ox)" },
  193. { optimisationOff, optimiseMinSize, optimiseMaxSpeed, optimiseFull }),
  194. "The optimisation level for this configuration");
  195. props.add (new TextPropertyComponent (intermediatesPathValue, "Intermediates Path", 2048, false),
  196. "An optional path to a folder to use for the intermediate build files. Note that Visual Studio allows "
  197. "you to use macros in this path, e.g. \"$(TEMP)\\MyAppBuildFiles\\$(Configuration)\", which is a handy way to "
  198. "send them to the user's temp folder.");
  199. props.add (new ChoicePropertyComponent (warningLevelValue, "Warning Level",
  200. { "Low", "Medium", "High" },
  201. { 2, 3, 4 }),
  202. "The compilation warning level to use.");
  203. props.add (new ChoicePropertyComponent (warningsAreErrorsValue, "Treat Warnings as Errors"),
  204. "Enable this to treat compilation warnings as errors.");
  205. props.add (new ChoicePropertyComponent (useRuntimeLibDLLValue, "Runtime Library",
  206. { "Use static runtime", "Use DLL runtime" },
  207. { false, true }),
  208. "If the static runtime is selected then your app/plug-in will not be dependent upon users having Microsoft's redistributable "
  209. "C++ runtime installed. However, if you are linking libraries from different sources you must select the same type of runtime "
  210. "used by the libraries.");
  211. props.add (new ChoicePropertyComponent (enableIncrementalLinkingValue, "Incremental Linking"),
  212. "Enable to avoid linking from scratch for every new build. "
  213. "Disable to ensure that your final release build does not contain padding or thunks.");
  214. if (! isDebug())
  215. {
  216. props.add (new ChoicePropertyComponent (generateDebugSymbolsValue, "Force Generation of Debug Symbols"),
  217. "Enable this to force generation of debug symbols in a release configuration.");
  218. }
  219. props.add (new TextPropertyComponent (prebuildCommandValue, "Pre-build Command", 2048, true),
  220. "Some command that will be run before a build starts.");
  221. props.add (new TextPropertyComponent (postbuildCommandValue, "Post-build Command", 2048, true),
  222. "Some command that will be run after a build starts.");
  223. props.add (new ChoicePropertyComponent (generateManifestValue, "Generate Manifest"),
  224. "Enable this to generate a Manifest file.");
  225. props.add (new ChoicePropertyComponent (characterSetValue, "Character Set",
  226. { "MultiByte", "Unicode" },
  227. { "MultiByte", "Unicode" }),
  228. "Specifies the character set used when building.");
  229. }
  230. String getModuleLibraryArchName() const override
  231. {
  232. String result ("$(Platform)\\");
  233. result += isUsingRuntimeLibDLL() ? "MD" : "MT";
  234. if (isDebug())
  235. result += "d";
  236. return result;
  237. }
  238. private:
  239. ValueWithDefault warningLevelValue, warningsAreErrorsValue, prebuildCommandValue, postbuildCommandValue, generateDebugSymbolsValue,
  240. generateManifestValue, enableIncrementalLinkingValue, useRuntimeLibDLLValue, intermediatesPathValue,
  241. characterSetValue, architectureTypeValue, fastMathValue, debugInformationFormatValue, pluginBinaryCopyStepValue;
  242. ValueWithDefault vstBinaryLocation, vst3BinaryLocation, rtasBinaryLocation, aaxBinaryLocation;
  243. Value architectureValueToListenTo;
  244. //==============================================================================
  245. void updateOldLTOSetting()
  246. {
  247. if (config.getPropertyAsValue ("wholeProgramOptimisation", nullptr) != Value())
  248. linkTimeOptimisationValue = (static_cast<int> (config ["wholeProgramOptimisation"]) == 0);
  249. }
  250. void addVisualStudioPluginInstallPathProperties (PropertyListBuilder& props)
  251. {
  252. auto isBuildingAnyPlugins = (project.shouldBuildVST() || project.shouldBuildVST3()
  253. || project.shouldBuildRTAS() || project.shouldBuildAAX());
  254. if (isBuildingAnyPlugins)
  255. props.add (new ChoicePropertyComponent (pluginBinaryCopyStepValue, "Enable Plugin Copy Step"),
  256. "Enable this to copy plugin binaries to a specified folder after building.");
  257. if (project.shouldBuildVST())
  258. props.add (new TextPropertyComponentWithEnablement (vstBinaryLocation, pluginBinaryCopyStepValue, "VST Binary Location",
  259. 1024, false),
  260. "The folder in which the compiled VST binary should be placed.");
  261. if (project.shouldBuildVST3())
  262. props.add (new TextPropertyComponentWithEnablement (vst3BinaryLocation, pluginBinaryCopyStepValue, "VST3 Binary Location",
  263. 1024, false),
  264. "The folder in which the compiled VST3 binary should be placed.");
  265. if (project.shouldBuildRTAS())
  266. props.add (new TextPropertyComponentWithEnablement (rtasBinaryLocation, pluginBinaryCopyStepValue, "RTAS Binary Location",
  267. 1024, false),
  268. "The folder in which the compiled RTAS binary should be placed.");
  269. if (project.shouldBuildAAX())
  270. props.add (new TextPropertyComponentWithEnablement (aaxBinaryLocation, pluginBinaryCopyStepValue, "AAX Binary Location",
  271. 1024, false),
  272. "The folder in which the compiled AAX binary should be placed.");
  273. }
  274. void setPluginBinaryCopyLocationDefaults()
  275. {
  276. vstBinaryLocation.setDefault ((is64Bit() ? "%ProgramW6432%" : "%programfiles(x86)%") + String ("\\Steinberg\\Vstplugins"));
  277. auto prefix = is64Bit() ? "%CommonProgramW6432%"
  278. : "%CommonProgramFiles(x86)%";
  279. vst3BinaryLocation.setDefault (prefix + String ("\\VST3"));
  280. rtasBinaryLocation.setDefault (prefix + String ("\\Digidesign\\DAE\\Plug-Ins"));
  281. aaxBinaryLocation.setDefault (prefix + String ("\\Avid\\Audio\\Plug-Ins"));
  282. }
  283. void valueChanged (Value&) override
  284. {
  285. setPluginBinaryCopyLocationDefaults();
  286. }
  287. };
  288. //==============================================================================
  289. class MSVCTargetBase : public ProjectType::Target
  290. {
  291. public:
  292. MSVCTargetBase (ProjectType::Target::Type targetType, const MSVCProjectExporterBase& exporter)
  293. : ProjectType::Target (targetType), owner (exporter)
  294. {
  295. projectGuid = createGUID (owner.getProject().getProjectUIDString() + getName());
  296. }
  297. virtual ~MSVCTargetBase() {}
  298. String getProjectVersionString() const { return "10.00"; }
  299. String getProjectFileSuffix() const { return ".vcxproj"; }
  300. String getFiltersFileSuffix() const { return ".vcxproj.filters"; }
  301. String getTopLevelXmlEntity() const { return "Project"; }
  302. //==============================================================================
  303. void fillInProjectXml (XmlElement& projectXml) const
  304. {
  305. projectXml.setAttribute ("DefaultTargets", "Build");
  306. projectXml.setAttribute ("ToolsVersion", getOwner().getToolsVersion());
  307. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  308. {
  309. auto* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  310. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  311. for (ConstConfigIterator i (owner); i.next();)
  312. {
  313. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  314. auto* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  315. e->setAttribute ("Include", config.createMSVCConfigName());
  316. e->createNewChildElement ("Configuration")->addTextElement (config.getName());
  317. e->createNewChildElement ("Platform")->addTextElement (config.is64Bit() ? config.get64BitArchName()
  318. : config.get32BitArchName());
  319. }
  320. }
  321. {
  322. auto* globals = projectXml.createNewChildElement ("PropertyGroup");
  323. globals->setAttribute ("Label", "Globals");
  324. globals->createNewChildElement ("ProjectGuid")->addTextElement (getProjectGuid());
  325. }
  326. {
  327. auto* imports = projectXml.createNewChildElement ("Import");
  328. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  329. }
  330. for (ConstConfigIterator i (owner); i.next();)
  331. {
  332. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  333. auto* e = projectXml.createNewChildElement ("PropertyGroup");
  334. setConditionAttribute (*e, config);
  335. e->setAttribute ("Label", "Configuration");
  336. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  337. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  338. e->createNewChildElement ("WholeProgramOptimization")->addTextElement (config.isLinkTimeOptimisationEnabled() ? "true"
  339. : "false");
  340. auto charSet = config.getCharacterSetString();
  341. if (charSet.isNotEmpty())
  342. e->createNewChildElement ("CharacterSet")->addTextElement (charSet);
  343. if (config.shouldLinkIncremental())
  344. e->createNewChildElement ("LinkIncremental")->addTextElement ("true");
  345. if (config.is64Bit())
  346. e->createNewChildElement ("PlatformToolset")->addTextElement (getOwner().getPlatformToolset());
  347. }
  348. {
  349. auto* e = projectXml.createNewChildElement ("Import");
  350. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  351. }
  352. {
  353. auto* e = projectXml.createNewChildElement ("ImportGroup");
  354. e->setAttribute ("Label", "ExtensionSettings");
  355. }
  356. {
  357. auto* e = projectXml.createNewChildElement ("ImportGroup");
  358. e->setAttribute ("Label", "PropertySheets");
  359. auto* p = e->createNewChildElement ("Import");
  360. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  361. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  362. p->setAttribute ("Label", "LocalAppDataPlatform");
  363. }
  364. {
  365. auto* e = projectXml.createNewChildElement ("PropertyGroup");
  366. e->setAttribute ("Label", "UserMacros");
  367. }
  368. {
  369. auto* props = projectXml.createNewChildElement ("PropertyGroup");
  370. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  371. props->createNewChildElement ("TargetExt")->addTextElement (getTargetSuffix());
  372. for (ConstConfigIterator i (owner); i.next();)
  373. {
  374. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  375. if (getConfigTargetPath (config).isNotEmpty())
  376. {
  377. auto* outdir = props->createNewChildElement ("OutDir");
  378. setConditionAttribute (*outdir, config);
  379. outdir->addTextElement (FileHelpers::windowsStylePath (getConfigTargetPath (config)) + "\\");
  380. }
  381. {
  382. auto* intdir = props->createNewChildElement("IntDir");
  383. setConditionAttribute (*intdir, config);
  384. auto intermediatesPath = getIntermediatesPath (config);
  385. if (! intermediatesPath.endsWithChar (L'\\'))
  386. intermediatesPath += L'\\';
  387. intdir->addTextElement (FileHelpers::windowsStylePath (intermediatesPath));
  388. }
  389. {
  390. auto* targetName = props->createNewChildElement ("TargetName");
  391. setConditionAttribute (*targetName, config);
  392. targetName->addTextElement (config.getOutputFilename ("", false));
  393. }
  394. {
  395. auto* manifest = props->createNewChildElement ("GenerateManifest");
  396. setConditionAttribute (*manifest, config);
  397. manifest->addTextElement (config.shouldGenerateManifest() ? "true" : "false");
  398. }
  399. if (type != SharedCodeTarget)
  400. {
  401. auto librarySearchPaths = getLibrarySearchPaths (config);
  402. if (librarySearchPaths.size() > 0)
  403. {
  404. auto* libPath = props->createNewChildElement ("LibraryPath");
  405. setConditionAttribute (*libPath, config);
  406. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  407. }
  408. }
  409. }
  410. }
  411. for (ConstConfigIterator i (owner); i.next();)
  412. {
  413. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  414. bool isDebug = config.isDebug();
  415. auto* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  416. setConditionAttribute (*group, config);
  417. {
  418. auto* midl = group->createNewChildElement ("Midl");
  419. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  420. : "NDEBUG;%(PreprocessorDefinitions)");
  421. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  422. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  423. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  424. midl->createNewChildElement ("HeaderFileName");
  425. }
  426. bool isUsingEditAndContinue = false;
  427. {
  428. auto* cl = group->createNewChildElement ("ClCompile");
  429. cl->createNewChildElement ("Optimization")->addTextElement (getOptimisationLevelString (config.getOptimisationLevelInt()));
  430. if (isDebug || config.shouldGenerateDebugSymbols())
  431. {
  432. cl->createNewChildElement ("DebugInformationFormat")
  433. ->addTextElement (config.getDebugInformationFormatString());
  434. }
  435. auto includePaths = getOwner().getHeaderSearchPaths (config);
  436. includePaths.addArray (getExtraSearchPaths());
  437. includePaths.add ("%(AdditionalIncludeDirectories)");
  438. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  439. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  440. bool runtimeDLL = config.isUsingRuntimeLibDLL();
  441. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (runtimeDLL ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  442. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  443. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  444. cl->createNewChildElement ("PrecompiledHeader");
  445. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  446. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  447. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement ("$(IntDir)\\");
  448. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (config.getWarningLevel()));
  449. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  450. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  451. if (config.isFastMathEnabled())
  452. cl->createNewChildElement ("FloatingPointModel")->addTextElement ("Fast");
  453. auto extraFlags = getOwner().replacePreprocessorTokens (config, getOwner().getExtraCompilerFlagsString()).trim();
  454. if (extraFlags.isNotEmpty())
  455. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  456. if (config.areWarningsTreatedAsErrors())
  457. cl->createNewChildElement ("TreatWarningAsError")->addTextElement ("true");
  458. auto cppStandard = owner.project.getCppStandardString();
  459. if (cppStandard == "11") // VS doesn't support the C++11 flag so we have to bump it to C++14
  460. cppStandard = "14";
  461. else if (cppStandard == "17") // nor does it support the C++17 flag, so we'll just use latest for now until it's added
  462. cppStandard = "latest";
  463. cl->createNewChildElement ("LanguageStandard")->addTextElement ("stdcpp" + cppStandard);
  464. }
  465. {
  466. auto* res = group->createNewChildElement ("ResourceCompile");
  467. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  468. : "NDEBUG;%(PreprocessorDefinitions)");
  469. }
  470. auto externalLibraries = getExternalLibraries (config, getOwner().getExternalLibrariesString());
  471. auto additionalDependencies = type != SharedCodeTarget && externalLibraries.isNotEmpty()
  472. ? getOwner().replacePreprocessorTokens (config, externalLibraries).trim() + ";%(AdditionalDependencies)"
  473. : String();
  474. auto librarySearchPaths = config.getLibrarySearchPaths();
  475. auto additionalLibraryDirs = type != SharedCodeTarget && librarySearchPaths.size() > 0
  476. ? getOwner().replacePreprocessorTokens (config, librarySearchPaths.joinIntoString (";")) + ";%(AdditionalLibraryDirectories)"
  477. : String();
  478. {
  479. auto* link = group->createNewChildElement ("Link");
  480. link->createNewChildElement ("OutputFile")->addTextElement (getOutputFilePath (config));
  481. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  482. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  483. : "%(IgnoreSpecificDefaultLibraries)");
  484. link->createNewChildElement ("GenerateDebugInformation")->addTextElement ((isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  485. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (getOwner().getIntDirFile (config, config.getOutputFilename (".pdb", true)));
  486. link->createNewChildElement ("SubSystem")->addTextElement (type == ConsoleApp ? "Console" : "Windows");
  487. if (! config.is64Bit())
  488. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  489. if (isUsingEditAndContinue)
  490. link->createNewChildElement ("ImageHasSafeExceptionHandlers")->addTextElement ("false");
  491. if (! isDebug)
  492. {
  493. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  494. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  495. }
  496. if (additionalLibraryDirs.isNotEmpty())
  497. link->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (additionalLibraryDirs);
  498. link->createNewChildElement ("LargeAddressAware")->addTextElement ("true");
  499. if (additionalDependencies.isNotEmpty())
  500. link->createNewChildElement ("AdditionalDependencies")->addTextElement (additionalDependencies);
  501. auto extraLinkerOptions = getOwner().getExtraLinkerFlagsString();
  502. if (extraLinkerOptions.isNotEmpty())
  503. link->createNewChildElement ("AdditionalOptions")->addTextElement (getOwner().replacePreprocessorTokens (config, extraLinkerOptions).trim()
  504. + " %(AdditionalOptions)");
  505. auto delayLoadedDLLs = getDelayLoadedDLLs();
  506. if (delayLoadedDLLs.isNotEmpty())
  507. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (delayLoadedDLLs);
  508. auto moduleDefinitionsFile = getModuleDefinitions (config);
  509. if (moduleDefinitionsFile.isNotEmpty())
  510. link->createNewChildElement ("ModuleDefinitionFile")
  511. ->addTextElement (moduleDefinitionsFile);
  512. }
  513. {
  514. auto* bsc = group->createNewChildElement ("Bscmake");
  515. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  516. bsc->createNewChildElement ("OutputFile")->addTextElement (getOwner().getIntDirFile (config, config.getOutputFilename (".bsc", true)));
  517. }
  518. if (type != SharedCodeTarget)
  519. {
  520. auto* lib = group->createNewChildElement ("Lib");
  521. if (additionalDependencies.isNotEmpty())
  522. lib->createNewChildElement ("AdditionalDependencies")->addTextElement (additionalDependencies);
  523. if (additionalLibraryDirs.isNotEmpty())
  524. lib->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (additionalLibraryDirs);
  525. }
  526. auto manifestFile = getOwner().getManifestPath();
  527. if (manifestFile.getRoot() != RelativePath::unknown)
  528. {
  529. auto* bsc = group->createNewChildElement ("Manifest");
  530. bsc->createNewChildElement ("AdditionalManifestFiles")
  531. ->addTextElement (manifestFile.rebased (getOwner().getProject().getFile().getParentDirectory(),
  532. getOwner().getTargetFolder(),
  533. RelativePath::buildTargetFolder).toWindowsStyle());
  534. }
  535. if (getTargetFileType() == staticLibrary && ! config.is64Bit())
  536. {
  537. auto* lib = group->createNewChildElement ("Lib");
  538. lib->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  539. }
  540. auto preBuild = getPreBuildSteps (config);
  541. if (preBuild.isNotEmpty())
  542. group->createNewChildElement ("PreBuildEvent")
  543. ->createNewChildElement ("Command")
  544. ->addTextElement (preBuild);
  545. auto postBuild = getPostBuildSteps (config);
  546. if (postBuild.isNotEmpty())
  547. group->createNewChildElement ("PostBuildEvent")
  548. ->createNewChildElement ("Command")
  549. ->addTextElement (postBuild);
  550. }
  551. std::unique_ptr<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  552. {
  553. auto* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  554. auto* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  555. for (int i = 0; i < getOwner().getAllGroups().size(); ++i)
  556. {
  557. auto& group = getOwner().getAllGroups().getReference (i);
  558. if (group.getNumChildren() > 0)
  559. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  560. }
  561. }
  562. if (getOwner().iconFile != File())
  563. {
  564. auto* e = otherFilesGroup->createNewChildElement ("None");
  565. e->setAttribute ("Include", prependDot (getOwner().iconFile.getFileName()));
  566. }
  567. if (otherFilesGroup->getFirstChildElement() != nullptr)
  568. projectXml.addChildElement (otherFilesGroup.release());
  569. if (type != SharedCodeTarget && getOwner().hasResourceFile())
  570. {
  571. auto* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  572. auto* e = rcGroup->createNewChildElement ("ResourceCompile");
  573. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  574. }
  575. {
  576. auto* e = projectXml.createNewChildElement ("Import");
  577. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  578. }
  579. {
  580. auto* e = projectXml.createNewChildElement ("ImportGroup");
  581. e->setAttribute ("Label", "ExtensionTargets");
  582. }
  583. getOwner().addPlatformToolsetToPropertyGroup (projectXml);
  584. getOwner().addWindowsTargetPlatformVersionToPropertyGroup (projectXml);
  585. getOwner().addIPPSettingToPropertyGroup (projectXml);
  586. }
  587. String getProjectType() const
  588. {
  589. switch (getTargetFileType())
  590. {
  591. case executable:
  592. return "Application";
  593. case staticLibrary:
  594. return "StaticLibrary";
  595. default:
  596. break;
  597. }
  598. return "DynamicLibrary";
  599. }
  600. //==============================================================================
  601. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  602. {
  603. auto targetType = (getOwner().getProject().getProjectType().isAudioPlugin() ? type : SharedCodeTarget);
  604. if (projectItem.isGroup())
  605. {
  606. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  607. addFilesToCompile (projectItem.getChild (i), cpps, headers, otherFiles);
  608. }
  609. else if (projectItem.shouldBeAddedToTargetProject()
  610. && getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType)
  611. {
  612. RelativePath path (projectItem.getFile(), getOwner().getTargetFolder(), RelativePath::buildTargetFolder);
  613. jassert (path.getRoot() == RelativePath::buildTargetFolder);
  614. if (path.hasFileExtension (cOrCppFileExtensions) || path.hasFileExtension (asmFileExtensions))
  615. {
  616. if (targetType == SharedCodeTarget || projectItem.shouldBeCompiled())
  617. {
  618. auto* e = cpps.createNewChildElement ("ClCompile");
  619. e->setAttribute ("Include", path.toWindowsStyle());
  620. if (shouldUseStdCall (path))
  621. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  622. if (! projectItem.shouldBeCompiled())
  623. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  624. }
  625. }
  626. else if (path.hasFileExtension (headerFileExtensions))
  627. {
  628. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  629. }
  630. else if (! path.hasFileExtension (objCFileExtensions))
  631. {
  632. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  633. }
  634. }
  635. }
  636. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  637. {
  638. auto& msvcConfig = dynamic_cast<const MSVCBuildConfiguration&> (config);
  639. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + msvcConfig.createMSVCConfigName() + "'");
  640. }
  641. //==============================================================================
  642. void addFilterGroup (XmlElement& groups, const String& path) const
  643. {
  644. auto* e = groups.createNewChildElement ("Filter");
  645. e->setAttribute ("Include", path);
  646. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  647. }
  648. void addFileToFilter (const RelativePath& file, const String& groupPath,
  649. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  650. {
  651. XmlElement* e = nullptr;
  652. if (file.hasFileExtension (headerFileExtensions))
  653. e = headers.createNewChildElement ("ClInclude");
  654. else if (file.hasFileExtension (sourceFileExtensions))
  655. e = cpps.createNewChildElement ("ClCompile");
  656. else
  657. e = otherFiles.createNewChildElement ("None");
  658. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  659. e->setAttribute ("Include", file.toWindowsStyle());
  660. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  661. }
  662. bool addFilesToFilter (const Project::Item& projectItem, const String& path,
  663. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  664. {
  665. auto targetType = (getOwner().getProject().getProjectType().isAudioPlugin() ? type : SharedCodeTarget);
  666. if (projectItem.isGroup())
  667. {
  668. bool filesWereAdded = false;
  669. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  670. if (addFilesToFilter (projectItem.getChild(i),
  671. (path.isEmpty() ? String() : (path + "\\")) + projectItem.getChild(i).getName(),
  672. cpps, headers, otherFiles, groups))
  673. filesWereAdded = true;
  674. if (filesWereAdded)
  675. addFilterGroup (groups, path);
  676. return filesWereAdded;
  677. }
  678. else if (projectItem.shouldBeAddedToTargetProject())
  679. {
  680. RelativePath relativePath (projectItem.getFile(), getOwner().getTargetFolder(), RelativePath::buildTargetFolder);
  681. jassert (relativePath.getRoot() == RelativePath::buildTargetFolder);
  682. if (getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType
  683. && (targetType == SharedCodeTarget || projectItem.shouldBeCompiled()))
  684. {
  685. addFileToFilter (relativePath, path.upToLastOccurrenceOf ("\\", false, false), cpps, headers, otherFiles);
  686. return true;
  687. }
  688. }
  689. return false;
  690. }
  691. bool addFilesToFilter (const Array<RelativePath>& files, const String& path,
  692. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups)
  693. {
  694. if (files.size() > 0)
  695. {
  696. addFilterGroup (groups, path);
  697. for (int i = 0; i < files.size(); ++i)
  698. addFileToFilter (files.getReference(i), path, cpps, headers, otherFiles);
  699. return true;
  700. }
  701. return false;
  702. }
  703. void fillInFiltersXml (XmlElement& filterXml) const
  704. {
  705. filterXml.setAttribute ("ToolsVersion", getOwner().getToolsVersion());
  706. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  707. auto* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  708. auto* cpps = filterXml.createNewChildElement ("ItemGroup");
  709. auto* headers = filterXml.createNewChildElement ("ItemGroup");
  710. std::unique_ptr<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  711. for (int i = 0; i < getOwner().getAllGroups().size(); ++i)
  712. {
  713. auto& group = getOwner().getAllGroups().getReference(i);
  714. if (group.getNumChildren() > 0)
  715. addFilesToFilter (group, group.getName(), *cpps, *headers, *otherFilesGroup, *groupsXml);
  716. }
  717. if (getOwner().iconFile.exists())
  718. {
  719. auto* e = otherFilesGroup->createNewChildElement ("None");
  720. e->setAttribute ("Include", prependDot (getOwner().iconFile.getFileName()));
  721. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  722. }
  723. if (otherFilesGroup->getFirstChildElement() != nullptr)
  724. filterXml.addChildElement (otherFilesGroup.release());
  725. if (type != SharedCodeTarget && getOwner().hasResourceFile())
  726. {
  727. auto* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  728. auto* e = rcGroup->createNewChildElement ("ResourceCompile");
  729. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  730. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  731. }
  732. }
  733. const MSVCProjectExporterBase& getOwner() const { return owner; }
  734. const String& getProjectGuid() const { return projectGuid; }
  735. //==============================================================================
  736. void writeProjectFile()
  737. {
  738. {
  739. XmlElement projectXml (getTopLevelXmlEntity());
  740. fillInProjectXml (projectXml);
  741. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  742. }
  743. {
  744. XmlElement filtersXml (getTopLevelXmlEntity());
  745. fillInFiltersXml (filtersXml);
  746. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "UTF-8", 100);
  747. }
  748. }
  749. String getSolutionTargetPath (const BuildConfiguration& config) const
  750. {
  751. auto binaryPath = config.getTargetBinaryRelativePathString().trim();
  752. if (binaryPath.isEmpty())
  753. return "$(SolutionDir)$(Platform)\\$(Configuration)";
  754. RelativePath binaryRelPath (binaryPath, RelativePath::projectFolder);
  755. if (binaryRelPath.isAbsolute())
  756. return binaryRelPath.toWindowsStyle();
  757. return prependDot (binaryRelPath.rebased (getOwner().projectFolder, getOwner().getTargetFolder(), RelativePath::buildTargetFolder)
  758. .toWindowsStyle());
  759. }
  760. String getConfigTargetPath (const BuildConfiguration& config) const
  761. {
  762. auto solutionTargetFolder = getSolutionTargetPath (config);
  763. return solutionTargetFolder + "\\" + getName();
  764. }
  765. String getIntermediatesPath (const MSVCBuildConfiguration& config) const
  766. {
  767. auto intDir = (config.getIntermediatesPathString().isNotEmpty() ? config.getIntermediatesPathString()
  768. : "$(Platform)\\$(Configuration)");
  769. if (! intDir.endsWithChar (L'\\'))
  770. intDir += L'\\';
  771. return intDir + getName();
  772. }
  773. static const char* getOptimisationLevelString (int level)
  774. {
  775. switch (level)
  776. {
  777. case optimiseMinSize: return "MinSpace";
  778. case optimiseMaxSpeed: return "MaxSpeed";
  779. case optimiseFull: return "Full";
  780. default: return "Disabled";
  781. }
  782. }
  783. String getTargetSuffix() const
  784. {
  785. auto fileType = getTargetFileType();
  786. switch (fileType)
  787. {
  788. case executable: return ".exe";
  789. case staticLibrary: return ".lib";
  790. case sharedLibraryOrDLL: return ".dll";
  791. case pluginBundle:
  792. switch (type)
  793. {
  794. case VST3PlugIn: return ".vst3";
  795. case AAXPlugIn: return ".aaxdll";
  796. case RTASPlugIn: return ".dpm";
  797. default: break;
  798. }
  799. return ".dll";
  800. default:
  801. break;
  802. }
  803. return {};
  804. }
  805. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  806. {
  807. auto* e = parent.createNewChildElement ("Tool");
  808. e->setAttribute ("Name", toolName);
  809. return e;
  810. }
  811. String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const
  812. {
  813. auto defines = getOwner().msvcExtraPreprocessorDefs;
  814. defines.set ("WIN32", "");
  815. defines.set ("_WINDOWS", "");
  816. if (config.isDebug())
  817. {
  818. defines.set ("DEBUG", "");
  819. defines.set ("_DEBUG", "");
  820. }
  821. else
  822. {
  823. defines.set ("NDEBUG", "");
  824. }
  825. defines = mergePreprocessorDefs (defines, getOwner().getAllPreprocessorDefs (config, type));
  826. addExtraPreprocessorDefines (defines);
  827. if (getTargetFileType() == staticLibrary || getTargetFileType() == sharedLibraryOrDLL)
  828. defines.set("_LIB", "");
  829. StringArray result;
  830. for (int i = 0; i < defines.size(); ++i)
  831. {
  832. auto def = defines.getAllKeys()[i];
  833. auto value = defines.getAllValues()[i];
  834. if (value.isNotEmpty())
  835. def << "=" << value;
  836. result.add (def);
  837. }
  838. return result.joinIntoString (joinString);
  839. }
  840. //==============================================================================
  841. RelativePath getAAXIconFile() const
  842. {
  843. RelativePath aaxSDK (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder);
  844. RelativePath projectIcon ("icon.ico", RelativePath::buildTargetFolder);
  845. if (getOwner().getTargetFolder().getChildFile ("icon.ico").existsAsFile())
  846. return projectIcon.rebased (getOwner().getTargetFolder(),
  847. getOwner().getProject().getProjectFolder(),
  848. RelativePath::projectFolder);
  849. return aaxSDK.getChildFile ("Utilities").getChildFile ("PlugIn.ico");
  850. }
  851. String getExtraPostBuildSteps (const MSVCBuildConfiguration& config) const
  852. {
  853. if (type == AAXPlugIn)
  854. {
  855. RelativePath aaxSDK (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder);
  856. RelativePath aaxLibsFolder = aaxSDK.getChildFile ("Libs");
  857. RelativePath bundleScript = aaxSDK.getChildFile ("Utilities").getChildFile ("CreatePackage.bat");
  858. RelativePath iconFilePath = getAAXIconFile();
  859. auto outputFilename = config.getOutputFilename (".aaxplugin", true);
  860. auto bundleDir = getOwner().getOutDirFile (config, outputFilename);
  861. auto bundleContents = bundleDir + "\\Contents";
  862. auto archDir = bundleContents + String ("\\") + (config.is64Bit() ? "x64" : "Win32");
  863. auto executable = archDir + String ("\\") + outputFilename;
  864. auto pkgScript = String ("copy /Y ") + getOutputFilePath (config).quoted() + String (" ") + executable.quoted() + String ("\r\ncall ")
  865. + createRebasedPath (bundleScript) + String (" ") + archDir.quoted() + String (" ") + createRebasedPath (iconFilePath);
  866. if (config.isPluginBinaryCopyStepEnabled())
  867. return pkgScript + "\r\n" + "xcopy " + bundleDir.quoted() + " "
  868. + String (config.getAAXBinaryLocationString() + "\\" + outputFilename + "\\").quoted() + " /E /H /K /R /Y";
  869. return pkgScript;
  870. }
  871. else if (config.isPluginBinaryCopyStepEnabled())
  872. {
  873. auto copyScript = String ("copy /Y \"$(OutDir)$(TargetFileName)\"") + String (" \"$COPYDIR$\\$(TargetFileName)\"");
  874. if (type == VSTPlugIn) return copyScript.replace ("$COPYDIR$", config.getVSTBinaryLocationString());
  875. if (type == VST3PlugIn) return copyScript.replace ("$COPYDIR$", config.getVST3BinaryLocationString());
  876. if (type == RTASPlugIn) return copyScript.replace ("$COPYDIR$", config.getRTASBinaryLocationString());
  877. }
  878. return {};
  879. }
  880. String getExtraPreBuildSteps (const MSVCBuildConfiguration& config) const
  881. {
  882. if (type == AAXPlugIn)
  883. {
  884. String script;
  885. auto bundleDir = getOwner().getOutDirFile (config, config.getOutputFilename (".aaxplugin", false));
  886. auto bundleContents = bundleDir + "\\Contents";
  887. auto archDir = bundleContents + String ("\\") + (config.is64Bit() ? "x64" : "Win32");
  888. for (auto& folder : StringArray { bundleDir, bundleContents, archDir })
  889. script += String ("if not exist \"") + folder + String ("\" mkdir \"") + folder + String ("\"\r\n");
  890. return script;
  891. }
  892. return {};
  893. }
  894. String getPostBuildSteps (const MSVCBuildConfiguration& config) const
  895. {
  896. auto postBuild = config.getPostbuildCommandString();
  897. auto extraPostBuild = getExtraPostBuildSteps (config);
  898. return postBuild + String (postBuild.isNotEmpty() && extraPostBuild.isNotEmpty() ? "\r\n" : "") + extraPostBuild;
  899. }
  900. String getPreBuildSteps (const MSVCBuildConfiguration& config) const
  901. {
  902. auto preBuild = config.getPrebuildCommandString();
  903. auto extraPreBuild = getExtraPreBuildSteps (config);
  904. return preBuild + String (preBuild.isNotEmpty() && extraPreBuild.isNotEmpty() ? "\r\n" : "") + extraPreBuild;
  905. }
  906. void addExtraPreprocessorDefines (StringPairArray& defines) const
  907. {
  908. switch (type)
  909. {
  910. case AAXPlugIn:
  911. {
  912. auto aaxLibsFolder = RelativePath (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder).getChildFile ("Libs");
  913. defines.set ("JucePlugin_AAXLibs_path", createRebasedPath (aaxLibsFolder));
  914. }
  915. break;
  916. case RTASPlugIn:
  917. {
  918. RelativePath rtasFolder (getOwner().getRTASPathValue().toString(), RelativePath::projectFolder);
  919. defines.set ("JucePlugin_WinBag_path", createRebasedPath (rtasFolder.getChildFile ("WinBag")));
  920. }
  921. break;
  922. default:
  923. break;
  924. }
  925. }
  926. String getExtraLinkerFlags() const
  927. {
  928. if (type == RTASPlugIn)
  929. return "/FORCE:multiple";
  930. return {};
  931. }
  932. StringArray getExtraSearchPaths() const
  933. {
  934. StringArray searchPaths;
  935. if (type == RTASPlugIn)
  936. {
  937. RelativePath rtasFolder (getOwner().getRTASPathValue().toString(), RelativePath::projectFolder);
  938. static const char* p[] = { "AlturaPorts/TDMPlugins/PluginLibrary/EffectClasses",
  939. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses",
  940. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses/Interfaces",
  941. "AlturaPorts/TDMPlugins/PluginLibrary/Utilities",
  942. "AlturaPorts/TDMPlugins/PluginLibrary/RTASP_Adapt",
  943. "AlturaPorts/TDMPlugins/PluginLibrary/CoreClasses",
  944. "AlturaPorts/TDMPlugins/PluginLibrary/Controls",
  945. "AlturaPorts/TDMPlugins/PluginLibrary/Meters",
  946. "AlturaPorts/TDMPlugins/PluginLibrary/ViewClasses",
  947. "AlturaPorts/TDMPlugins/PluginLibrary/DSPClasses",
  948. "AlturaPorts/TDMPlugins/PluginLibrary/Interfaces",
  949. "AlturaPorts/TDMPlugins/common",
  950. "AlturaPorts/TDMPlugins/common/Platform",
  951. "AlturaPorts/TDMPlugins/common/Macros",
  952. "AlturaPorts/TDMPlugins/SignalProcessing/Public",
  953. "AlturaPorts/TDMPlugIns/DSPManager/Interfaces",
  954. "AlturaPorts/SADriver/Interfaces",
  955. "AlturaPorts/DigiPublic/Interfaces",
  956. "AlturaPorts/DigiPublic",
  957. "AlturaPorts/Fic/Interfaces/DAEClient",
  958. "AlturaPorts/NewFileLibs/Cmn",
  959. "AlturaPorts/NewFileLibs/DOA",
  960. "AlturaPorts/AlturaSource/PPC_H",
  961. "AlturaPorts/AlturaSource/AppSupport",
  962. "AvidCode/AVX2sdk/AVX/avx2/avx2sdk/inc",
  963. "xplat/AVX/avx2/avx2sdk/inc" };
  964. for (auto* path : p)
  965. searchPaths.add (createRebasedPath (rtasFolder.getChildFile (path)));
  966. }
  967. return searchPaths;
  968. }
  969. String getBinaryNameWithSuffix (const MSVCBuildConfiguration& config) const
  970. {
  971. return config.getOutputFilename (getTargetSuffix(), true);
  972. }
  973. String getOutputFilePath (const MSVCBuildConfiguration& config) const
  974. {
  975. return getOwner().getOutDirFile (config, getBinaryNameWithSuffix (config));
  976. }
  977. StringArray getLibrarySearchPaths (const BuildConfiguration& config) const
  978. {
  979. auto librarySearchPaths = config.getLibrarySearchPaths();
  980. if (type != SharedCodeTarget)
  981. if (auto* shared = getOwner().getSharedCodeTarget())
  982. librarySearchPaths.add (shared->getConfigTargetPath (config));
  983. return librarySearchPaths;
  984. }
  985. String getExternalLibraries (const MSVCBuildConfiguration& config, const String& otherLibs) const
  986. {
  987. StringArray libraries;
  988. if (otherLibs.isNotEmpty())
  989. libraries.add (otherLibs);
  990. auto moduleLibs = getOwner().getModuleLibs();
  991. if (! moduleLibs.isEmpty())
  992. libraries.addArray (moduleLibs);
  993. if (type != SharedCodeTarget)
  994. if (auto* shared = getOwner().getSharedCodeTarget())
  995. libraries.add (shared->getBinaryNameWithSuffix (config));
  996. return libraries.joinIntoString (";");
  997. }
  998. String getDelayLoadedDLLs() const
  999. {
  1000. auto delayLoadedDLLs = getOwner().msvcDelayLoadedDLLs;
  1001. if (type == RTASPlugIn)
  1002. delayLoadedDLLs += "DAE.dll; DigiExt.dll; DSI.dll; PluginLib.dll; "
  1003. "DSPManager.dll; DSPManager.dll; DSPManagerClientLib.dll; RTASClientLib.dll";
  1004. return delayLoadedDLLs;
  1005. }
  1006. String getModuleDefinitions (const MSVCBuildConfiguration& config) const
  1007. {
  1008. auto moduleDefinitions = config.config [Ids::msvcModuleDefinitionFile].toString();
  1009. if (moduleDefinitions.isNotEmpty())
  1010. return moduleDefinitions;
  1011. if (type == RTASPlugIn)
  1012. {
  1013. auto& exp = getOwner();
  1014. auto moduleDefPath
  1015. = RelativePath (exp.getPathForModuleString ("juce_audio_plugin_client"), RelativePath::projectFolder)
  1016. .getChildFile ("juce_audio_plugin_client").getChildFile ("RTAS").getChildFile ("juce_RTAS_WinExports.def");
  1017. return prependDot (moduleDefPath.rebased (exp.getProject().getProjectFolder(),
  1018. exp.getTargetFolder(),
  1019. RelativePath::buildTargetFolder).toWindowsStyle());
  1020. }
  1021. return {};
  1022. }
  1023. File getVCProjFile() const { return getOwner().getProjectFile (getProjectFileSuffix(), getName()); }
  1024. File getVCProjFiltersFile() const { return getOwner().getProjectFile (getFiltersFileSuffix(), getName()); }
  1025. String createRebasedPath (const RelativePath& path) const { return getOwner().createRebasedPath (path); }
  1026. protected:
  1027. const MSVCProjectExporterBase& owner;
  1028. String projectGuid;
  1029. };
  1030. //==============================================================================
  1031. bool usesMMFiles() const override { return false; }
  1032. bool canCopeWithDuplicateFiles() override { return false; }
  1033. bool supportsUserDefinedConfigurations() const override { return true; }
  1034. bool isXcode() const override { return false; }
  1035. bool isVisualStudio() const override { return true; }
  1036. bool isCodeBlocks() const override { return false; }
  1037. bool isMakefile() const override { return false; }
  1038. bool isAndroidStudio() const override { return false; }
  1039. bool isCLion() const override { return false; }
  1040. bool isAndroid() const override { return false; }
  1041. bool isWindows() const override { return true; }
  1042. bool isLinux() const override { return false; }
  1043. bool isOSX() const override { return false; }
  1044. bool isiOS() const override { return false; }
  1045. bool supportsTargetType (ProjectType::Target::Type type) const override
  1046. {
  1047. switch (type)
  1048. {
  1049. case ProjectType::Target::StandalonePlugIn:
  1050. case ProjectType::Target::GUIApp:
  1051. case ProjectType::Target::ConsoleApp:
  1052. case ProjectType::Target::StaticLibrary:
  1053. case ProjectType::Target::SharedCodeTarget:
  1054. case ProjectType::Target::AggregateTarget:
  1055. case ProjectType::Target::VSTPlugIn:
  1056. case ProjectType::Target::VST3PlugIn:
  1057. case ProjectType::Target::AAXPlugIn:
  1058. case ProjectType::Target::RTASPlugIn:
  1059. case ProjectType::Target::DynamicLibrary:
  1060. return true;
  1061. default:
  1062. break;
  1063. }
  1064. return false;
  1065. }
  1066. //==============================================================================
  1067. RelativePath getManifestPath() const
  1068. {
  1069. auto path = manifestFileValue.get().toString();
  1070. return path.isEmpty() ? RelativePath()
  1071. : RelativePath (path, RelativePath::projectFolder);
  1072. }
  1073. //==============================================================================
  1074. const String& getProjectName() const { return projectName; }
  1075. bool launchProject() override
  1076. {
  1077. #if JUCE_WINDOWS
  1078. return getSLNFile().startAsProcess();
  1079. #else
  1080. return false;
  1081. #endif
  1082. }
  1083. bool canLaunchProject() override
  1084. {
  1085. #if JUCE_WINDOWS
  1086. return true;
  1087. #else
  1088. return false;
  1089. #endif
  1090. }
  1091. void createExporterProperties (PropertyListBuilder& props) override
  1092. {
  1093. props.add (new TextPropertyComponent (manifestFileValue, "Manifest file", 8192, false),
  1094. "Path to a manifest input file which should be linked into your binary (path is relative to jucer file).");
  1095. }
  1096. enum OptimisationLevel
  1097. {
  1098. optimisationOff = 1,
  1099. optimiseMinSize = 2,
  1100. optimiseFull = 3,
  1101. optimiseMaxSpeed = 4
  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. auto 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. ValueWithDefault IPPLibraryValue, platformToolsetValue, targetPlatformVersion, manifestFileValue;
  1149. File getProjectFile (const String& extension, const String& target) const
  1150. {
  1151. auto filename = project.getProjectFilenameRootString();
  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. auto 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).getValue (Ids::prebuildCommand) = oldStylePrebuildCommand;
  1173. }
  1174. {
  1175. auto 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->getValue (Ids::targetName) = oldStyleLibName;
  1181. }
  1182. {
  1183. auto 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->getValue (Ids::targetName) = 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. auto 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 (auto* 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. auto 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 (auto* 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. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1247. auto 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. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1256. auto 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. 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. Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  1282. int alphaThreshold = 5;
  1283. int y;
  1284. for (y = h; --y >= 0;)
  1285. {
  1286. for (int x = 0; x < w; ++x)
  1287. {
  1288. auto 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. auto 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. int imageDirEntrySize = 16;
  1331. int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  1332. for (int i = 0; i < images.size(); ++i)
  1333. {
  1334. auto oldDataSize = dataBlock.getDataSize();
  1335. auto& image = images.getReference (i);
  1336. auto w = image.getWidth();
  1337. auto 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. int sizes[] = { 16, 32, 48, 256 };
  1369. for (int i = 0; i < numElementsInArray (sizes); ++i)
  1370. {
  1371. auto 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. auto 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.getCompanyNameString());
  1406. writeRCValue (mo, "LegalCopyright", project.getCompanyCopyrightString());
  1407. writeRCValue (mo, "FileDescription", project.getProjectNameString());
  1408. writeRCValue (mo, "FileVersion", version);
  1409. writeRCValue (mo, "ProductName", project.getProjectNameString());
  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. auto versionParts = StringArray::fromTokens (version, ",.", "");
  1437. versionParts.trim();
  1438. versionParts.removeEmptyStrings();
  1439. while (versionParts.size() < 4)
  1440. versionParts.add ("0");
  1441. return versionParts.joinIntoString (",");
  1442. }
  1443. static String prependDot (const String& filename)
  1444. {
  1445. return FileHelpers::isAbsolutePath (filename) ? filename
  1446. : (".\\" + filename);
  1447. }
  1448. static bool shouldUseStdCall (const RelativePath& path)
  1449. {
  1450. return path.getFileNameWithoutExtension().startsWithIgnoreCase ("juce_audio_plugin_client_RTAS_");
  1451. }
  1452. StringArray getModuleLibs() const
  1453. {
  1454. StringArray result;
  1455. for (auto& lib : windowsLibs)
  1456. result.add (lib + ".lib");
  1457. return result;
  1458. }
  1459. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase)
  1460. };
  1461. //==============================================================================
  1462. class MSVCProjectExporterVC2013 : public MSVCProjectExporterBase
  1463. {
  1464. public:
  1465. MSVCProjectExporterVC2013 (Project& p, const ValueTree& t)
  1466. : MSVCProjectExporterBase (p, t, getTargetFolderForExporter (getValueTreeTypeName()))
  1467. {
  1468. name = getName();
  1469. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1470. platformToolsetValue.setDefault (getDefaultToolset());
  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[] = { "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1489. const var toolsets[] = { "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, getTargetFolderForExporter (getValueTreeTypeName()))
  1502. {
  1503. name = getName();
  1504. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1505. platformToolsetValue.setDefault (getDefaultToolset());
  1506. }
  1507. static const char* getName() { return "Visual Studio 2015"; }
  1508. static const char* getValueTreeTypeName() { return "VS2015"; }
  1509. int getVisualStudioVersion() const override { return 14; }
  1510. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1511. String getToolsVersion() const override { return "14.0"; }
  1512. String getDefaultToolset() const override { return "v140"; }
  1513. String getDefaultWindowsTargetPlatformVersion() const override { return "8.1"; }
  1514. static MSVCProjectExporterVC2015* createForSettings (Project& project, const ValueTree& settings)
  1515. {
  1516. if (settings.hasType (getValueTreeTypeName()))
  1517. return new MSVCProjectExporterVC2015 (project, settings);
  1518. return nullptr;
  1519. }
  1520. void createExporterProperties (PropertyListBuilder& props) override
  1521. {
  1522. MSVCProjectExporterBase::createExporterProperties (props);
  1523. static const char* toolsetNames[] = { "v140", "v140_xp", "CTP_Nov2013" };
  1524. const var toolsets[] = { "v140", "v140_xp", "CTP_Nov2013" };
  1525. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1526. addIPPLibraryProperty (props);
  1527. addWindowsTargetPlatformProperties (props);
  1528. }
  1529. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1530. };
  1531. //==============================================================================
  1532. class MSVCProjectExporterVC2017 : public MSVCProjectExporterBase
  1533. {
  1534. public:
  1535. MSVCProjectExporterVC2017 (Project& p, const ValueTree& t)
  1536. : MSVCProjectExporterBase (p, t, getTargetFolderForExporter (getValueTreeTypeName()))
  1537. {
  1538. name = getName();
  1539. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1540. platformToolsetValue.setDefault (getDefaultToolset());
  1541. }
  1542. static const char* getName() { return "Visual Studio 2017"; }
  1543. static const char* getValueTreeTypeName() { return "VS2017"; }
  1544. int getVisualStudioVersion() const override { return 15; }
  1545. String getSolutionComment() const override { return "# Visual Studio 2017"; }
  1546. String getToolsVersion() const override { return "15.0"; }
  1547. String getDefaultToolset() const override { return "v141"; }
  1548. String getDefaultWindowsTargetPlatformVersion() const override { return "10.0.16299.0"; }
  1549. static MSVCProjectExporterVC2017* createForSettings (Project& project, const ValueTree& settings)
  1550. {
  1551. if (settings.hasType (getValueTreeTypeName()))
  1552. return new MSVCProjectExporterVC2017 (project, settings);
  1553. return nullptr;
  1554. }
  1555. void createExporterProperties (PropertyListBuilder& props) override
  1556. {
  1557. MSVCProjectExporterBase::createExporterProperties (props);
  1558. static const char* toolsetNames[] = { "v140", "v140_xp", "v141", "v141_xp" };
  1559. const var toolsets[] = { "v140", "v140_xp", "v141", "v141_xp" };
  1560. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1561. addIPPLibraryProperty (props);
  1562. addWindowsTargetPlatformProperties (props);
  1563. }
  1564. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2017)
  1565. };