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.

1985 lines
94KB

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