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.

2198 lines
97KB

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