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.

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