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.

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