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.

1515 lines
66KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__
  19. #define __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__
  20. #include "jucer_ProjectExporter.h"
  21. #include "jucer_ProjectSaver.h"
  22. //==============================================================================
  23. class MSVCProjectExporterBase : public ProjectExporter
  24. {
  25. public:
  26. //==============================================================================
  27. MSVCProjectExporterBase (Project& project_, const ValueTree& settings_, const char* const folderName)
  28. : ProjectExporter (project_, settings_), hasIcon (false)
  29. {
  30. if (getTargetLocation().toString().isEmpty())
  31. getTargetLocation() = getDefaultBuildsRootFolder() + folderName;
  32. if ((int) getLibraryType().getValue() <= 0)
  33. getLibraryType() = 1;
  34. projectGUID = createGUID (project.getProjectUID());
  35. msvcPreBuildCommand = getPrebuildCommand().toString();
  36. }
  37. //==============================================================================
  38. bool isPossibleForCurrentProject() { return true; }
  39. bool usesMMFiles() const { return false; }
  40. bool isVisualStudio() const { return true; }
  41. bool canCopeWithDuplicateFiles() { return false; }
  42. void createPropertyEditors (PropertyListBuilder& props)
  43. {
  44. ProjectExporter::createPropertyEditors (props);
  45. if (projectType.isLibrary())
  46. {
  47. const char* const libTypes[] = { "Static Library (.lib)", "Dynamic Library (.dll)", 0 };
  48. const int libTypeValues[] = { 1, 2, 0 };
  49. props.add (new ChoicePropertyComponent (getLibraryType(), "Library Type", StringArray (libTypes), Array<var> (libTypeValues)));
  50. props.add (new TextPropertyComponent (getSetting (Ids::libraryName_Debug), "Library Name (Debug)", 128, false),
  51. "If set, this name will override the binary name specified in the configuration settings, for a debug build. You must include the .lib or .dll suffix on this filename.");
  52. props.add (new TextPropertyComponent (getSetting (Ids::libraryName_Release), "Library Name (Release)", 128, false),
  53. "If set, this name will override the binary name specified in the configuration settings, for a release build. You must include the .lib or .dll suffix on this filename.");
  54. }
  55. props.add (new TextPropertyComponent (getPrebuildCommand(), "Pre-build Command", 2048, false));
  56. }
  57. protected:
  58. String projectGUID;
  59. File rcFile, iconFile;
  60. bool hasIcon;
  61. File getProjectFile (const String& extension) const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (extension); }
  62. Value getLibraryType() const { return getSetting (Ids::libraryType); }
  63. Value getPrebuildCommand() const { return getSetting (Ids::prebuildCommand); }
  64. bool isLibraryDLL() const { return msvcIsDLL || (projectType.isLibrary() && getLibraryType() == 2); }
  65. //==============================================================================
  66. class MSVCBuildConfiguration : public BuildConfiguration
  67. {
  68. public:
  69. MSVCBuildConfiguration (Project& project, const ValueTree& settings)
  70. : BuildConfiguration (project, settings)
  71. {
  72. if (getWarningLevel() == 0)
  73. getWarningLevelValue() = 4;
  74. }
  75. Value getWarningLevelValue() const { return getValue (Ids::winWarningLevel); }
  76. int getWarningLevel() const { return getWarningLevelValue().getValue(); }
  77. void createPropertyEditors (PropertyListBuilder& props)
  78. {
  79. createBasicPropertyEditors (props);
  80. const char* const warningLevelNames[] = { "Low", "Medium", "High", nullptr };
  81. const int warningLevels[] = { 2, 3, 4, 0 };
  82. props.add (new ChoicePropertyComponent (getWarningLevelValue(), "Warning Level",
  83. StringArray (warningLevelNames), Array<var> (warningLevels)));
  84. }
  85. };
  86. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  87. {
  88. return new MSVCBuildConfiguration (project, settings);
  89. }
  90. static int getWarningLevel (const BuildConfiguration& config)
  91. {
  92. return dynamic_cast <const MSVCBuildConfiguration&> (config).getWarningLevel();
  93. }
  94. //==============================================================================
  95. String getIntermediatesPath (const BuildConfiguration& config) const
  96. {
  97. return ".\\" + File::createLegalFileName (config.getName().toString().trim());
  98. }
  99. String getConfigTargetPath (const BuildConfiguration& config) const
  100. {
  101. const String binaryPath (config.getTargetBinaryRelativePath().toString().trim());
  102. if (binaryPath.isEmpty())
  103. return getIntermediatesPath (config);
  104. RelativePath binaryRelPath (binaryPath, RelativePath::projectFolder);
  105. if (binaryRelPath.isAbsolute())
  106. return binaryRelPath.toWindowsStyle();
  107. return ".\\" + binaryRelPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder)
  108. .toWindowsStyle();
  109. }
  110. String getPreprocessorDefs (const BuildConfiguration& config, const String& joinString) const
  111. {
  112. StringPairArray defines (msvcExtraPreprocessorDefs);
  113. defines.set ("WIN32", "");
  114. defines.set ("_WINDOWS", "");
  115. if (config.isDebug().getValue())
  116. {
  117. defines.set ("DEBUG", "");
  118. defines.set ("_DEBUG", "");
  119. }
  120. else
  121. {
  122. defines.set ("NDEBUG", "");
  123. }
  124. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  125. StringArray result;
  126. for (int i = 0; i < defines.size(); ++i)
  127. {
  128. String def (defines.getAllKeys()[i]);
  129. const String value (defines.getAllValues()[i]);
  130. if (value.isNotEmpty())
  131. def << "=" << value;
  132. result.add (def);
  133. }
  134. return result.joinIntoString (joinString);
  135. }
  136. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  137. {
  138. StringArray searchPaths (extraSearchPaths);
  139. searchPaths.addArray (config.getHeaderSearchPaths());
  140. searchPaths.removeDuplicates (false);
  141. return searchPaths;
  142. }
  143. String getBinaryFileForConfig (const BuildConfiguration& config) const
  144. {
  145. const String targetBinary (getSetting (config.isDebug().getValue() ? Ids::libraryName_Debug : Ids::libraryName_Release).toString().trim());
  146. if (targetBinary.isNotEmpty())
  147. return targetBinary;
  148. return config.getTargetBinaryName().toString() + msvcTargetSuffix;
  149. }
  150. virtual String createConfigName (const BuildConfiguration& config) const
  151. {
  152. return config.getName().toString() + "|Win32";
  153. }
  154. //==============================================================================
  155. void writeSolutionFile (OutputStream& out, const String& versionString, String commentString, const File& vcProject)
  156. {
  157. if (commentString.isNotEmpty())
  158. commentString += newLine;
  159. out << "Microsoft Visual Studio Solution File, Format Version " << versionString << newLine
  160. << commentString
  161. << "Project(\"" << createGUID (projectName + "sln_guid") << "\") = \"" << projectName << "\", \""
  162. << vcProject.getFileName() << "\", \"" << projectGUID << '"' << newLine
  163. << "EndProject" << newLine
  164. << "Global" << newLine
  165. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  166. int i;
  167. for (i = 0; i < getNumConfigurations(); ++i)
  168. {
  169. const String configName (createConfigName (*getConfiguration(i)));
  170. out << "\t\t" << configName << " = " << configName << newLine;
  171. }
  172. out << "\tEndGlobalSection" << newLine
  173. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  174. for (i = 0; i < getNumConfigurations(); ++i)
  175. {
  176. const String configName (createConfigName (*getConfiguration(i)));
  177. out << "\t\t" << projectGUID << "." << configName << ".ActiveCfg = " << configName << newLine;
  178. out << "\t\t" << projectGUID << "." << configName << ".Build.0 = " << configName << newLine;
  179. }
  180. out << "\tEndGlobalSection" << newLine
  181. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  182. << "\t\tHideSolutionNode = FALSE" << newLine
  183. << "\tEndGlobalSection" << newLine
  184. << "EndGlobal" << newLine;
  185. }
  186. //==============================================================================
  187. static bool writeRCFile (const File& file, const File& iconFile)
  188. {
  189. return file.deleteFile()
  190. && file.appendText ("IDI_ICON1 ICON DISCARDABLE "
  191. + iconFile.getFileName().quoted(), false, false);
  192. }
  193. static void writeIconFile (const Array<Image>& images, OutputStream& out)
  194. {
  195. out.writeShort (0); // reserved
  196. out.writeShort (1); // .ico tag
  197. out.writeShort ((short) images.size());
  198. MemoryOutputStream dataBlock;
  199. const int imageDirEntrySize = 16;
  200. const int dataBlockStart = 6 + images.size() * imageDirEntrySize;
  201. for (int i = 0; i < images.size(); ++i)
  202. {
  203. const Image& image = images.getReference (i);
  204. const int w = image.getWidth();
  205. const int h = image.getHeight();
  206. const int maskStride = (w / 8 + 3) & ~3;
  207. const size_t oldDataSize = dataBlock.getDataSize();
  208. dataBlock.writeInt (40); // bitmapinfoheader size
  209. dataBlock.writeInt (w);
  210. dataBlock.writeInt (h * 2);
  211. dataBlock.writeShort (1); // planes
  212. dataBlock.writeShort (32); // bits
  213. dataBlock.writeInt (0); // compression
  214. dataBlock.writeInt ((h * w * 4) + (h * maskStride)); // size image
  215. dataBlock.writeInt (0); // x pixels per meter
  216. dataBlock.writeInt (0); // y pixels per meter
  217. dataBlock.writeInt (0); // clr used
  218. dataBlock.writeInt (0); // clr important
  219. const Image::BitmapData bitmap (image, Image::BitmapData::readOnly);
  220. const int alphaThreshold = 5;
  221. int y;
  222. for (y = h; --y >= 0;)
  223. {
  224. for (int x = 0; x < w; ++x)
  225. {
  226. const Colour pixel (bitmap.getPixelColour (x, y));
  227. if (pixel.getAlpha() <= alphaThreshold)
  228. {
  229. dataBlock.writeInt (0);
  230. }
  231. else
  232. {
  233. dataBlock.writeByte ((char) pixel.getBlue());
  234. dataBlock.writeByte ((char) pixel.getGreen());
  235. dataBlock.writeByte ((char) pixel.getRed());
  236. dataBlock.writeByte ((char) pixel.getAlpha());
  237. }
  238. }
  239. }
  240. for (y = h; --y >= 0;)
  241. {
  242. int mask = 0, count = 0;
  243. for (int x = 0; x < w; ++x)
  244. {
  245. const Colour pixel (bitmap.getPixelColour (x, y));
  246. mask <<= 1;
  247. if (pixel.getAlpha() <= alphaThreshold)
  248. mask |= 1;
  249. if (++count == 8)
  250. {
  251. dataBlock.writeByte ((char) mask);
  252. count = 0;
  253. mask = 0;
  254. }
  255. }
  256. if (mask != 0)
  257. dataBlock.writeByte ((char) mask);
  258. for (int i = maskStride - w / 8; --i >= 0;)
  259. dataBlock.writeByte (0);
  260. }
  261. out.writeByte ((char) w);
  262. out.writeByte ((char) h);
  263. out.writeByte (0);
  264. out.writeByte (0);
  265. out.writeShort (1); // colour planes
  266. out.writeShort (32); // bits per pixel
  267. out.writeInt ((int) (dataBlock.getDataSize() - oldDataSize));
  268. out.writeInt (dataBlockStart + oldDataSize);
  269. }
  270. jassert (out.getPosition() == dataBlockStart);
  271. out << dataBlock;
  272. }
  273. bool createIconFile()
  274. {
  275. Array<Image> images;
  276. Image im (getBestIconForSize (16, true));
  277. if (im.isValid())
  278. images.add (im);
  279. im = getBestIconForSize (32, true);
  280. if (im.isValid())
  281. images.add (im);
  282. im = getBestIconForSize (48, true);
  283. if (im.isValid())
  284. images.add (im);
  285. im = getBestIconForSize (128, true);
  286. if (im.isValid())
  287. images.add (im);
  288. if (images.size() == 0)
  289. return true;
  290. MemoryOutputStream mo;
  291. writeIconFile (images, mo);
  292. iconFile = getTargetFolder().getChildFile ("icon.ico");
  293. rcFile = getTargetFolder().getChildFile ("resources.rc");
  294. hasIcon = FileHelpers::overwriteFileWithNewDataIfDifferent (iconFile, mo)
  295. && writeRCFile (rcFile, iconFile);
  296. return hasIcon;
  297. }
  298. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterBase);
  299. };
  300. //==============================================================================
  301. class MSVCProjectExporterVC2008 : public MSVCProjectExporterBase
  302. {
  303. public:
  304. //==============================================================================
  305. MSVCProjectExporterVC2008 (Project& project_, const ValueTree& settings_, const char* folderName = "VisualStudio2008")
  306. : MSVCProjectExporterBase (project_, settings_, folderName)
  307. {
  308. name = getName();
  309. }
  310. static const char* getName() { return "Visual Studio 2008"; }
  311. static const char* getValueTreeTypeName() { return "VS2008"; }
  312. void launchProject() { getSLNFile().startAsProcess(); }
  313. int getLaunchPreferenceOrderForCurrentOS()
  314. {
  315. #if JUCE_WINDOWS
  316. return 4;
  317. #else
  318. return 0;
  319. #endif
  320. }
  321. static MSVCProjectExporterVC2008* createForSettings (Project& project, const ValueTree& settings)
  322. {
  323. if (settings.hasType (getValueTreeTypeName()))
  324. return new MSVCProjectExporterVC2008 (project, settings);
  325. return nullptr;
  326. }
  327. //==============================================================================
  328. void create()
  329. {
  330. createIconFile();
  331. if (hasIcon)
  332. {
  333. for (int i = 0; i < groups.size(); ++i)
  334. {
  335. Project::Item& group = groups.getReference(i);
  336. if (group.getID() == ProjectSaver::getGeneratedGroupID())
  337. {
  338. group.addFile (iconFile, -1, true);
  339. group.addFile (rcFile, -1, true);
  340. group.findItemForFile (iconFile).getShouldAddToResourceValue() = false;
  341. group.findItemForFile (rcFile).getShouldAddToResourceValue() = false;
  342. break;
  343. }
  344. }
  345. }
  346. {
  347. XmlElement projectXml ("VisualStudioProject");
  348. fillInProjectXml (projectXml);
  349. writeXmlOrThrow (projectXml, getVCProjFile(), "UTF-8", 10);
  350. }
  351. {
  352. MemoryOutputStream mo;
  353. writeSolutionFile (mo, getSolutionVersionString(), String::empty, getVCProjFile());
  354. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  355. }
  356. }
  357. protected:
  358. virtual String getProjectVersionString() const { return "9.00"; }
  359. virtual String getSolutionVersionString() const { return "10.00" + newLine + "# Visual C++ Express 2008"; }
  360. File getVCProjFile() const { return getProjectFile (".vcproj"); }
  361. File getSLNFile() const { return getProjectFile (".sln"); }
  362. //==============================================================================
  363. void fillInProjectXml (XmlElement& projectXml)
  364. {
  365. projectXml.setAttribute ("ProjectType", "Visual C++");
  366. projectXml.setAttribute ("Version", getProjectVersionString());
  367. projectXml.setAttribute ("Name", projectName);
  368. projectXml.setAttribute ("ProjectGUID", projectGUID);
  369. projectXml.setAttribute ("TargetFrameworkVersion", "131072");
  370. {
  371. XmlElement* platforms = projectXml.createNewChildElement ("Platforms");
  372. XmlElement* platform = platforms->createNewChildElement ("Platform");
  373. platform->setAttribute ("Name", "Win32");
  374. }
  375. projectXml.createNewChildElement ("ToolFiles");
  376. createConfigs (*projectXml.createNewChildElement ("Configurations"));
  377. projectXml.createNewChildElement ("References");
  378. createFiles (*projectXml.createNewChildElement ("Files"));
  379. projectXml.createNewChildElement ("Globals");
  380. }
  381. //==============================================================================
  382. void addFile (const RelativePath& file, XmlElement& parent, const bool excludeFromBuild, const bool useStdcall)
  383. {
  384. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  385. XmlElement* fileXml = parent.createNewChildElement ("File");
  386. fileXml->setAttribute ("RelativePath", file.toWindowsStyle());
  387. if (excludeFromBuild || useStdcall)
  388. {
  389. for (int i = 0; i < getNumConfigurations(); ++i)
  390. {
  391. XmlElement* fileConfig = fileXml->createNewChildElement ("FileConfiguration");
  392. fileConfig->setAttribute ("Name", createConfigName (*getConfiguration (i)));
  393. if (excludeFromBuild)
  394. fileConfig->setAttribute ("ExcludedFromBuild", "true");
  395. XmlElement* tool = createToolElement (*fileConfig, "VCCLCompilerTool");
  396. if (useStdcall)
  397. tool->setAttribute ("CallingConvention", "2");
  398. }
  399. }
  400. }
  401. XmlElement* createGroup (const String& groupName, XmlElement& parent)
  402. {
  403. XmlElement* filter = parent.createNewChildElement ("Filter");
  404. filter->setAttribute ("Name", groupName);
  405. return filter;
  406. }
  407. void addFiles (const Project::Item& projectItem, XmlElement& parent)
  408. {
  409. if (projectItem.isGroup())
  410. {
  411. XmlElement* filter = createGroup (projectItem.getName().toString(), parent);
  412. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  413. addFiles (projectItem.getChild(i), *filter);
  414. }
  415. else if (projectItem.shouldBeAddedToTargetProject())
  416. {
  417. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  418. addFile (path, parent,
  419. projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()),
  420. shouldFileBeCompiledByDefault (path) && (bool) projectItem.getShouldUseStdCallValue().getValue());
  421. }
  422. }
  423. void createFiles (XmlElement& files)
  424. {
  425. for (int i = 0; i < groups.size(); ++i)
  426. if (groups.getReference(i).getNumChildren() > 0)
  427. addFiles (groups.getReference(i), files);
  428. }
  429. //==============================================================================
  430. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  431. {
  432. XmlElement* const e = parent.createNewChildElement ("Tool");
  433. e->setAttribute ("Name", toolName);
  434. return e;
  435. }
  436. void createConfig (XmlElement& xml, const BuildConfiguration& config) const
  437. {
  438. String binariesPath (getConfigTargetPath (config));
  439. String intermediatesPath (getIntermediatesPath (config));
  440. const bool isDebug = (bool) config.isDebug().getValue();
  441. const String binaryName (File::createLegalFileName (config.getTargetBinaryName().toString()));
  442. xml.setAttribute ("Name", createConfigName (config));
  443. xml.setAttribute ("OutputDirectory", FileHelpers::windowsStylePath (binariesPath));
  444. xml.setAttribute ("IntermediateDirectory", FileHelpers::windowsStylePath (intermediatesPath));
  445. xml.setAttribute ("ConfigurationType", isLibraryDLL() ? "2" : (projectType.isLibrary() ? "4" : "1"));
  446. xml.setAttribute ("UseOfMFC", "0");
  447. xml.setAttribute ("ATLMinimizesCRunTimeLibraryUsage", "false");
  448. xml.setAttribute ("CharacterSet", "2");
  449. if (! isDebug)
  450. xml.setAttribute ("WholeProgramOptimization", "1");
  451. XmlElement* preBuildEvent = createToolElement (xml, "VCPreBuildEventTool");
  452. if (msvcPreBuildCommand.isNotEmpty())
  453. {
  454. preBuildEvent->setAttribute ("Description", "Pre-build");
  455. preBuildEvent->setAttribute ("CommandLine", msvcPreBuildCommand);
  456. }
  457. XmlElement* customBuild = createToolElement (xml, "VCCustomBuildTool");
  458. if (msvcPostBuildCommand.isNotEmpty())
  459. customBuild->setAttribute ("CommandLine", msvcPostBuildCommand);
  460. if (msvcPostBuildOutputs.isNotEmpty())
  461. customBuild->setAttribute ("Outputs", msvcPostBuildOutputs);
  462. createToolElement (xml, "VCXMLDataGeneratorTool");
  463. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  464. if (! projectType.isLibrary())
  465. {
  466. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  467. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  468. midl->setAttribute ("MkTypLibCompatible", "true");
  469. midl->setAttribute ("SuppressStartupBanner", "true");
  470. midl->setAttribute ("TargetEnvironment", "1");
  471. midl->setAttribute ("TypeLibraryName", FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".tlb"));
  472. midl->setAttribute ("HeaderFileName", "");
  473. }
  474. {
  475. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  476. const int optimiseLevel = (int) config.getOptimisationLevel().getValue();
  477. compiler->setAttribute ("Optimization", optimiseLevel <= 1 ? "0" : (optimiseLevel == 2 ? "1" : "2"));
  478. if (isDebug)
  479. {
  480. compiler->setAttribute ("BufferSecurityCheck", "");
  481. compiler->setAttribute ("DebugInformationFormat", projectType.isLibrary() ? "3" : "4");
  482. }
  483. else
  484. {
  485. compiler->setAttribute ("InlineFunctionExpansion", "1");
  486. compiler->setAttribute ("StringPooling", "true");
  487. }
  488. compiler->setAttribute ("AdditionalIncludeDirectories", replacePreprocessorTokens (config, getHeaderSearchPaths (config).joinIntoString (";")));
  489. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  490. compiler->setAttribute ("RuntimeLibrary", msvcNeedsDLLRuntimeLib ? (isDebug ? 3 : 2) // MT DLL
  491. : (isDebug ? 1 : 0)); // MT static
  492. compiler->setAttribute ("RuntimeTypeInfo", "true");
  493. compiler->setAttribute ("UsePrecompiledHeader", "0");
  494. compiler->setAttribute ("PrecompiledHeaderFile", FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".pch"));
  495. compiler->setAttribute ("AssemblerListingLocation", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  496. compiler->setAttribute ("ObjectFile", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  497. compiler->setAttribute ("ProgramDataBaseFileName", FileHelpers::windowsStylePath (intermediatesPath + "/"));
  498. compiler->setAttribute ("WarningLevel", String (getWarningLevel (config)));
  499. compiler->setAttribute ("SuppressStartupBanner", "true");
  500. const String extraFlags (replacePreprocessorTokens (config, getExtraCompilerFlags().toString()).trim());
  501. if (extraFlags.isNotEmpty())
  502. compiler->setAttribute ("AdditionalOptions", extraFlags);
  503. }
  504. createToolElement (xml, "VCManagedResourceCompilerTool");
  505. {
  506. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  507. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  508. }
  509. createToolElement (xml, "VCPreLinkEventTool");
  510. const String outputFileName (getBinaryFileForConfig (config));
  511. if (! projectType.isLibrary())
  512. {
  513. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  514. linker->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  515. linker->setAttribute ("SuppressStartupBanner", "true");
  516. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  517. linker->setAttribute ("GenerateDebugInformation", isDebug ? "true" : "false");
  518. linker->setAttribute ("ProgramDatabaseFile", FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".pdb"));
  519. linker->setAttribute ("SubSystem", msvcIsWindowsSubsystem ? "2" : "1");
  520. if (! isDebug)
  521. {
  522. linker->setAttribute ("GenerateManifest", "false");
  523. linker->setAttribute ("OptimizeReferences", "2");
  524. linker->setAttribute ("EnableCOMDATFolding", "2");
  525. }
  526. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  527. if (msvcDelayLoadedDLLs.isNotEmpty())
  528. linker->setAttribute ("DelayLoadDLLs", msvcDelayLoadedDLLs);
  529. if (msvcModuleDefinitionFile.isNotEmpty())
  530. linker->setAttribute ("ModuleDefinitionFile", msvcModuleDefinitionFile);
  531. String extraLinkerOptions (getExtraLinkerFlags().toString());
  532. if (msvcExtraLinkerOptions.isNotEmpty())
  533. extraLinkerOptions << ' ' << msvcExtraLinkerOptions;
  534. if (extraLinkerOptions.isNotEmpty())
  535. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  536. }
  537. else
  538. {
  539. if (isLibraryDLL())
  540. {
  541. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  542. String extraLinkerOptions (getExtraLinkerFlags().toString());
  543. extraLinkerOptions << " /IMPLIB:" << FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName.upToLastOccurrenceOf (".", false, false) + ".lib");
  544. linker->setAttribute ("AdditionalOptions", replacePreprocessorTokens (config, extraLinkerOptions).trim());
  545. linker->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  546. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  547. }
  548. else
  549. {
  550. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  551. librarian->setAttribute ("OutputFile", FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  552. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  553. }
  554. }
  555. createToolElement (xml, "VCALinkTool");
  556. createToolElement (xml, "VCManifestTool");
  557. createToolElement (xml, "VCXDCMakeTool");
  558. {
  559. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  560. bscMake->setAttribute ("SuppressStartupBanner", "true");
  561. bscMake->setAttribute ("OutputFile", FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".bsc"));
  562. }
  563. createToolElement (xml, "VCFxCopTool");
  564. if (! projectType.isLibrary())
  565. createToolElement (xml, "VCAppVerifierTool");
  566. createToolElement (xml, "VCPostBuildEventTool");
  567. }
  568. void createConfigs (XmlElement& xml)
  569. {
  570. for (int i = 0; i < getNumConfigurations(); ++i)
  571. createConfig (*xml.createNewChildElement ("Configuration"), *getConfiguration(i));
  572. }
  573. //==============================================================================
  574. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2008);
  575. };
  576. //==============================================================================
  577. class MSVCProjectExporterVC2005 : public MSVCProjectExporterVC2008
  578. {
  579. public:
  580. MSVCProjectExporterVC2005 (Project& project_, const ValueTree& settings_)
  581. : MSVCProjectExporterVC2008 (project_, settings_, "VisualStudio2005")
  582. {
  583. name = getName();
  584. }
  585. static const char* getName() { return "Visual Studio 2005"; }
  586. static const char* getValueTreeTypeName() { return "VS2005"; }
  587. int getLaunchPreferenceOrderForCurrentOS()
  588. {
  589. #if JUCE_WINDOWS
  590. return 2;
  591. #else
  592. return 0;
  593. #endif
  594. }
  595. static MSVCProjectExporterVC2005* createForSettings (Project& project, const ValueTree& settings)
  596. {
  597. if (settings.hasType (getValueTreeTypeName()))
  598. return new MSVCProjectExporterVC2005 (project, settings);
  599. return 0;
  600. }
  601. protected:
  602. String getProjectVersionString() const { return "8.00"; }
  603. String getSolutionVersionString() const { return "9.00" + newLine + "# Visual C++ Express 2005"; }
  604. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2005);
  605. };
  606. //==============================================================================
  607. class MSVCProjectExporterVC6 : public MSVCProjectExporterBase
  608. {
  609. public:
  610. //==============================================================================
  611. MSVCProjectExporterVC6 (Project& project_, const ValueTree& settings_)
  612. : MSVCProjectExporterBase (project_, settings_, "MSVC6")
  613. {
  614. name = getName();
  615. }
  616. static const char* getName() { return "Visual C++ 6.0"; }
  617. static const char* getValueTreeTypeName() { return "MSVC6"; }
  618. int getLaunchPreferenceOrderForCurrentOS()
  619. {
  620. #if JUCE_WINDOWS
  621. return 1;
  622. #else
  623. return 0;
  624. #endif
  625. }
  626. void launchProject() { getDSWFile().startAsProcess(); }
  627. static MSVCProjectExporterVC6* createForSettings (Project& project, const ValueTree& settings)
  628. {
  629. if (settings.hasType (getValueTreeTypeName()))
  630. return new MSVCProjectExporterVC6 (project, settings);
  631. return nullptr;
  632. }
  633. //==============================================================================
  634. void create()
  635. {
  636. {
  637. MemoryOutputStream mo;
  638. writeProject (mo);
  639. overwriteFileIfDifferentOrThrow (getDSPFile(), mo);
  640. }
  641. {
  642. MemoryOutputStream mo;
  643. writeDSWFile (mo);
  644. overwriteFileIfDifferentOrThrow (getDSWFile(), mo);
  645. }
  646. }
  647. private:
  648. File getDSPFile() const { return getProjectFile (".dsp"); }
  649. File getDSWFile() const { return getProjectFile (".dsw"); }
  650. //==============================================================================
  651. String createConfigName (const BuildConfiguration& config) const
  652. {
  653. return projectName + " - Win32 " + config.getName().toString();
  654. }
  655. void writeProject (OutputStream& out)
  656. {
  657. const String defaultConfigName (createConfigName (*getConfiguration(0)));
  658. String targetType, targetCode;
  659. if (isLibraryDLL()) { targetType = "\"Win32 (x86) Dynamic-Link Library\""; targetCode = "0x0102"; }
  660. else if (projectType.isLibrary()) { targetType = "\"Win32 (x86) Static Library\""; targetCode = "0x0104"; }
  661. else if (projectType.isCommandLineApp()) { targetType = "\"Win32 (x86) Console Application\""; targetCode = "0x0103"; }
  662. else { targetType = "\"Win32 (x86) Application\""; targetCode = "0x0101"; }
  663. out << "# Microsoft Developer Studio Project File - Name=\"" << projectName
  664. << "\" - Package Owner=<4>" << newLine
  665. << "# Microsoft Developer Studio Generated Build File, Format Version 6.00" << newLine
  666. << "# ** DO NOT EDIT **" << newLine
  667. << "# TARGTYPE " << targetType << " " << targetCode << newLine
  668. << "CFG=" << defaultConfigName << newLine
  669. << "!MESSAGE This is not a valid makefile. To build this project using NMAKE," << newLine
  670. << "!MESSAGE use the Export Makefile command and run" << newLine
  671. << "!MESSAGE " << newLine
  672. << "!MESSAGE NMAKE /f \"" << projectName << ".mak.\"" << newLine
  673. << "!MESSAGE " << newLine
  674. << "!MESSAGE You can specify a configuration when running NMAKE" << newLine
  675. << "!MESSAGE by defining the macro CFG on the command line. For example:" << newLine
  676. << "!MESSAGE " << newLine
  677. << "!MESSAGE NMAKE /f \"" << projectName << ".mak\" CFG=\"" << defaultConfigName << '"' << newLine
  678. << "!MESSAGE " << newLine
  679. << "!MESSAGE Possible choices for configuration are:" << newLine
  680. << "!MESSAGE " << newLine;
  681. int i;
  682. for (i = 0; i < getNumConfigurations(); ++i)
  683. out << "!MESSAGE \"" << createConfigName (*getConfiguration (i)) << "\" (based on " << targetType << ")" << newLine;
  684. out << "!MESSAGE " << newLine
  685. << "# Begin Project" << newLine
  686. << "# PROP AllowPerConfigDependencies 0" << newLine
  687. << "# PROP Scc_ProjName \"\"" << newLine
  688. << "# PROP Scc_LocalPath \"\"" << newLine
  689. << "CPP=cl.exe" << newLine
  690. << "MTL=midl.exe" << newLine
  691. << "RSC=rc.exe" << newLine;
  692. String targetList;
  693. for (i = 0; i < getNumConfigurations(); ++i)
  694. {
  695. const BuildConfiguration::Ptr config (getConfiguration(i));
  696. const String configName (createConfigName (*config));
  697. targetList << "# Name \"" << configName << '"' << newLine;
  698. const String binariesPath (getConfigTargetPath (*config));
  699. const String targetBinary (FileHelpers::windowsStylePath (binariesPath + "/" + getBinaryFileForConfig (*config)));
  700. const String optimisationFlag (((int) config->getOptimisationLevel().getValue() <= 1) ? "Od" : (config->getOptimisationLevel() == 2 ? "O2" : "O3"));
  701. const String defines (getPreprocessorDefs (*config, " /D "));
  702. const bool isDebug = (bool) config->isDebug().getValue();
  703. const String extraDebugFlags (isDebug ? "/Gm /ZI /GZ" : "");
  704. out << (i == 0 ? "!IF" : "!ELSEIF") << " \"$(CFG)\" == \"" << configName << '"' << newLine
  705. << "# PROP BASE Use_MFC 0" << newLine
  706. << "# PROP BASE Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  707. << "# PROP BASE Output_Dir \"" << binariesPath << '"' << newLine
  708. << "# PROP BASE Intermediate_Dir \"" << getIntermediatesPath (*config) << '"' << newLine
  709. << "# PROP BASE Target_Dir \"\"" << newLine
  710. << "# PROP Use_MFC 0" << newLine
  711. << "# PROP Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  712. << "# PROP Output_Dir \"" << binariesPath << '"' << newLine
  713. << "# PROP Intermediate_Dir \"" << getIntermediatesPath (*config) << '"' << newLine
  714. << "# PROP Ignore_Export_Lib 0" << newLine
  715. << "# PROP Target_Dir \"\"" << newLine
  716. << "# ADD BASE CPP /nologo /W3 /GX /" << optimisationFlag << " /D " << defines
  717. << " /YX /FD /c " << extraDebugFlags << " /Zm1024" << newLine
  718. << "# ADD CPP /nologo " << (isDebug ? "/MTd" : "/MT") << " /W3 /GR /GX /" << optimisationFlag
  719. << " /I " << replacePreprocessorTokens (*config, getHeaderSearchPaths (*config).joinIntoString (" /I "))
  720. << " /D " << defines << " /D \"_UNICODE\" /D \"UNICODE\" /FD /c /Zm1024 " << extraDebugFlags
  721. << " " << replacePreprocessorTokens (*config, getExtraCompilerFlags().toString()).trim() << newLine;
  722. if (! isDebug)
  723. out << "# SUBTRACT CPP /YX" << newLine;
  724. if (! projectType.isLibrary())
  725. out << "# ADD BASE MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine
  726. << "# ADD MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine;
  727. out << "# ADD BASE RSC /l 0x40c /d " << defines << newLine
  728. << "# ADD RSC /l 0x40c /d " << defines << newLine
  729. << "BSC32=bscmake.exe" << newLine
  730. << "# ADD BASE BSC32 /nologo" << newLine
  731. << "# ADD BSC32 /nologo" << newLine;
  732. if (projectType.isLibrary())
  733. {
  734. out << "LIB32=link.exe -lib" << newLine
  735. << "# ADD BASE LIB32 /nologo" << newLine
  736. << "# ADD LIB32 /nologo /out:\"" << targetBinary << '"' << newLine;
  737. }
  738. else
  739. {
  740. out << "LINK32=link.exe" << newLine
  741. << "# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386" << newLine
  742. << "# ADD LINK32 \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\LIB\\shell32.lib\" " // This is avoid debug information corruption when mixing Platform SDK
  743. << "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "
  744. << (isDebug ? " /debug" : "")
  745. << " /nologo /machine:I386 /out:\"" << targetBinary << "\" "
  746. << (isLibraryDLL() ? "/dll" : (msvcIsWindowsSubsystem ? "/subsystem:windows "
  747. : "/subsystem:console "))
  748. << replacePreprocessorTokens (*config, getExtraLinkerFlags().toString()).trim() << newLine;
  749. }
  750. }
  751. out << "!ENDIF" << newLine
  752. << "# Begin Target" << newLine
  753. << targetList;
  754. for (int i = 0; i < groups.size(); ++i)
  755. if (groups.getReference(i).getNumChildren() > 0)
  756. writeFiles (out, groups.getReference(i));
  757. out << "# End Target" << newLine
  758. << "# End Project" << newLine;
  759. }
  760. void writeFile (OutputStream& out, const RelativePath& file, const bool excludeFromBuild)
  761. {
  762. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  763. out << "# Begin Source File" << newLine
  764. << "SOURCE=" << file.toWindowsStyle().quoted() << newLine;
  765. if (excludeFromBuild)
  766. out << "# PROP Exclude_From_Build 1" << newLine;
  767. out << "# End Source File" << newLine;
  768. }
  769. void writeFiles (OutputStream& out, const Project::Item& projectItem)
  770. {
  771. if (projectItem.isGroup())
  772. {
  773. out << "# Begin Group \"" << projectItem.getName() << '"' << newLine
  774. << "# PROP Default_Filter \"cpp;c;cc;cxx;rc;def;r;odl;idl;hpj;bat\"" << newLine;
  775. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  776. writeFiles (out, projectItem.getChild (i));
  777. out << "# End Group" << newLine;
  778. }
  779. else if (projectItem.shouldBeAddedToTargetProject())
  780. {
  781. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  782. writeFile (out, path, projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()));
  783. }
  784. }
  785. void writeGroup (OutputStream& out, const String& groupName, const Array<RelativePath>& files)
  786. {
  787. if (files.size() > 0)
  788. {
  789. out << "# Begin Group \"" << groupName << '"' << newLine;
  790. for (int i = 0; i < files.size(); ++i)
  791. if (files.getReference(i).hasFileExtension ("cpp;cc;c;cxx;h;hpp;hxx"))
  792. writeFile (out, files.getReference(i), false);
  793. out << "# End Group" << newLine;
  794. }
  795. }
  796. void writeDSWFile (OutputStream& out)
  797. {
  798. out << "Microsoft Developer Studio Workspace File, Format Version 6.00 " << newLine;
  799. /*if (! project.isUsingWrapperFiles())
  800. {
  801. out << "Project: \"JUCE\"= ..\\JUCE.dsp - Package Owner=<4>" << newLine
  802. << "Package=<5>" << newLine
  803. << "{{{" << newLine
  804. << "}}}" << newLine
  805. << "Package=<4>" << newLine
  806. << "{{{" << newLine
  807. << "}}}" << newLine;
  808. }*/
  809. out << "Project: \"" << projectName << "\" = .\\" << getDSPFile().getFileName() << " - Package Owner=<4>" << newLine
  810. << "Package=<5>" << newLine
  811. << "{{{" << newLine
  812. << "}}}" << newLine
  813. << "Package=<4>" << newLine
  814. << "{{{" << newLine;
  815. /*if (! project.isUsingWrapperFiles())
  816. {
  817. out << " Begin Project Dependency" << newLine
  818. << " Project_Dep_Name JUCE" << newLine
  819. << " End Project Dependency" << newLine;
  820. }*/
  821. out << "}}}" << newLine
  822. << "Global:" << newLine
  823. << "Package=<5>" << newLine
  824. << "{{{" << newLine
  825. << "}}}" << newLine
  826. << "Package=<3>" << newLine
  827. << "{{{" << newLine
  828. << "}}}" << newLine;
  829. }
  830. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC6);
  831. };
  832. //==============================================================================
  833. class MSVCProjectExporterVC2010 : public MSVCProjectExporterBase
  834. {
  835. public:
  836. MSVCProjectExporterVC2010 (Project& project_, const ValueTree& settings_)
  837. : MSVCProjectExporterBase (project_, settings_, "VisualStudio2010")
  838. {
  839. name = getName();
  840. }
  841. static const char* getName() { return "Visual Studio 2010"; }
  842. static const char* getValueTreeTypeName() { return "VS2010"; }
  843. int getLaunchPreferenceOrderForCurrentOS()
  844. {
  845. #if JUCE_WINDOWS
  846. return 3;
  847. #else
  848. return 0;
  849. #endif
  850. }
  851. void launchProject() { getSLNFile().startAsProcess(); }
  852. static MSVCProjectExporterVC2010* createForSettings (Project& project, const ValueTree& settings)
  853. {
  854. if (settings.hasType (getValueTreeTypeName()))
  855. return new MSVCProjectExporterVC2010 (project, settings);
  856. return nullptr;
  857. }
  858. //==============================================================================
  859. void create()
  860. {
  861. createIconFile();
  862. {
  863. XmlElement projectXml ("Project");
  864. fillInProjectXml (projectXml);
  865. writeXmlOrThrow (projectXml, getVCProjFile(), "utf-8", 100);
  866. }
  867. {
  868. XmlElement filtersXml ("Project");
  869. fillInFiltersXml (filtersXml);
  870. writeXmlOrThrow (filtersXml, getVCProjFiltersFile(), "utf-8", 100);
  871. }
  872. {
  873. MemoryOutputStream mo;
  874. writeSolutionFile (mo, "11.00", "# Visual Studio 2010", getVCProjFile());
  875. overwriteFileIfDifferentOrThrow (getSLNFile(), mo);
  876. }
  877. }
  878. protected:
  879. //==============================================================================
  880. class VC2010BuildConfiguration : public MSVCBuildConfiguration
  881. {
  882. public:
  883. VC2010BuildConfiguration (Project& project, const ValueTree& settings)
  884. : MSVCBuildConfiguration (project, settings)
  885. {
  886. if (getArchitectureType().toString().isEmpty())
  887. getArchitectureType() = get32BitArchName();
  888. }
  889. //==============================================================================
  890. static const char* get32BitArchName() { return "32-bit"; }
  891. static const char* get64BitArchName() { return "x64"; }
  892. Value getArchitectureType() const { return getValue (Ids::winArchitecture); }
  893. bool is64Bit() const { return getArchitectureType().toString() == get64BitArchName(); }
  894. //==============================================================================
  895. void createPropertyEditors (PropertyListBuilder& props)
  896. {
  897. MSVCBuildConfiguration::createPropertyEditors (props);
  898. const char* const archTypes[] = { get32BitArchName(), get64BitArchName(), nullptr };
  899. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  900. StringArray (archTypes), Array<var> (archTypes)));
  901. }
  902. };
  903. BuildConfiguration::Ptr createBuildConfig (const ValueTree& settings) const
  904. {
  905. return new VC2010BuildConfiguration (project, settings);
  906. }
  907. static bool is64Bit (const BuildConfiguration& config)
  908. {
  909. return dynamic_cast <const VC2010BuildConfiguration&> (config).is64Bit();
  910. }
  911. //==============================================================================
  912. File getVCProjFile() const { return getProjectFile (".vcxproj"); }
  913. File getVCProjFiltersFile() const { return getProjectFile (".vcxproj.filters"); }
  914. File getSLNFile() const { return getProjectFile (".sln"); }
  915. String createConfigName (const BuildConfiguration& config) const
  916. {
  917. return config.getName().toString() + (is64Bit (config) ? "|x64"
  918. : "|Win32");
  919. }
  920. void setConditionAttribute (XmlElement& xml, const BuildConfiguration& config)
  921. {
  922. xml.setAttribute ("Condition", "'$(Configuration)|$(Platform)'=='" + createConfigName (config) + "'");
  923. }
  924. //==============================================================================
  925. void fillInProjectXml (XmlElement& projectXml)
  926. {
  927. projectXml.setAttribute ("DefaultTargets", "Build");
  928. projectXml.setAttribute ("ToolsVersion", "4.0");
  929. projectXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  930. {
  931. XmlElement* configsGroup = projectXml.createNewChildElement ("ItemGroup");
  932. configsGroup->setAttribute ("Label", "ProjectConfigurations");
  933. for (int i = 0; i < getNumConfigurations(); ++i)
  934. {
  935. const BuildConfiguration::Ptr config (getConfiguration(i));
  936. XmlElement* e = configsGroup->createNewChildElement ("ProjectConfiguration");
  937. e->setAttribute ("Include", createConfigName (*config));
  938. e->createNewChildElement ("Configuration")->addTextElement (config->getName().toString());
  939. e->createNewChildElement ("Platform")->addTextElement (is64Bit (*config) ? "x64" : "Win32");
  940. }
  941. }
  942. {
  943. XmlElement* globals = projectXml.createNewChildElement ("PropertyGroup");
  944. globals->setAttribute ("Label", "Globals");
  945. globals->createNewChildElement ("ProjectGuid")->addTextElement (projectGUID);
  946. }
  947. {
  948. XmlElement* imports = projectXml.createNewChildElement ("Import");
  949. imports->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
  950. }
  951. for (int i = 0; i < getNumConfigurations(); ++i)
  952. {
  953. const BuildConfiguration::Ptr config (getConfiguration(i));
  954. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  955. setConditionAttribute (*e, *config);
  956. e->setAttribute ("Label", "Configuration");
  957. e->createNewChildElement ("ConfigurationType")->addTextElement (getProjectType());
  958. e->createNewChildElement ("UseOfMfc")->addTextElement ("false");
  959. e->createNewChildElement ("CharacterSet")->addTextElement ("MultiByte");
  960. if (! config->isDebug().getValue())
  961. e->createNewChildElement ("WholeProgramOptimization")->addTextElement ("true");
  962. if (is64Bit (*config))
  963. e->createNewChildElement ("PlatformToolset")->addTextElement ("Windows7.1SDK");
  964. }
  965. {
  966. XmlElement* e = projectXml.createNewChildElement ("Import");
  967. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
  968. }
  969. {
  970. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  971. e->setAttribute ("Label", "ExtensionSettings");
  972. }
  973. {
  974. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  975. e->setAttribute ("Label", "PropertySheets");
  976. XmlElement* p = e->createNewChildElement ("Import");
  977. p->setAttribute ("Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props");
  978. p->setAttribute ("Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')");
  979. p->setAttribute ("Label", "LocalAppDataPlatform");
  980. }
  981. {
  982. XmlElement* e = projectXml.createNewChildElement ("PropertyGroup");
  983. e->setAttribute ("Label", "UserMacros");
  984. }
  985. {
  986. XmlElement* props = projectXml.createNewChildElement ("PropertyGroup");
  987. props->createNewChildElement ("_ProjectFileVersion")->addTextElement ("10.0.30319.1");
  988. for (int i = 0; i < getNumConfigurations(); ++i)
  989. {
  990. const BuildConfiguration::Ptr config (getConfiguration(i));
  991. XmlElement* outdir = props->createNewChildElement ("OutDir");
  992. setConditionAttribute (*outdir, *config);
  993. outdir->addTextElement (getConfigTargetPath (*config) + "\\");
  994. XmlElement* intdir = props->createNewChildElement ("IntDir");
  995. setConditionAttribute (*intdir, *config);
  996. intdir->addTextElement (getConfigTargetPath (*config) + "\\");
  997. XmlElement* name = props->createNewChildElement ("TargetName");
  998. setConditionAttribute (*name, *config);
  999. name->addTextElement (getBinaryFileForConfig (*config).upToLastOccurrenceOf (".", false, false));
  1000. }
  1001. }
  1002. for (int i = 0; i < getNumConfigurations(); ++i)
  1003. {
  1004. const BuildConfiguration::Ptr config (getConfiguration(i));
  1005. String binariesPath (getConfigTargetPath (*config));
  1006. String intermediatesPath (getIntermediatesPath (*config));
  1007. const bool isDebug = (bool) config->isDebug().getValue();
  1008. const String binaryName (File::createLegalFileName (config->getTargetBinaryName().toString()));
  1009. const String outputFileName (getBinaryFileForConfig (*config));
  1010. XmlElement* group = projectXml.createNewChildElement ("ItemDefinitionGroup");
  1011. setConditionAttribute (*group, *config);
  1012. {
  1013. XmlElement* midl = group->createNewChildElement ("Midl");
  1014. midl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1015. : "NDEBUG;%(PreprocessorDefinitions)");
  1016. midl->createNewChildElement ("MkTypLibCompatible")->addTextElement ("true");
  1017. midl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1018. midl->createNewChildElement ("TargetEnvironment")->addTextElement ("Win32");
  1019. midl->createNewChildElement ("HeaderFileName");
  1020. }
  1021. {
  1022. XmlElement* cl = group->createNewChildElement ("ClCompile");
  1023. cl->createNewChildElement ("Optimization")->addTextElement (isDebug ? "Disabled" : "MaxSpeed");
  1024. if (isDebug)
  1025. cl->createNewChildElement ("DebugInformationFormat")->addTextElement (is64Bit (*config) ? "ProgramDatabase"
  1026. : "EditAndContinue");
  1027. StringArray includePaths (getHeaderSearchPaths (*config));
  1028. includePaths.add ("%(AdditionalIncludeDirectories)");
  1029. cl->createNewChildElement ("AdditionalIncludeDirectories")->addTextElement (includePaths.joinIntoString (";"));
  1030. cl->createNewChildElement ("PreprocessorDefinitions")->addTextElement (getPreprocessorDefs (*config, ";") + ";%(PreprocessorDefinitions)");
  1031. cl->createNewChildElement ("RuntimeLibrary")->addTextElement (msvcNeedsDLLRuntimeLib ? (isDebug ? "MultiThreadedDLLDebug" : "MultiThreadedDLL")
  1032. : (isDebug ? "MultiThreadedDebug" : "MultiThreaded"));
  1033. cl->createNewChildElement ("RuntimeTypeInfo")->addTextElement ("true");
  1034. cl->createNewChildElement ("PrecompiledHeader");
  1035. cl->createNewChildElement ("AssemblerListingLocation")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  1036. cl->createNewChildElement ("ObjectFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  1037. cl->createNewChildElement ("ProgramDataBaseFileName")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/"));
  1038. cl->createNewChildElement ("WarningLevel")->addTextElement ("Level" + String (getWarningLevel (*config)));
  1039. cl->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1040. cl->createNewChildElement ("MultiProcessorCompilation")->addTextElement ("true");
  1041. const String extraFlags (replacePreprocessorTokens (*config, getExtraCompilerFlags().toString()).trim());
  1042. if (extraFlags.isNotEmpty())
  1043. cl->createNewChildElement ("AdditionalOptions")->addTextElement (extraFlags + " %(AdditionalOptions)");
  1044. }
  1045. {
  1046. XmlElement* res = group->createNewChildElement ("ResourceCompile");
  1047. res->createNewChildElement ("PreprocessorDefinitions")->addTextElement (isDebug ? "_DEBUG;%(PreprocessorDefinitions)"
  1048. : "NDEBUG;%(PreprocessorDefinitions)");
  1049. }
  1050. {
  1051. XmlElement* link = group->createNewChildElement ("Link");
  1052. link->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (binariesPath + "/" + outputFileName));
  1053. link->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1054. link->createNewChildElement ("IgnoreSpecificDefaultLibraries")->addTextElement (isDebug ? "libcmt.lib; msvcrt.lib;;%(IgnoreSpecificDefaultLibraries)"
  1055. : "%(IgnoreSpecificDefaultLibraries)");
  1056. link->createNewChildElement ("GenerateDebugInformation")->addTextElement (isDebug ? "true" : "false");
  1057. link->createNewChildElement ("ProgramDatabaseFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".pdb"));
  1058. link->createNewChildElement ("SubSystem")->addTextElement (msvcIsWindowsSubsystem ? "Windows" : "Console");
  1059. if (! is64Bit (*config))
  1060. link->createNewChildElement ("TargetMachine")->addTextElement ("MachineX86");
  1061. if (! isDebug)
  1062. {
  1063. link->createNewChildElement ("OptimizeReferences")->addTextElement ("true");
  1064. link->createNewChildElement ("EnableCOMDATFolding")->addTextElement ("true");
  1065. }
  1066. String extraLinkerOptions (getExtraLinkerFlags().toString());
  1067. if (extraLinkerOptions.isNotEmpty())
  1068. link->createNewChildElement ("AdditionalOptions")->addTextElement (replacePreprocessorTokens (*config, extraLinkerOptions).trim()
  1069. + " %(AdditionalOptions)");
  1070. }
  1071. {
  1072. XmlElement* bsc = group->createNewChildElement ("Bscmake");
  1073. bsc->createNewChildElement ("SuppressStartupBanner")->addTextElement ("true");
  1074. bsc->createNewChildElement ("OutputFile")->addTextElement (FileHelpers::windowsStylePath (intermediatesPath + "/" + binaryName + ".bsc"));
  1075. }
  1076. }
  1077. {
  1078. XmlElement* cppFiles = projectXml.createNewChildElement ("ItemGroup");
  1079. XmlElement* headerFiles = projectXml.createNewChildElement ("ItemGroup");
  1080. for (int i = 0; i < groups.size(); ++i)
  1081. if (groups.getReference(i).getNumChildren() > 0)
  1082. addFilesToCompile (groups.getReference(i), *cppFiles, *headerFiles, false);
  1083. }
  1084. if (hasIcon)
  1085. {
  1086. {
  1087. XmlElement* iconGroup = projectXml.createNewChildElement ("ItemGroup");
  1088. XmlElement* e = iconGroup->createNewChildElement ("None");
  1089. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1090. }
  1091. {
  1092. XmlElement* rcGroup = projectXml.createNewChildElement ("ItemGroup");
  1093. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1094. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1095. }
  1096. }
  1097. {
  1098. XmlElement* e = projectXml.createNewChildElement ("Import");
  1099. e->setAttribute ("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
  1100. }
  1101. {
  1102. XmlElement* e = projectXml.createNewChildElement ("ImportGroup");
  1103. e->setAttribute ("Label", "ExtensionTargets");
  1104. }
  1105. }
  1106. String getProjectType() const
  1107. {
  1108. if (projectType.isGUIApplication() || projectType.isCommandLineApp()) return "Application";
  1109. else if (isLibraryDLL()) return "DynamicLibrary";
  1110. else if (projectType.isLibrary()) return "StaticLibrary";
  1111. jassertfalse;
  1112. return String::empty;
  1113. }
  1114. //==============================================================================
  1115. void addFileToCompile (const RelativePath& file, XmlElement& cpps, XmlElement& headers, const bool excludeFromBuild, const bool useStdcall)
  1116. {
  1117. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1118. if (file.hasFileExtension ("cpp;cc;cxx;c"))
  1119. {
  1120. XmlElement* e = cpps.createNewChildElement ("ClCompile");
  1121. e->setAttribute ("Include", file.toWindowsStyle());
  1122. if (excludeFromBuild)
  1123. e->createNewChildElement ("ExcludedFromBuild")->addTextElement ("true");
  1124. if (useStdcall)
  1125. {
  1126. jassertfalse;
  1127. }
  1128. }
  1129. else if (file.hasFileExtension (headerFileExtensions))
  1130. {
  1131. headers.createNewChildElement ("ClInclude")->setAttribute ("Include", file.toWindowsStyle());
  1132. }
  1133. }
  1134. void addFilesToCompile (const Array<RelativePath>& files, XmlElement& cpps, XmlElement& headers, bool useStdCall)
  1135. {
  1136. for (int i = 0; i < files.size(); ++i)
  1137. addFileToCompile (files.getReference(i), cpps, headers, false, useStdCall);
  1138. }
  1139. void addFilesToCompile (const Project::Item& projectItem, XmlElement& cpps, XmlElement& headers, bool useStdCall)
  1140. {
  1141. if (projectItem.isGroup())
  1142. {
  1143. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1144. addFilesToCompile (projectItem.getChild(i), cpps, headers, useStdCall);
  1145. }
  1146. else
  1147. {
  1148. if (projectItem.shouldBeAddedToTargetProject())
  1149. {
  1150. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  1151. if (path.hasFileExtension (headerFileExtensions) || (path.hasFileExtension ("cpp;cc;c;cxx")))
  1152. addFileToCompile (path, cpps, headers, ! projectItem.shouldBeCompiled(), useStdCall);
  1153. }
  1154. }
  1155. }
  1156. //==============================================================================
  1157. void addFilterGroup (XmlElement& groups, const String& path)
  1158. {
  1159. XmlElement* e = groups.createNewChildElement ("Filter");
  1160. e->setAttribute ("Include", path);
  1161. e->createNewChildElement ("UniqueIdentifier")->addTextElement (createGUID (path + "_guidpathsaltxhsdf"));
  1162. }
  1163. void addFileToFilter (const RelativePath& file, const String& groupPath, XmlElement& cpps, XmlElement& headers)
  1164. {
  1165. XmlElement* e;
  1166. if (file.hasFileExtension (headerFileExtensions))
  1167. e = headers.createNewChildElement ("ClInclude");
  1168. else
  1169. e = cpps.createNewChildElement ("ClCompile");
  1170. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  1171. e->setAttribute ("Include", file.toWindowsStyle());
  1172. e->createNewChildElement ("Filter")->addTextElement (groupPath);
  1173. }
  1174. void addFilesToFilter (const Project::Item& projectItem, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1175. {
  1176. if (projectItem.isGroup())
  1177. {
  1178. addFilterGroup (groups, path);
  1179. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  1180. addFilesToFilter (projectItem.getChild(i),
  1181. (path.isEmpty() ? String::empty : (path + "\\")) + projectItem.getChild(i).getName().toString(),
  1182. cpps, headers, groups);
  1183. }
  1184. else
  1185. {
  1186. if (projectItem.shouldBeAddedToTargetProject())
  1187. {
  1188. addFileToFilter (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder),
  1189. path.upToLastOccurrenceOf ("\\", false, false), cpps, headers);
  1190. }
  1191. }
  1192. }
  1193. void addFilesToFilter (const Array<RelativePath>& files, const String& path, XmlElement& cpps, XmlElement& headers, XmlElement& groups)
  1194. {
  1195. if (files.size() > 0)
  1196. {
  1197. addFilterGroup (groups, path);
  1198. for (int i = 0; i < files.size(); ++i)
  1199. addFileToFilter (files.getReference(i), path, cpps, headers);
  1200. }
  1201. }
  1202. void fillInFiltersXml (XmlElement& filterXml)
  1203. {
  1204. filterXml.setAttribute ("ToolsVersion", "4.0");
  1205. filterXml.setAttribute ("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  1206. XmlElement* groupsXml = filterXml.createNewChildElement ("ItemGroup");
  1207. XmlElement* cpps = filterXml.createNewChildElement ("ItemGroup");
  1208. XmlElement* headers = filterXml.createNewChildElement ("ItemGroup");
  1209. for (int i = 0; i < groups.size(); ++i)
  1210. if (groups.getReference(i).getNumChildren() > 0)
  1211. addFilesToFilter (groups.getReference(i), groups.getReference(i).getName().toString(), *cpps, *headers, *groupsXml);
  1212. if (iconFile.exists())
  1213. {
  1214. {
  1215. XmlElement* iconGroup = filterXml.createNewChildElement ("ItemGroup");
  1216. XmlElement* e = iconGroup->createNewChildElement ("None");
  1217. e->setAttribute ("Include", ".\\" + iconFile.getFileName());
  1218. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1219. }
  1220. {
  1221. XmlElement* rcGroup = filterXml.createNewChildElement ("ItemGroup");
  1222. XmlElement* e = rcGroup->createNewChildElement ("ResourceCompile");
  1223. e->setAttribute ("Include", ".\\" + rcFile.getFileName());
  1224. e->createNewChildElement ("Filter")->addTextElement (ProjectSaver::getJuceCodeGroupName());
  1225. }
  1226. }
  1227. }
  1228. //==============================================================================
  1229. JUCE_DECLARE_NON_COPYABLE (MSVCProjectExporterVC2010);
  1230. };
  1231. #endif // __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__