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.

1934 lines
90KB

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