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.

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