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.

1941 lines
89KB

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