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.

1940 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. auto librarySearchPaths = getLibrarySearchPaths (config);
  389. if (librarySearchPaths.size() > 0)
  390. {
  391. auto* libPath = props->createNewChildElement ("LibraryPath");
  392. setConditionAttribute (*libPath, config);
  393. libPath->addTextElement ("$(LibraryPath);" + librarySearchPaths.joinIntoString (";"));
  394. }
  395. }
  396. }
  397. for (ConstConfigIterator i (owner); i.next();)
  398. {
  399. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  400. bool isDebug = config.isDebug();
  401. auto* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  402. setConditionAttribute (*group, config);
  403. {
  404. auto* midl = group->createNewChildElement ("Midl");
  405. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  406. : "NDEBUG;%(PreprocessorDefinitions)");
  407. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  408. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  409. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  410. midl->createNewChildElement ("HeaderFileName");
  411. }
  412. bool isUsingEditAndContinue = false;
  413. {
  414. auto* cl = group->createNewChildElement ("ClCompile");
  415. cl->createNewChildElement ("Optimization")->addTextElement (getOptimisationLevelString (config.getOptimisationLevelInt()));
  416. if (isDebug || config.shouldGenerateDebugSymbols())
  417. {
  418. cl->createNewChildElement ("DebugInformationFormat")
  419. ->addTextElement (config.getDebugInformationFormatString());
  420. }
  421. auto includePaths = getOwner().getHeaderSearchPaths (config);
  422. includePaths.addArray (getExtraSearchPaths());
  423. includePaths.add ("%(AdditionalIncludeDirectories)");
  424. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  425. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (config, ";") + ";%(PreprocessorDefinitions)");
  426. bool runtimeDLL = config.isUsingRuntimeLibDLL();
  427. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (runtimeDLL ? (isDebug ? "MultiThreadedDebugDLL" : "MultiThreadedDLL")
  428. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  429. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  430. cl->createNewChildElement ("PrecompiledHeader");
  431. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement ("$(IntDir)\\");
  432. cl->createNewChildElement ("ObjectFileName")->addTextElement ("$(IntDir)\\");
  433. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement ("$(IntDir)\\");
  434. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (config.getWarningLevel()));
  435. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  436. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  437. if (config.isFastMathEnabled())
  438. cl->createNewChildElement ("FloatingPointModel")->addTextElement ("Fast");
  439. auto extraFlags = getOwner().replacePreprocessorTokens (config, getOwner().getExtraCompilerFlagsString()).trim();
  440. if (extraFlags.isNotEmpty())
  441. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  442. if (config.areWarningsTreatedAsErrors())
  443. cl->createNewChildElement ("TreatWarningAsError")->addTextElement ("true");
  444. auto cppStandard = owner.project.getCppStandardString();
  445. if (cppStandard == "11") // VS doesn't support the C++11 flag so we have to bump it to C++14
  446. cppStandard = "14";
  447. else if (cppStandard == "17") // nor does it support the C++17 flag, so we'll just use latest for now until it's added
  448. cppStandard = "latest";
  449. cl->createNewChildElement ("LanguageStandard")->addTextElement ("stdcpp" + cppStandard);
  450. }
  451. {
  452. auto* res = group->createNewChildElement ("ResourceCompile");
  453. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  454. : "NDEBUG;%(PreprocessorDefinitions)");
  455. }
  456. auto externalLibraries = getExternalLibraries (config, getOwner().getExternalLibrariesString());
  457. auto additionalDependencies = externalLibraries.isNotEmpty() ? getOwner().replacePreprocessorTokens (config, externalLibraries).trim() + ";%(AdditionalDependencies)"
  458. : String();
  459. auto librarySearchPaths = config.getLibrarySearchPaths();
  460. auto additionalLibraryDirs = librarySearchPaths.size() > 0 ? getOwner().replacePreprocessorTokens (config, librarySearchPaths.joinIntoString (";")) + ";%(AdditionalLibraryDirectories)"
  461. : String();
  462. {
  463. auto* link = group->createNewChildElement ("Link");
  464. link->createNewChildElement ("OutputFile")->addTextElement (getOutputFilePath (config));
  465. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  466. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  467. : "%(IgnoreSpecificDefaultLibraries)");
  468. link->createNewChildElement ("GenerateDebugInformation")->addTextElement ((isDebug || config.shouldGenerateDebugSymbols()) ? "true" : "false");
  469. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (getOwner().getIntDirFile (config, config.getOutputFilename (".pdb", true)));
  470. link->createNewChildElement ("SubSystem")->addTextElement (type == ConsoleApp ? "Console" : "Windows");
  471. if (! config.is64Bit())
  472. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  473. if (isUsingEditAndContinue)
  474. link->createNewChildElement ("ImageHasSafeExceptionHandlers")->addTextElement ("false");
  475. if (! isDebug)
  476. {
  477. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  478. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  479. }
  480. if (additionalLibraryDirs.isNotEmpty())
  481. link->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (additionalLibraryDirs);
  482. link->createNewChildElement ("LargeAddressAware")->addTextElement ("true");
  483. if (additionalDependencies.isNotEmpty())
  484. link->createNewChildElement ("AdditionalDependencies")->addTextElement (additionalDependencies);
  485. auto extraLinkerOptions = getOwner().getExtraLinkerFlagsString();
  486. if (extraLinkerOptions.isNotEmpty())
  487. link->createNewChildElement ("AdditionalOptions")->addTextElement (getOwner().replacePreprocessorTokens (config, extraLinkerOptions).trim()
  488. + " %(AdditionalOptions)");
  489. auto delayLoadedDLLs = getDelayLoadedDLLs();
  490. if (delayLoadedDLLs.isNotEmpty())
  491. link->createNewChildElement ("DelayLoadDLLs")->addTextElement (delayLoadedDLLs);
  492. auto moduleDefinitionsFile = getModuleDefinitions (config);
  493. if (moduleDefinitionsFile.isNotEmpty())
  494. link->createNewChildElement ("ModuleDefinitionFile")
  495. ->addTextElement (moduleDefinitionsFile);
  496. }
  497. {
  498. auto* bsc = group->createNewChildElement ("Bscmake");
  499. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  500. bsc->createNewChildElement ("OutputFile")->addTextElement (getOwner().getIntDirFile (config, config.getOutputFilename (".bsc", true)));
  501. }
  502. {
  503. auto* lib = group->createNewChildElement ("Lib");
  504. if (additionalDependencies.isNotEmpty())
  505. lib->createNewChildElement ("AdditionalDependencies")->addTextElement (additionalDependencies);
  506. if (additionalLibraryDirs.isNotEmpty())
  507. lib->createNewChildElement ("AdditionalLibraryDirectories")->addTextElement (additionalLibraryDirs);
  508. }
  509. auto manifestFile = getOwner().getManifestPath();
  510. if (manifestFile.getRoot() != RelativePath::unknown)
  511. {
  512. auto* bsc = group->createNewChildElement ("Manifest");
  513. bsc->createNewChildElement ("AdditionalManifestFiles")
  514. ->addTextElement (manifestFile.rebased (getOwner().getProject().getFile().getParentDirectory(),
  515. getOwner().getTargetFolder(),
  516. RelativePath::buildTargetFolder).toWindowsStyle());
  517. }
  518. if (getTargetFileType() == staticLibrary && ! config.is64Bit())
  519. {
  520. auto* lib = group->createNewChildElement ("Lib");
  521. lib->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  522. }
  523. auto preBuild = getPreBuildSteps (config);
  524. if (preBuild.isNotEmpty())
  525. group->createNewChildElement ("PreBuildEvent")
  526. ->createNewChildElement ("Command")
  527. ->addTextElement (preBuild);
  528. auto postBuild = getPostBuildSteps (config);
  529. if (postBuild.isNotEmpty())
  530. group->createNewChildElement ("PostBuildEvent")
  531. ->createNewChildElement ("Command")
  532. ->addTextElement (postBuild);
  533. }
  534. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  535. {
  536. auto* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  537. auto* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  538. for (int i = 0; i < getOwner().getAllGroups().size(); ++i)
  539. {
  540. auto& group = getOwner().getAllGroups().getReference (i);
  541. if (group.getNumChildren() > 0)
  542. addFilesToCompile (group, *cppFiles, *headerFiles, *otherFilesGroup);
  543. }
  544. }
  545. if (getOwner().iconFile != File())
  546. {
  547. auto* e = otherFilesGroup->createNewChildElement ("None");
  548. e->setAttribute ("Include", prependDot (getOwner().iconFile.getFileName()));
  549. }
  550. if (otherFilesGroup->getFirstChildElement() != nullptr)
  551. projectXml.addChildElement (otherFilesGroup.release());
  552. if (getOwner().hasResourceFile())
  553. {
  554. auto* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  555. auto* e = rcGroup->createNewChildElement ("ResourceCompile");
  556. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  557. }
  558. {
  559. auto* e = projectXml.createNewChildElement ("Import");
  560. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  561. }
  562. {
  563. auto* e = projectXml.createNewChildElement ("ImportGroup");
  564. e->setAttribute ("Label", "ExtensionTargets");
  565. }
  566. getOwner().addPlatformToolsetToPropertyGroup (projectXml);
  567. getOwner().addWindowsTargetPlatformVersionToPropertyGroup (projectXml);
  568. getOwner().addIPPSettingToPropertyGroup (projectXml);
  569. }
  570. String getProjectType() const
  571. {
  572. switch (getTargetFileType())
  573. {
  574. case executable:
  575. return "Application";
  576. case staticLibrary:
  577. return "StaticLibrary";
  578. default:
  579. break;
  580. }
  581. return "DynamicLibrary";
  582. }
  583. //==============================================================================
  584. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  585. {
  586. auto targetType = (getOwner().getProject().getProjectType().isAudioPlugin() ? type : SharedCodeTarget);
  587. if (projectItem.isGroup())
  588. {
  589. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  590. addFilesToCompile (projectItem.getChild (i), cpps, headers, otherFiles);
  591. }
  592. else if (projectItem.shouldBeAddedToTargetProject()
  593. && getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType)
  594. {
  595. RelativePath path (projectItem.getFile(), getOwner().getTargetFolder(), RelativePath::buildTargetFolder);
  596. jassert (path.getRoot() == RelativePath::buildTargetFolder);
  597. if (path.hasFileExtension (cOrCppFileExtensions) || path.hasFileExtension (asmFileExtensions))
  598. {
  599. if (targetType == SharedCodeTarget || projectItem.shouldBeCompiled())
  600. {
  601. auto* e = cpps.createNewChildElement ("ClCompile");
  602. e->setAttribute ("Include", path.toWindowsStyle());
  603. if (shouldUseStdCall (path))
  604. e->createNewChildElement ("CallingConvention")->addTextElement ("StdCall");
  605. if (! projectItem.shouldBeCompiled())
  606. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  607. }
  608. }
  609. else if (path.hasFileExtension (headerFileExtensions))
  610. {
  611. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", path.toWindowsStyle());
  612. }
  613. else if (! path.hasFileExtension (objCFileExtensions))
  614. {
  615. otherFiles.createNewChildElement ("None")->setAttribute ("Include", path.toWindowsStyle());
  616. }
  617. }
  618. }
  619. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config) const
  620. {
  621. auto& msvcConfig = dynamic_cast<const MSVCBuildConfiguration&> (config);
  622. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + msvcConfig.createMSVCConfigName() + "'");
  623. }
  624. //==============================================================================
  625. void addFilterGroup (XmlElement& groups, const String& path) const
  626. {
  627. auto* e = groups.createNewChildElement ("Filter");
  628. e->setAttribute ("Include", path);
  629. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  630. }
  631. void addFileToFilter (const RelativePath& file, const String& groupPath,
  632. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles) const
  633. {
  634. XmlElement* e = nullptr;
  635. if (file.hasFileExtension (headerFileExtensions))
  636. e = headers.createNewChildElement ("ClInclude");
  637. else if (file.hasFileExtension (sourceFileExtensions))
  638. e = cpps.createNewChildElement ("ClCompile");
  639. else
  640. e = otherFiles.createNewChildElement ("None");
  641. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  642. e->setAttribute ("Include", file.toWindowsStyle());
  643. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  644. }
  645. bool addFilesToFilter (const Project::Item& projectItem, const String& path,
  646. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups) const
  647. {
  648. auto targetType = (getOwner().getProject().getProjectType().isAudioPlugin() ? type : SharedCodeTarget);
  649. if (projectItem.isGroup())
  650. {
  651. bool filesWereAdded = false;
  652. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  653. if (addFilesToFilter (projectItem.getChild(i),
  654. (path.isEmpty() ? String() : (path + "\\")) + projectItem.getChild(i).getName(),
  655. cpps, headers, otherFiles, groups))
  656. filesWereAdded = true;
  657. if (filesWereAdded)
  658. addFilterGroup (groups, path);
  659. return filesWereAdded;
  660. }
  661. else if (projectItem.shouldBeAddedToTargetProject())
  662. {
  663. RelativePath relativePath (projectItem.getFile(), getOwner().getTargetFolder(), RelativePath::buildTargetFolder);
  664. jassert (relativePath.getRoot() == RelativePath::buildTargetFolder);
  665. if (getOwner().getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType
  666. && (targetType == SharedCodeTarget || projectItem.shouldBeCompiled()))
  667. {
  668. addFileToFilter (relativePath, path.upToLastOccurrenceOf ("\\", false, false), cpps, headers, otherFiles);
  669. return true;
  670. }
  671. }
  672. return false;
  673. }
  674. bool addFilesToFilter (const Array<RelativePath>& files, const String& path,
  675. XmlElement& cpps, XmlElement& headers, XmlElement& otherFiles, XmlElement& groups)
  676. {
  677. if (files.size() > 0)
  678. {
  679. addFilterGroup (groups, path);
  680. for (int i = 0; i < files.size(); ++i)
  681. addFileToFilter (files.getReference(i), path, cpps, headers, otherFiles);
  682. return true;
  683. }
  684. return false;
  685. }
  686. void fillInFiltersXml (XmlElement& filterXml) const
  687. {
  688. filterXml.setAttribute ("ToolsVersion", getOwner().getToolsVersion());
  689. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  690. auto* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  691. auto* cpps = filterXml.createNewChildElement ("ItemGroup");
  692. auto* headers = filterXml.createNewChildElement ("ItemGroup");
  693. ScopedPointer<XmlElement> otherFilesGroup (new XmlElement ("ItemGroup"));
  694. for (int i = 0; i < getOwner().getAllGroups().size(); ++i)
  695. {
  696. auto& group = getOwner().getAllGroups().getReference(i);
  697. if (group.getNumChildren() > 0)
  698. addFilesToFilter (group, group.getName(), *cpps, *headers, *otherFilesGroup, *groupsXml);
  699. }
  700. if (getOwner().iconFile.exists())
  701. {
  702. auto* e = otherFilesGroup->createNewChildElement ("None");
  703. e->setAttribute ("Include", prependDot (getOwner().iconFile.getFileName()));
  704. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  705. }
  706. if (otherFilesGroup->getFirstChildElement() != nullptr)
  707. filterXml.addChildElement (otherFilesGroup.release());
  708. if (getOwner().hasResourceFile())
  709. {
  710. auto* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  711. auto* e = rcGroup->createNewChildElement ("ResourceCompile");
  712. e->setAttribute ("Include", prependDot (getOwner().rcFile.getFileName()));
  713. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  714. }
  715. }
  716. const MSVCProjectExporterBase& getOwner() const { return owner; }
  717. const String& getProjectGuid() const { return projectGuid; }
  718. //==============================================================================
  719. void writeProjectFile()
  720. {
  721. {
  722. XmlElement projectXml (getTopLevelXmlEntity());
  723. fillInProjectXml (projectXml);
  724. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  725. }
  726. {
  727. XmlElement filtersXml (getTopLevelXmlEntity());
  728. fillInFiltersXml (filtersXml);
  729. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "UTF-8", 100);
  730. }
  731. }
  732. String getSolutionTargetPath (const BuildConfiguration& config) const
  733. {
  734. auto binaryPath = config.getTargetBinaryRelativePathString().trim();
  735. if (binaryPath.isEmpty())
  736. return "$(SolutionDir)$(Platform)\\$(Configuration)";
  737. RelativePath binaryRelPath (binaryPath, RelativePath::projectFolder);
  738. if (binaryRelPath.isAbsolute())
  739. return binaryRelPath.toWindowsStyle();
  740. return prependDot (binaryRelPath.rebased (getOwner().projectFolder, getOwner().getTargetFolder(), RelativePath::buildTargetFolder)
  741. .toWindowsStyle());
  742. }
  743. String getConfigTargetPath (const BuildConfiguration& config) const
  744. {
  745. auto solutionTargetFolder = getSolutionTargetPath (config);
  746. return solutionTargetFolder + "\\" + getName();
  747. }
  748. String getIntermediatesPath (const MSVCBuildConfiguration& config) const
  749. {
  750. auto intDir = (config.getIntermediatesPathString().isNotEmpty() ? config.getIntermediatesPathString()
  751. : "$(Platform)\\$(Configuration)");
  752. if (! intDir.endsWithChar (L'\\'))
  753. intDir += L'\\';
  754. return intDir + getName();
  755. }
  756. static const char* getOptimisationLevelString (int level)
  757. {
  758. switch (level)
  759. {
  760. case optimiseMinSize: return "MinSpace";
  761. case optimiseMaxSpeed: return "MaxSpeed";
  762. case optimiseFull: return "Full";
  763. default: return "Disabled";
  764. }
  765. }
  766. String getTargetSuffix() const
  767. {
  768. auto fileType = getTargetFileType();
  769. switch (fileType)
  770. {
  771. case executable: return ".exe";
  772. case staticLibrary: return ".lib";
  773. case sharedLibraryOrDLL: return ".dll";
  774. case pluginBundle:
  775. switch (type)
  776. {
  777. case VST3PlugIn: return ".vst3";
  778. case AAXPlugIn: return ".aaxdll";
  779. case RTASPlugIn: return ".dpm";
  780. default: break;
  781. }
  782. return ".dll";
  783. default:
  784. break;
  785. }
  786. return {};
  787. }
  788. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  789. {
  790. auto* e = parent.createNewChildElement ("Tool");
  791. e->setAttribute ("Name", toolName);
  792. return e;
  793. }
  794. String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const
  795. {
  796. auto defines = getOwner().msvcExtraPreprocessorDefs;
  797. defines.set ("WIN32", "");
  798. defines.set ("_WINDOWS", "");
  799. if (config.isDebug())
  800. {
  801. defines.set ("DEBUG", "");
  802. defines.set ("_DEBUG", "");
  803. }
  804. else
  805. {
  806. defines.set ("NDEBUG", "");
  807. }
  808. defines = mergePreprocessorDefs (defines, getOwner().getAllPreprocessorDefs (config, type));
  809. addExtraPreprocessorDefines (defines);
  810. if (getTargetFileType() == staticLibrary || getTargetFileType() == sharedLibraryOrDLL)
  811. defines.set("_LIB", "");
  812. StringArray result;
  813. for (int i = 0; i < defines.size(); ++i)
  814. {
  815. auto def = defines.getAllKeys()[i];
  816. auto value = defines.getAllValues()[i];
  817. if (value.isNotEmpty())
  818. def << "=" << value;
  819. result.add (def);
  820. }
  821. return result.joinIntoString (joinString);
  822. }
  823. //==============================================================================
  824. RelativePath getAAXIconFile() const
  825. {
  826. RelativePath aaxSDK (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder);
  827. RelativePath projectIcon ("icon.ico", RelativePath::buildTargetFolder);
  828. if (getOwner().getTargetFolder().getChildFile ("icon.ico").existsAsFile())
  829. return projectIcon.rebased (getOwner().getTargetFolder(),
  830. getOwner().getProject().getProjectFolder(),
  831. RelativePath::projectFolder);
  832. return aaxSDK.getChildFile ("Utilities").getChildFile ("PlugIn.ico");
  833. }
  834. String getExtraPostBuildSteps (const MSVCBuildConfiguration& config) const
  835. {
  836. if (type == AAXPlugIn)
  837. {
  838. RelativePath aaxSDK (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder);
  839. RelativePath aaxLibsFolder = aaxSDK.getChildFile ("Libs");
  840. RelativePath bundleScript = aaxSDK.getChildFile ("Utilities").getChildFile ("CreatePackage.bat");
  841. RelativePath iconFilePath = getAAXIconFile();
  842. auto outputFilename = config.getOutputFilename (".aaxplugin", true);
  843. auto bundleDir = getOwner().getOutDirFile (config, outputFilename);
  844. auto bundleContents = bundleDir + "\\Contents";
  845. auto archDir = bundleContents + String ("\\") + (config.is64Bit() ? "x64" : "Win32");
  846. auto executable = archDir + String ("\\") + outputFilename;
  847. auto pkgScript = String ("copy /Y ") + getOutputFilePath (config).quoted() + String (" ") + executable.quoted() + String ("\r\ncall ")
  848. + createRebasedPath (bundleScript) + String (" ") + archDir.quoted() + String (" ") + createRebasedPath (iconFilePath);
  849. if (config.isPluginBinaryCopyStepEnabled())
  850. return pkgScript + "\r\n" + "xcopy " + bundleDir.quoted() + " "
  851. + String (config.getAAXBinaryLocationString() + "\\" + outputFilename + "\\").quoted() + " /E /H /K /R /Y";
  852. return pkgScript;
  853. }
  854. else if (config.isPluginBinaryCopyStepEnabled())
  855. {
  856. auto copyScript = String ("copy /Y \"$(OutDir)$(TargetFileName)\"") + String (" \"$COPYDIR$\\$(TargetFileName)\"");
  857. if (type == VSTPlugIn) return copyScript.replace ("$COPYDIR$", config.getVSTBinaryLocationString());
  858. if (type == VST3PlugIn) return copyScript.replace ("$COPYDIR$", config.getVST3BinaryLocationString());
  859. if (type == RTASPlugIn) return copyScript.replace ("$COPYDIR$", config.getRTASBinaryLocationString());
  860. }
  861. return {};
  862. }
  863. String getExtraPreBuildSteps (const MSVCBuildConfiguration& config) const
  864. {
  865. if (type == AAXPlugIn)
  866. {
  867. String script;
  868. auto bundleDir = getOwner().getOutDirFile (config, config.getOutputFilename (".aaxplugin", false));
  869. auto bundleContents = bundleDir + "\\Contents";
  870. auto archDir = bundleContents + String ("\\") + (config.is64Bit() ? "x64" : "Win32");
  871. for (auto& folder : StringArray { bundleDir, bundleContents, archDir })
  872. script += String ("if not exist \"") + folder + String ("\" mkdir \"") + folder + String ("\"\r\n");
  873. return script;
  874. }
  875. return {};
  876. }
  877. String getPostBuildSteps (const MSVCBuildConfiguration& config) const
  878. {
  879. auto postBuild = config.getPostbuildCommandString();
  880. auto extraPostBuild = getExtraPostBuildSteps (config);
  881. return postBuild + String (postBuild.isNotEmpty() && extraPostBuild.isNotEmpty() ? "\r\n" : "") + extraPostBuild;
  882. }
  883. String getPreBuildSteps (const MSVCBuildConfiguration& config) const
  884. {
  885. auto preBuild = config.getPrebuildCommandString();
  886. auto extraPreBuild = getExtraPreBuildSteps (config);
  887. return preBuild + String (preBuild.isNotEmpty() && extraPreBuild.isNotEmpty() ? "\r\n" : "") + extraPreBuild;
  888. }
  889. void addExtraPreprocessorDefines (StringPairArray& defines) const
  890. {
  891. switch (type)
  892. {
  893. case AAXPlugIn:
  894. {
  895. auto aaxLibsFolder = RelativePath (getOwner().getAAXPathValue().toString(), RelativePath::projectFolder).getChildFile ("Libs");
  896. defines.set ("JucePlugin_AAXLibs_path", createRebasedPath (aaxLibsFolder));
  897. }
  898. break;
  899. case RTASPlugIn:
  900. {
  901. RelativePath rtasFolder (getOwner().getRTASPathValue().toString(), RelativePath::projectFolder);
  902. defines.set ("JucePlugin_WinBag_path", createRebasedPath (rtasFolder.getChildFile ("WinBag")));
  903. }
  904. break;
  905. default:
  906. break;
  907. }
  908. }
  909. String getExtraLinkerFlags() const
  910. {
  911. if (type == RTASPlugIn)
  912. return "/FORCE:multiple";
  913. return {};
  914. }
  915. StringArray getExtraSearchPaths() const
  916. {
  917. StringArray searchPaths;
  918. if (type == RTASPlugIn)
  919. {
  920. RelativePath rtasFolder (getOwner().getRTASPathValue().toString(), RelativePath::projectFolder);
  921. static const char* p[] = { "AlturaPorts/TDMPlugins/PluginLibrary/EffectClasses",
  922. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses",
  923. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses/Interfaces",
  924. "AlturaPorts/TDMPlugins/PluginLibrary/Utilities",
  925. "AlturaPorts/TDMPlugins/PluginLibrary/RTASP_Adapt",
  926. "AlturaPorts/TDMPlugins/PluginLibrary/CoreClasses",
  927. "AlturaPorts/TDMPlugins/PluginLibrary/Controls",
  928. "AlturaPorts/TDMPlugins/PluginLibrary/Meters",
  929. "AlturaPorts/TDMPlugins/PluginLibrary/ViewClasses",
  930. "AlturaPorts/TDMPlugins/PluginLibrary/DSPClasses",
  931. "AlturaPorts/TDMPlugins/PluginLibrary/Interfaces",
  932. "AlturaPorts/TDMPlugins/common",
  933. "AlturaPorts/TDMPlugins/common/Platform",
  934. "AlturaPorts/TDMPlugins/common/Macros",
  935. "AlturaPorts/TDMPlugins/SignalProcessing/Public",
  936. "AlturaPorts/TDMPlugIns/DSPManager/Interfaces",
  937. "AlturaPorts/SADriver/Interfaces",
  938. "AlturaPorts/DigiPublic/Interfaces",
  939. "AlturaPorts/DigiPublic",
  940. "AlturaPorts/Fic/Interfaces/DAEClient",
  941. "AlturaPorts/NewFileLibs/Cmn",
  942. "AlturaPorts/NewFileLibs/DOA",
  943. "AlturaPorts/AlturaSource/PPC_H",
  944. "AlturaPorts/AlturaSource/AppSupport",
  945. "AvidCode/AVX2sdk/AVX/avx2/avx2sdk/inc",
  946. "xplat/AVX/avx2/avx2sdk/inc" };
  947. for (auto* path : p)
  948. searchPaths.add (createRebasedPath (rtasFolder.getChildFile (path)));
  949. }
  950. return searchPaths;
  951. }
  952. String getBinaryNameWithSuffix (const MSVCBuildConfiguration& config) const
  953. {
  954. return config.getOutputFilename (getTargetSuffix(), true);
  955. }
  956. String getOutputFilePath (const MSVCBuildConfiguration& config) const
  957. {
  958. return getOwner().getOutDirFile (config, getBinaryNameWithSuffix (config));
  959. }
  960. StringArray getLibrarySearchPaths (const BuildConfiguration& config) const
  961. {
  962. auto librarySearchPaths = config.getLibrarySearchPaths();
  963. if (type != SharedCodeTarget)
  964. if (auto* shared = getOwner().getSharedCodeTarget())
  965. librarySearchPaths.add (shared->getConfigTargetPath (config));
  966. return librarySearchPaths;
  967. }
  968. String getExternalLibraries (const MSVCBuildConfiguration& config, const String& otherLibs) const
  969. {
  970. StringArray libraries;
  971. if (otherLibs.isNotEmpty())
  972. libraries.add (otherLibs);
  973. auto moduleLibs = getOwner().getModuleLibs();
  974. if (! moduleLibs.isEmpty())
  975. libraries.addArray (moduleLibs);
  976. if (type != SharedCodeTarget)
  977. if (auto* shared = getOwner().getSharedCodeTarget())
  978. libraries.add (shared->getBinaryNameWithSuffix (config));
  979. return libraries.joinIntoString (";");
  980. }
  981. String getDelayLoadedDLLs() const
  982. {
  983. auto delayLoadedDLLs = getOwner().msvcDelayLoadedDLLs;
  984. if (type == RTASPlugIn)
  985. delayLoadedDLLs += "DAE.dll; DigiExt.dll; DSI.dll; PluginLib.dll; "
  986. "DSPManager.dll; DSPManager.dll; DSPManagerClientLib.dll; RTASClientLib.dll";
  987. return delayLoadedDLLs;
  988. }
  989. String getModuleDefinitions (const MSVCBuildConfiguration& config) const
  990. {
  991. auto moduleDefinitions = config.config [Ids::msvcModuleDefinitionFile].toString();
  992. if (moduleDefinitions.isNotEmpty())
  993. return moduleDefinitions;
  994. if (type == RTASPlugIn)
  995. {
  996. auto& exp = getOwner();
  997. auto moduleDefPath
  998. = RelativePath (exp.getPathForModuleString ("juce_audio_plugin_client"), RelativePath::projectFolder)
  999. .getChildFile ("juce_audio_plugin_client").getChildFile ("RTAS").getChildFile ("juce_RTAS_WinExports.def");
  1000. return prependDot (moduleDefPath.rebased (exp.getProject().getProjectFolder(),
  1001. exp.getTargetFolder(),
  1002. RelativePath::buildTargetFolder).toWindowsStyle());
  1003. }
  1004. return {};
  1005. }
  1006. File getVCProjFile() const { return getOwner().getProjectFile (getProjectFileSuffix(), getName()); }
  1007. File getVCProjFiltersFile() const { return getOwner().getProjectFile (getFiltersFileSuffix(), getName()); }
  1008. String createRebasedPath (const RelativePath& path) const { return getOwner().createRebasedPath (path); }
  1009. protected:
  1010. const MSVCProjectExporterBase& owner;
  1011. String projectGuid;
  1012. };
  1013. //==============================================================================
  1014. bool usesMMFiles() const override { return false; }
  1015. bool canCopeWithDuplicateFiles() override { return false; }
  1016. bool supportsUserDefinedConfigurations() const override { return true; }
  1017. bool isXcode() const override { return false; }
  1018. bool isVisualStudio() const override { return true; }
  1019. bool isCodeBlocks() const override { return false; }
  1020. bool isMakefile() const override { return false; }
  1021. bool isAndroidStudio() const override { return false; }
  1022. bool isCLion() const override { return false; }
  1023. bool isAndroid() const override { return false; }
  1024. bool isWindows() const override { return true; }
  1025. bool isLinux() const override { return false; }
  1026. bool isOSX() const override { return false; }
  1027. bool isiOS() const override { return false; }
  1028. bool supportsTargetType (ProjectType::Target::Type type) const override
  1029. {
  1030. switch (type)
  1031. {
  1032. case ProjectType::Target::StandalonePlugIn:
  1033. case ProjectType::Target::GUIApp:
  1034. case ProjectType::Target::ConsoleApp:
  1035. case ProjectType::Target::StaticLibrary:
  1036. case ProjectType::Target::SharedCodeTarget:
  1037. case ProjectType::Target::AggregateTarget:
  1038. case ProjectType::Target::VSTPlugIn:
  1039. case ProjectType::Target::VST3PlugIn:
  1040. case ProjectType::Target::AAXPlugIn:
  1041. case ProjectType::Target::RTASPlugIn:
  1042. case ProjectType::Target::DynamicLibrary:
  1043. return true;
  1044. default:
  1045. break;
  1046. }
  1047. return false;
  1048. }
  1049. //==============================================================================
  1050. RelativePath getManifestPath() const
  1051. {
  1052. auto path = manifestFileValue.get().toString();
  1053. return path.isEmpty() ? RelativePath()
  1054. : RelativePath (path, RelativePath::projectFolder);
  1055. }
  1056. //==============================================================================
  1057. const String& getProjectName() const { return projectName; }
  1058. bool launchProject() override
  1059. {
  1060. #if JUCE_WINDOWS
  1061. return getSLNFile().startAsProcess();
  1062. #else
  1063. return false;
  1064. #endif
  1065. }
  1066. bool canLaunchProject() override
  1067. {
  1068. #if JUCE_WINDOWS
  1069. return true;
  1070. #else
  1071. return false;
  1072. #endif
  1073. }
  1074. void createExporterProperties (PropertyListBuilder& props) override
  1075. {
  1076. props.add (new TextPropertyComponent (manifestFileValue, "Manifest file", 8192, false),
  1077. "Path to a manifest input file which should be linked into your binary (path is relative to jucer file).");
  1078. }
  1079. enum OptimisationLevel
  1080. {
  1081. optimisationOff = 1,
  1082. optimiseMinSize = 2,
  1083. optimiseFull = 3,
  1084. optimiseMaxSpeed = 4
  1085. };
  1086. //==============================================================================
  1087. void addPlatformSpecificSettingsForProjectType (const ProjectType& type) override
  1088. {
  1089. msvcExtraPreprocessorDefs.set ("_CRT_SECURE_NO_WARNINGS", "");
  1090. if (type.isCommandLineApp())
  1091. msvcExtraPreprocessorDefs.set("_CONSOLE", "");
  1092. callForAllSupportedTargets ([this] (ProjectType::Target::Type targetType)
  1093. {
  1094. if (MSVCTargetBase* target = new MSVCTargetBase (targetType, *this))
  1095. {
  1096. if (targetType != ProjectType::Target::AggregateTarget)
  1097. targets.add (target);
  1098. }
  1099. });
  1100. // If you hit this assert, you tried to generate a project for an exporter
  1101. // that does not support any of your targets!
  1102. jassert (targets.size() > 0);
  1103. }
  1104. const MSVCTargetBase* getSharedCodeTarget() const
  1105. {
  1106. for (auto target : targets)
  1107. if (target->type == ProjectType::Target::SharedCodeTarget)
  1108. return target;
  1109. return nullptr;
  1110. }
  1111. bool hasTarget (ProjectType::Target::Type type) const
  1112. {
  1113. for (auto target : targets)
  1114. if (target->type == type)
  1115. return true;
  1116. return false;
  1117. }
  1118. private:
  1119. //==============================================================================
  1120. String createRebasedPath (const RelativePath& path) const
  1121. {
  1122. auto rebasedPath = rebaseFromProjectFolderToBuildTarget (path).toWindowsStyle();
  1123. return getVisualStudioVersion() < 10 // (VS10 automatically adds escape characters to the quotes for this definition)
  1124. ? CppTokeniserFunctions::addEscapeChars (rebasedPath.quoted())
  1125. : CppTokeniserFunctions::addEscapeChars (rebasedPath).quoted();
  1126. }
  1127. protected:
  1128. //==============================================================================
  1129. mutable File rcFile, iconFile;
  1130. OwnedArray<MSVCTargetBase> targets;
  1131. ValueWithDefault IPPLibraryValue, platformToolsetValue, targetPlatformVersion, manifestFileValue;
  1132. File getProjectFile (const String& extension, const String& target) const
  1133. {
  1134. auto filename = project.getProjectFilenameRootString();
  1135. if (target.isNotEmpty())
  1136. filename += String ("_") + target.removeCharacters (" ");
  1137. return getTargetFolder().getChildFile (filename).withFileExtension (extension);
  1138. }
  1139. File getSLNFile() const { return getProjectFile (".sln", String()); }
  1140. static String prependIfNotAbsolute (const String& file, const char* prefix)
  1141. {
  1142. if (File::isAbsolutePath (file) || file.startsWithChar ('$'))
  1143. prefix = "";
  1144. return prefix + FileHelpers::windowsStylePath (file);
  1145. }
  1146. String getIntDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(IntDir)\\"); }
  1147. String getOutDirFile (const BuildConfiguration& config, const String& file) const { return prependIfNotAbsolute (replacePreprocessorTokens (config, file), "$(OutDir)\\"); }
  1148. void updateOldSettings()
  1149. {
  1150. {
  1151. auto oldStylePrebuildCommand = getSettingString (Ids::prebuildCommand);
  1152. settings.removeProperty (Ids::prebuildCommand, nullptr);
  1153. if (oldStylePrebuildCommand.isNotEmpty())
  1154. for (ConfigIterator config (*this); config.next();)
  1155. dynamic_cast<MSVCBuildConfiguration&> (*config).getValue (Ids::prebuildCommand) = oldStylePrebuildCommand;
  1156. }
  1157. {
  1158. auto oldStyleLibName = getSettingString ("libraryName_Debug");
  1159. settings.removeProperty ("libraryName_Debug", nullptr);
  1160. if (oldStyleLibName.isNotEmpty())
  1161. for (ConfigIterator config (*this); config.next();)
  1162. if (config->isDebug())
  1163. config->getValue (Ids::targetName) = oldStyleLibName;
  1164. }
  1165. {
  1166. auto oldStyleLibName = getSettingString ("libraryName_Release");
  1167. settings.removeProperty ("libraryName_Release", nullptr);
  1168. if (oldStyleLibName.isNotEmpty())
  1169. for (ConfigIterator config (*this); config.next();)
  1170. if (! config->isDebug())
  1171. config->getValue (Ids::targetName) = oldStyleLibName;
  1172. }
  1173. }
  1174. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  1175. {
  1176. return new MSVCBuildConfiguration (project, v, *this);
  1177. }
  1178. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  1179. {
  1180. auto searchPaths = extraSearchPaths;
  1181. searchPaths.addArray (config.getHeaderSearchPaths());
  1182. return getCleanedStringArray (searchPaths);
  1183. }
  1184. String getSharedCodeGuid() const
  1185. {
  1186. String sharedCodeGuid;
  1187. for (int i = 0; i < targets.size(); ++i)
  1188. if (auto* target = targets[i])
  1189. if (target->type == ProjectType::Target::SharedCodeTarget)
  1190. return target->getProjectGuid();
  1191. return {};
  1192. }
  1193. //==============================================================================
  1194. void writeProjectDependencies (OutputStream& out) const
  1195. {
  1196. auto sharedCodeGuid = getSharedCodeGuid();
  1197. for (int addingOtherTargets = 0; addingOtherTargets < (sharedCodeGuid.isNotEmpty() ? 2 : 1); ++addingOtherTargets)
  1198. {
  1199. for (int i = 0; i < targets.size(); ++i)
  1200. {
  1201. if (auto* target = targets[i])
  1202. {
  1203. if (sharedCodeGuid.isEmpty() || (addingOtherTargets != 0) == (target->type != ProjectType::Target::StandalonePlugIn))
  1204. {
  1205. out << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" << projectName << " - "
  1206. << target->getName() << "\", \""
  1207. << target->getVCProjFile().getFileName() << "\", \"" << target->getProjectGuid() << '"' << newLine;
  1208. if (sharedCodeGuid.isNotEmpty() && target->type != ProjectType::Target::SharedCodeTarget)
  1209. out << "\tProjectSection(ProjectDependencies) = postProject" << newLine
  1210. << "\t\t" << sharedCodeGuid << " = " << sharedCodeGuid << newLine
  1211. << "\tEndProjectSection" << newLine;
  1212. out << "EndProject" << newLine;
  1213. }
  1214. }
  1215. }
  1216. }
  1217. }
  1218. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString) const
  1219. {
  1220. if (commentString.isNotEmpty())
  1221. commentString += newLine;
  1222. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  1223. << commentString << newLine;
  1224. writeProjectDependencies (out);
  1225. out << "Global" << newLine
  1226. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  1227. for (ConstConfigIterator i (*this); i.next();)
  1228. {
  1229. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1230. auto configName = config.createMSVCConfigName();
  1231. out << "\t\t" << configName << " = " << configName << newLine;
  1232. }
  1233. out << "\tEndGlobalSection" << newLine
  1234. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  1235. for (auto& target : targets)
  1236. for (ConstConfigIterator i (*this); i.next();)
  1237. {
  1238. auto& config = dynamic_cast<const MSVCBuildConfiguration&> (*i);
  1239. auto configName = config.createMSVCConfigName();
  1240. for (auto& suffix : { "ActiveCfg", "Build.0" })
  1241. out << "\t\t" << target->getProjectGuid() << "." << configName << "." << suffix << " = " << configName << newLine;
  1242. }
  1243. out << "\tEndGlobalSection" << newLine
  1244. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  1245. << "\t\tHideSolutionNode = FALSE" << newLine
  1246. << "\tEndGlobalSection" << newLine;
  1247. out << "EndGlobal" << newLine;
  1248. }
  1249. //==============================================================================
  1250. static void writeBMPImage (const Image& image, const int w, const int h, MemoryOutputStream& out)
  1251. {
  1252. int maskStride = (w / 8 + 3) & ~3;
  1253. out.writeInt (40); // bitmapinfoheader size
  1254. out.writeInt (w);
  1255. out.writeInt (h * 2);
  1256. out.writeShort (1); // planes
  1257. out.writeShort (32); // bits
  1258. out.writeInt (0); // compression
  1259. out.writeInt ((h * w * 4) + (h * maskStride)); // size image
  1260. out.writeInt (0); // x pixels per meter
  1261. out.writeInt (0); // y pixels per meter
  1262. out.writeInt (0); // clr used
  1263. out.writeInt (0); // clr important
  1264. Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  1265. int alphaThreshold = 5;
  1266. int y;
  1267. for (y = h; --y >= 0;)
  1268. {
  1269. for (int x = 0; x < w; ++x)
  1270. {
  1271. auto pixel = bitmap.getPixelColour (x, y);
  1272. if (pixel.getAlpha() <= alphaThreshold)
  1273. {
  1274. out.writeInt (0);
  1275. }
  1276. else
  1277. {
  1278. out.writeByte ((char) pixel.getBlue());
  1279. out.writeByte ((char) pixel.getGreen());
  1280. out.writeByte ((char) pixel.getRed());
  1281. out.writeByte ((char) pixel.getAlpha());
  1282. }
  1283. }
  1284. }
  1285. for (y = h; --y >= 0;)
  1286. {
  1287. int mask = 0, count = 0;
  1288. for (int x = 0; x < w; ++x)
  1289. {
  1290. auto pixel = bitmap.getPixelColour (x, y);
  1291. mask <<= 1;
  1292. if (pixel.getAlpha() <= alphaThreshold)
  1293. mask |= 1;
  1294. if (++count == 8)
  1295. {
  1296. out.writeByte ((char) mask);
  1297. count = 0;
  1298. mask = 0;
  1299. }
  1300. }
  1301. if (mask != 0)
  1302. out.writeByte ((char) mask);
  1303. for (int i = maskStride - w / 8; --i >= 0;)
  1304. out.writeByte (0);
  1305. }
  1306. }
  1307. static void writeIconFile (const Array<Image>& images, MemoryOutputStream& out)
  1308. {
  1309. out.writeShort (0); // reserved
  1310. out.writeShort (1); // .ico tag
  1311. out.writeShort ((short) images.size());
  1312. MemoryOutputStream dataBlock;
  1313. int imageDirEntrySize = 16;
  1314. int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  1315. for (int i = 0; i < images.size(); ++i)
  1316. {
  1317. auto oldDataSize = dataBlock.getDataSize();
  1318. auto& image = images.getReference (i);
  1319. auto w = image.getWidth();
  1320. auto h = image.getHeight();
  1321. if (w >= 256 || h >= 256)
  1322. {
  1323. PNGImageFormat pngFormat;
  1324. pngFormat.writeImageToStream (image, dataBlock);
  1325. }
  1326. else
  1327. {
  1328. writeBMPImage (image, w, h, dataBlock);
  1329. }
  1330. out.writeByte ((char) w);
  1331. out.writeByte ((char) h);
  1332. out.writeByte (0);
  1333. out.writeByte (0);
  1334. out.writeShort (1); // colour planes
  1335. out.writeShort (32); // bits per pixel
  1336. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  1337. out.writeInt (dataBlockStart + (int) oldDataSize);
  1338. }
  1339. jassert (out.getPosition() == dataBlockStart);
  1340. out << dataBlock;
  1341. }
  1342. bool hasResourceFile() const
  1343. {
  1344. return ! projectType.isStaticLibrary();
  1345. }
  1346. void createResourcesAndIcon() const
  1347. {
  1348. if (hasResourceFile())
  1349. {
  1350. Array<Image> images;
  1351. int sizes[] = { 16, 32, 48, 256 };
  1352. for (int i = 0; i < numElementsInArray (sizes); ++i)
  1353. {
  1354. auto im = getBestIconForSize (sizes[i], true);
  1355. if (im.isValid())
  1356. images.add (im);
  1357. }
  1358. if (images.size() > 0)
  1359. {
  1360. iconFile = getTargetFolder().getChildFile ("icon.ico");
  1361. MemoryOutputStream mo;
  1362. writeIconFile (images, mo);
  1363. overwriteFileIfDifferentOrThrow (iconFile, mo);
  1364. }
  1365. createRCFile();
  1366. }
  1367. }
  1368. void createRCFile() const
  1369. {
  1370. rcFile = getTargetFolder().getChildFile ("resources.rc");
  1371. auto version = project.getVersionString();
  1372. MemoryOutputStream mo;
  1373. mo << "#ifdef JUCE_USER_DEFINED_RC_FILE" << newLine
  1374. << " #include JUCE_USER_DEFINED_RC_FILE" << newLine
  1375. << "#else" << newLine
  1376. << newLine
  1377. << "#undef WIN32_LEAN_AND_MEAN" << newLine
  1378. << "#define WIN32_LEAN_AND_MEAN" << newLine
  1379. << "#include <windows.h>" << newLine
  1380. << newLine
  1381. << "VS_VERSION_INFO VERSIONINFO" << newLine
  1382. << "FILEVERSION " << getCommaSeparatedVersionNumber (version) << newLine
  1383. << "BEGIN" << newLine
  1384. << " BLOCK \"StringFileInfo\"" << newLine
  1385. << " BEGIN" << newLine
  1386. << " BLOCK \"040904E4\"" << newLine
  1387. << " BEGIN" << newLine;
  1388. writeRCValue (mo, "CompanyName", project.getCompanyNameString());
  1389. writeRCValue (mo, "LegalCopyright", project.getCompanyCopyrightString());
  1390. writeRCValue (mo, "FileDescription", project.getProjectNameString());
  1391. writeRCValue (mo, "FileVersion", version);
  1392. writeRCValue (mo, "ProductName", project.getProjectNameString());
  1393. writeRCValue (mo, "ProductVersion", version);
  1394. mo << " END" << newLine
  1395. << " END" << newLine
  1396. << newLine
  1397. << " BLOCK \"VarFileInfo\"" << newLine
  1398. << " BEGIN" << newLine
  1399. << " VALUE \"Translation\", 0x409, 1252" << newLine
  1400. << " END" << newLine
  1401. << "END" << newLine
  1402. << newLine
  1403. << "#endif" << newLine;
  1404. if (iconFile != File())
  1405. mo << newLine
  1406. << "IDI_ICON1 ICON DISCARDABLE " << iconFile.getFileName().quoted()
  1407. << newLine
  1408. << "IDI_ICON2 ICON DISCARDABLE " << iconFile.getFileName().quoted();
  1409. overwriteFileIfDifferentOrThrow (rcFile, mo);
  1410. }
  1411. static void writeRCValue (MemoryOutputStream& mo, const String& name, const String& value)
  1412. {
  1413. if (value.isNotEmpty())
  1414. mo << " VALUE \"" << name << "\", \""
  1415. << CppTokeniserFunctions::addEscapeChars (value) << "\\0\"" << newLine;
  1416. }
  1417. static String getCommaSeparatedVersionNumber (const String& version)
  1418. {
  1419. auto versionParts = StringArray::fromTokens (version, ",.", "");
  1420. versionParts.trim();
  1421. versionParts.removeEmptyStrings();
  1422. while (versionParts.size() < 4)
  1423. versionParts.add ("0");
  1424. return versionParts.joinIntoString (",");
  1425. }
  1426. static String prependDot (const String& filename)
  1427. {
  1428. return FileHelpers::isAbsolutePath (filename) ? filename
  1429. : (".\\" + filename);
  1430. }
  1431. static bool shouldUseStdCall (const RelativePath& path)
  1432. {
  1433. return path.getFileNameWithoutExtension().startsWithIgnoreCase ("juce_audio_plugin_client_RTAS_");
  1434. }
  1435. StringArray getModuleLibs() const
  1436. {
  1437. StringArray result;
  1438. for (auto& lib : windowsLibs)
  1439. result.add (lib + ".lib");
  1440. return result;
  1441. }
  1442. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase)
  1443. };
  1444. //==============================================================================
  1445. class MSVCProjectExporterVC2013 : public MSVCProjectExporterBase
  1446. {
  1447. public:
  1448. MSVCProjectExporterVC2013 (Project& p, const ValueTree& t)
  1449. : MSVCProjectExporterBase (p, t, getTargetFolderForExporter (getValueTreeTypeName()))
  1450. {
  1451. name = getName();
  1452. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1453. platformToolsetValue.setDefault (getDefaultToolset());
  1454. }
  1455. static const char* getName() { return "Visual Studio 2013"; }
  1456. static const char* getValueTreeTypeName() { return "VS2013"; }
  1457. int getVisualStudioVersion() const override { return 12; }
  1458. String getSolutionComment() const override { return "# Visual Studio 2013"; }
  1459. String getToolsVersion() const override { return "12.0"; }
  1460. String getDefaultToolset() const override { return "v120"; }
  1461. String getDefaultWindowsTargetPlatformVersion() const override { return "8.1"; }
  1462. static MSVCProjectExporterVC2013* createForSettings (Project& project, const ValueTree& settings)
  1463. {
  1464. if (settings.hasType (getValueTreeTypeName()))
  1465. return new MSVCProjectExporterVC2013 (project, settings);
  1466. return nullptr;
  1467. }
  1468. void createExporterProperties (PropertyListBuilder& props) override
  1469. {
  1470. MSVCProjectExporterBase::createExporterProperties (props);
  1471. static const char* toolsetNames[] = { "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1472. const var toolsets[] = { "v120", "v120_xp", "Windows7.1SDK", "CTP_Nov2013" };
  1473. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1474. addIPPLibraryProperty (props);
  1475. addWindowsTargetPlatformProperties (props);
  1476. }
  1477. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2013)
  1478. };
  1479. //==============================================================================
  1480. class MSVCProjectExporterVC2015 : public MSVCProjectExporterBase
  1481. {
  1482. public:
  1483. MSVCProjectExporterVC2015 (Project& p, const ValueTree& t)
  1484. : MSVCProjectExporterBase (p, t, getTargetFolderForExporter (getValueTreeTypeName()))
  1485. {
  1486. name = getName();
  1487. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1488. platformToolsetValue.setDefault (getDefaultToolset());
  1489. }
  1490. static const char* getName() { return "Visual Studio 2015"; }
  1491. static const char* getValueTreeTypeName() { return "VS2015"; }
  1492. int getVisualStudioVersion() const override { return 14; }
  1493. String getSolutionComment() const override { return "# Visual Studio 2015"; }
  1494. String getToolsVersion() const override { return "14.0"; }
  1495. String getDefaultToolset() const override { return "v140"; }
  1496. String getDefaultWindowsTargetPlatformVersion() const override { return "8.1"; }
  1497. static MSVCProjectExporterVC2015* createForSettings (Project& project, const ValueTree& settings)
  1498. {
  1499. if (settings.hasType (getValueTreeTypeName()))
  1500. return new MSVCProjectExporterVC2015 (project, settings);
  1501. return nullptr;
  1502. }
  1503. void createExporterProperties (PropertyListBuilder& props) override
  1504. {
  1505. MSVCProjectExporterBase::createExporterProperties (props);
  1506. static const char* toolsetNames[] = { "v140", "v140_xp", "CTP_Nov2013" };
  1507. const var toolsets[] = { "v140", "v140_xp", "CTP_Nov2013" };
  1508. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1509. addIPPLibraryProperty (props);
  1510. addWindowsTargetPlatformProperties (props);
  1511. }
  1512. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2015)
  1513. };
  1514. //==============================================================================
  1515. class MSVCProjectExporterVC2017 : public MSVCProjectExporterBase
  1516. {
  1517. public:
  1518. MSVCProjectExporterVC2017 (Project& p, const ValueTree& t)
  1519. : MSVCProjectExporterBase (p, t, getTargetFolderForExporter (getValueTreeTypeName()))
  1520. {
  1521. name = getName();
  1522. targetPlatformVersion.setDefault (getDefaultWindowsTargetPlatformVersion());
  1523. platformToolsetValue.setDefault (getDefaultToolset());
  1524. }
  1525. static const char* getName() { return "Visual Studio 2017"; }
  1526. static const char* getValueTreeTypeName() { return "VS2017"; }
  1527. int getVisualStudioVersion() const override { return 15; }
  1528. String getSolutionComment() const override { return "# Visual Studio 2017"; }
  1529. String getToolsVersion() const override { return "15.0"; }
  1530. String getDefaultToolset() const override { return "v141"; }
  1531. String getDefaultWindowsTargetPlatformVersion() const override { return "10.0.16299.0"; }
  1532. static MSVCProjectExporterVC2017* createForSettings (Project& project, const ValueTree& settings)
  1533. {
  1534. if (settings.hasType (getValueTreeTypeName()))
  1535. return new MSVCProjectExporterVC2017 (project, settings);
  1536. return nullptr;
  1537. }
  1538. void createExporterProperties (PropertyListBuilder& props) override
  1539. {
  1540. MSVCProjectExporterBase::createExporterProperties (props);
  1541. static const char* toolsetNames[] = { "v140", "v140_xp", "v141", "v141_xp" };
  1542. const var toolsets[] = { "v140", "v140_xp", "v141", "v141_xp" };
  1543. addToolsetProperty (props, toolsetNames, toolsets, numElementsInArray (toolsets));
  1544. addIPPLibraryProperty (props);
  1545. addWindowsTargetPlatformProperties (props);
  1546. }
  1547. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2017)
  1548. };