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.

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