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.

848 lines
39KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 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. //==============================================================================
  22. class MSVCProjectExporter : public ProjectExporter
  23. {
  24. public:
  25. //==============================================================================
  26. enum VisualStudioVersion
  27. {
  28. visualStudio6,
  29. visualStudio2005,
  30. visualStudio2008
  31. };
  32. static const char* getNameVC6() { return "Visual C++ 6.0"; }
  33. static const char* getName2005() { return "Visual Studio 2005"; }
  34. static const char* getName2008() { return "Visual Studio 2008"; }
  35. static const char* getValueTreeTypeName (VisualStudioVersion version)
  36. {
  37. switch (version)
  38. {
  39. case visualStudio6: return "MSVC6"; break;
  40. case visualStudio2005: return "VS2005"; break;
  41. case visualStudio2008: return "VS2008"; break;
  42. default: jassertfalse; break;
  43. }
  44. return 0;
  45. }
  46. //==============================================================================
  47. static MSVCProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  48. {
  49. if (settings.hasType (getValueTreeTypeName (visualStudio6)))
  50. return new MSVCProjectExporter (project, settings, visualStudio6);
  51. else if (settings.hasType (getValueTreeTypeName (visualStudio2005)))
  52. return new MSVCProjectExporter (project, settings, visualStudio2005);
  53. else if (settings.hasType (getValueTreeTypeName (visualStudio2008)))
  54. return new MSVCProjectExporter (project, settings, visualStudio2008);
  55. return 0;
  56. }
  57. //==============================================================================
  58. MSVCProjectExporter (Project& project_, const ValueTree& settings_, const VisualStudioVersion version_)
  59. : ProjectExporter (project_, settings_), version (version_)
  60. {
  61. String subFolderName (getDefaultBuildsRootFolder());
  62. switch (version)
  63. {
  64. case visualStudio6: name = "Visual C++ 6.0"; subFolderName += "MSVC6"; break;
  65. case visualStudio2005: name = "Visual Studio 2005"; subFolderName += "VisualStudio2005"; break;
  66. case visualStudio2008: name = "Visual Studio 2008"; subFolderName += "VisualStudio2008"; break;
  67. default: jassertfalse; break;
  68. }
  69. if (getTargetLocation().toString().isEmpty())
  70. getTargetLocation() = subFolderName;
  71. if (getVSTFolder().toString().isEmpty())
  72. getVSTFolder() = "c:\\SDKs\\vstsdk2.4";
  73. if (getRTASFolder().toString().isEmpty())
  74. getRTASFolder() = "c:\\SDKs\\PT_80_SDK";
  75. }
  76. ~MSVCProjectExporter() {}
  77. //==============================================================================
  78. bool isDefaultFormatForCurrentOS()
  79. {
  80. #if JUCE_WINDOWS
  81. return true;
  82. #else
  83. return false;
  84. #endif
  85. }
  86. bool isPossibleForCurrentProject() { return true; }
  87. bool usesMMFiles() const { return false; }
  88. const String getOSTestMacro() { return "(defined (_WIN32) || defined (_WIN64))"; }
  89. void launchProject()
  90. {
  91. getSLNFile().startAsProcess();
  92. }
  93. void createPropertyEditors (Array <PropertyComponent*>& props)
  94. {
  95. ProjectExporter::createPropertyEditors (props);
  96. }
  97. //==============================================================================
  98. const String create()
  99. {
  100. if (version == visualStudio6)
  101. {
  102. {
  103. MemoryOutputStream mo;
  104. writeVC6Project (mo);
  105. if (! overwriteFileWithNewDataIfDifferent (getDSPFile(), mo))
  106. return "Can't write to the VC project file: " + getDSPFile().getFullPathName();
  107. }
  108. {
  109. MemoryOutputStream mo;
  110. writeDSWFile (mo);
  111. if (! overwriteFileWithNewDataIfDifferent (getDSWFile(), mo))
  112. return "Can't write to the VC solution file: " + getDSWFile().getFullPathName();
  113. }
  114. }
  115. else
  116. {
  117. projectGUID = createGUID (project.getProjectUID());
  118. XmlElement masterXml ("VisualStudioProject");
  119. fillInMasterXml (masterXml);
  120. {
  121. MemoryOutputStream mo;
  122. masterXml.writeToStream (mo, String::empty, false, true, "UTF-8", 10);
  123. if (! overwriteFileWithNewDataIfDifferent (getVCProjFile(), mo))
  124. return "Can't write to the VC project file: " + getVCProjFile().getFullPathName();
  125. }
  126. {
  127. MemoryOutputStream mo;
  128. writeSolutionFile (mo);
  129. if (! overwriteFileWithNewDataIfDifferent (getSLNFile(), mo))
  130. return "Can't write to the VC solution file: " + getSLNFile().getFullPathName();
  131. }
  132. }
  133. return String::empty;
  134. }
  135. private:
  136. String projectGUID;
  137. const VisualStudioVersion version;
  138. const File getProjectFile (const String& extension) const { return getTargetFolder().getChildFile (project.getProjectFilenameRoot()).withFileExtension (extension); }
  139. const File getVCProjFile() const { return getProjectFile (".vcproj"); }
  140. const File getSLNFile() const { return getProjectFile (".sln"); }
  141. const File getDSPFile() const { return getProjectFile (".dsp"); }
  142. const File getDSWFile() const { return getProjectFile (".dsw"); }
  143. //==============================================================================
  144. void fillInMasterXml (XmlElement& masterXml)
  145. {
  146. masterXml.setAttribute ("ProjectType", "Visual C++");
  147. switch (version)
  148. {
  149. case visualStudio2005: masterXml.setAttribute ("Version", "8.00"); break;
  150. case visualStudio2008: masterXml.setAttribute ("Version", "9.00"); break;
  151. default: jassertfalse; break;
  152. }
  153. masterXml.setAttribute ("Name", project.getProjectName().toString());
  154. masterXml.setAttribute ("ProjectGUID", projectGUID);
  155. masterXml.setAttribute ("TargetFrameworkVersion", "131072");
  156. {
  157. XmlElement* platforms = masterXml.createNewChildElement ("Platforms");
  158. XmlElement* platform = platforms->createNewChildElement ("Platform");
  159. platform->setAttribute ("Name", "Win32");
  160. }
  161. masterXml.createNewChildElement ("ToolFiles");
  162. createConfigs (*masterXml.createNewChildElement ("Configurations"));
  163. masterXml.createNewChildElement ("References");
  164. createFiles (*masterXml.createNewChildElement ("Files"));
  165. masterXml.createNewChildElement ("Globals");
  166. }
  167. //==============================================================================
  168. void addFile (const RelativePath& file, XmlElement& parent, const bool excludeFromBuild, const bool useStdcall)
  169. {
  170. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  171. XmlElement* fileXml = parent.createNewChildElement ("File");
  172. fileXml->setAttribute ("RelativePath", file.toWindowsStyle());
  173. if (excludeFromBuild || useStdcall)
  174. {
  175. for (int i = 0; i < project.getNumConfigurations(); ++i)
  176. {
  177. Project::BuildConfiguration config (project.getConfiguration (i));
  178. XmlElement* fileConfig = fileXml->createNewChildElement ("FileConfiguration");
  179. fileConfig->setAttribute ("Name", createConfigName (config));
  180. if (excludeFromBuild)
  181. fileConfig->setAttribute ("ExcludedFromBuild", "true");
  182. XmlElement* tool = createToolElement (*fileConfig, "VCCLCompilerTool");
  183. if (useStdcall)
  184. tool->setAttribute ("CallingConvention", "2");
  185. }
  186. }
  187. }
  188. XmlElement* createGroup (const String& name, XmlElement& parent)
  189. {
  190. XmlElement* filter = parent.createNewChildElement ("Filter");
  191. filter->setAttribute ("Name", name);
  192. return filter;
  193. }
  194. void addFiles (const Project::Item& projectItem, XmlElement& parent)
  195. {
  196. if (projectItem.isGroup())
  197. {
  198. XmlElement* filter = createGroup (projectItem.getName().toString(), parent);
  199. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  200. addFiles (projectItem.getChild(i), *filter);
  201. }
  202. else
  203. {
  204. if (projectItem.shouldBeAddedToTargetProject())
  205. {
  206. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  207. addFile (path, parent,
  208. projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()),
  209. false);
  210. }
  211. }
  212. }
  213. void addGroup (XmlElement& parent, const String& groupName, const Array<RelativePath>& files, const bool useStdcall)
  214. {
  215. if (files.size() > 0)
  216. {
  217. XmlElement* const group = createGroup (groupName, parent);
  218. for (int i = 0; i < files.size(); ++i)
  219. if (files.getReference(i).hasFileExtension ("cpp;c;h"))
  220. addFile (files.getReference(i), *group, false,
  221. useStdcall && shouldFileBeCompiledByDefault (files.getReference(i)));
  222. }
  223. }
  224. void createFiles (XmlElement& files)
  225. {
  226. addFiles (project.getMainGroup(), files);
  227. addGroup (files, project.getJuceCodeGroupName(), juceWrapperFiles, false);
  228. addGroup (files, "Juce VST Wrapper", getVSTFilesRequired(), false);
  229. addGroup (files, "Juce RTAS Wrapper", getRTASFilesRequired(), true);
  230. }
  231. //==============================================================================
  232. const Array<RelativePath> getRTASFilesRequired() const
  233. {
  234. Array<RelativePath> s;
  235. if (isRTAS())
  236. {
  237. static const char* files[] = { "extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode1.cpp",
  238. "extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode2.cpp",
  239. "extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode3.cpp",
  240. "extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode_Header.h",
  241. "extras/audio plugins/wrapper/RTAS/juce_RTAS_WinUtilities.cpp",
  242. "extras/audio plugins/wrapper/RTAS/juce_RTAS_Wrapper.cpp" };
  243. for (int i = 0; i < numElementsInArray (files); ++i)
  244. s.add (getJucePathFromTargetFolder().getChildFile (files[i]));
  245. }
  246. return s;
  247. }
  248. const String getIntermediatesPath (const Project::BuildConfiguration& config) const
  249. {
  250. return ".\\" + File::createLegalFileName (config.getName().toString().trim());
  251. }
  252. const String getConfigTargetPath (const Project::BuildConfiguration& config) const
  253. {
  254. const String binaryPath (config.getTargetBinaryRelativePath().toString().trim());
  255. if (binaryPath.isEmpty())
  256. return getIntermediatesPath (config);
  257. return ".\\" + RelativePath (binaryPath, RelativePath::projectFolder)
  258. .rebased (project.getFile().getParentDirectory(), getTargetFolder(), RelativePath::buildTargetFolder)
  259. .toWindowsStyle();
  260. }
  261. const String getTargetBinarySuffix() const
  262. {
  263. if (project.isLibrary())
  264. return ".lib";
  265. else if (isRTAS())
  266. return ".dpm";
  267. else if (project.isAudioPlugin() || project.isBrowserPlugin())
  268. return ".dll";
  269. return ".exe";
  270. }
  271. const String getPreprocessorDefs (const Project::BuildConfiguration& config, const String& joinString) const
  272. {
  273. StringArray defines;
  274. defines.add ("WIN32");
  275. defines.add ("_WINDOWS");
  276. defines.add (config.isDebug().getValue() ? "_DEBUG" : "NDEBUG");
  277. if (project.isCommandLineApp())
  278. defines.add ("_CONSOLE");
  279. if (project.isLibrary())
  280. defines.add ("_LIB");
  281. if (isRTAS())
  282. {
  283. RelativePath rtasFolder (getRTASFolder().toString(), RelativePath::unknown);
  284. defines.add ("JucePlugin_WinBag_path="
  285. + replaceCEscapeChars (rtasFolder.getChildFile ("WinBag")
  286. .toWindowsStyle().quoted()));
  287. }
  288. defines.addArray (config.parsePreprocessorDefs());
  289. return defines.joinIntoString (joinString);
  290. }
  291. const StringArray getHeaderSearchPaths (const Project::BuildConfiguration& config) const
  292. {
  293. StringArray searchPaths (config.getHeaderSearchPaths());
  294. if (project.shouldAddVSTFolderToPath() && getVSTFolder().toString().isNotEmpty())
  295. searchPaths.add (RelativePath (getVSTFolder().toString(), RelativePath::projectFolder)
  296. .rebased (project.getFile().getParentDirectory(), getTargetFolder(), RelativePath::buildTargetFolder)
  297. .toWindowsStyle());
  298. if (project.isAudioPlugin())
  299. searchPaths.add (juceWrapperFiles[0].getParentDirectory().toWindowsStyle());
  300. if (isRTAS())
  301. {
  302. static const char* rtasIncludePaths[] = { "AlturaPorts/TDMPlugins/PluginLibrary/EffectClasses",
  303. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses",
  304. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses/Interfaces",
  305. "AlturaPorts/TDMPlugins/PluginLibrary/Utilities",
  306. "AlturaPorts/TDMPlugins/PluginLibrary/RTASP_Adapt",
  307. "AlturaPorts/TDMPlugins/PluginLibrary/CoreClasses",
  308. "AlturaPorts/TDMPlugins/PluginLibrary/Controls",
  309. "AlturaPorts/TDMPlugins/PluginLibrary/Meters",
  310. "AlturaPorts/TDMPlugins/PluginLibrary/ViewClasses",
  311. "AlturaPorts/TDMPlugins/PluginLibrary/DSPClasses",
  312. "AlturaPorts/TDMPlugins/PluginLibrary/Interfaces",
  313. "AlturaPorts/TDMPlugins/common",
  314. "AlturaPorts/TDMPlugins/common/Platform",
  315. "AlturaPorts/TDMPlugins/SignalProcessing/Public",
  316. "AlturaPorts/TDMPlugIns/DSPManager/Interfaces",
  317. "AlturaPorts/SADriver/Interfaces",
  318. "AlturaPorts/DigiPublic/Interfaces",
  319. "AlturaPorts/Fic/Interfaces/DAEClient",
  320. "AlturaPorts/NewFileLibs/Cmn",
  321. "AlturaPorts/NewFileLibs/DOA",
  322. "AlturaPorts/AlturaSource/PPC_H",
  323. "AlturaPorts/AlturaSource/AppSupport",
  324. "AvidCode/AVX2sdk/AVX/avx2/avx2sdk/inc",
  325. "xplat/AVX/avx2/avx2sdk/inc" };
  326. RelativePath sdkFolder (getRTASFolder().toString(), RelativePath::projectFolder);
  327. sdkFolder = sdkFolder.rebased (project.getFile().getParentDirectory(), getTargetFolder(), RelativePath::buildTargetFolder);
  328. for (int i = 0; i < numElementsInArray (rtasIncludePaths); ++i)
  329. searchPaths.add (sdkFolder.getChildFile (rtasIncludePaths[i]).toWindowsStyle());
  330. }
  331. return searchPaths;
  332. }
  333. XmlElement* createToolElement (XmlElement& parent, const String& name) const
  334. {
  335. XmlElement* const e = parent.createNewChildElement ("Tool");
  336. e->setAttribute ("Name", name);
  337. return e;
  338. }
  339. void createConfig (XmlElement& xml, const Project::BuildConfiguration& config) const
  340. {
  341. String binariesPath (getConfigTargetPath (config));
  342. String intermediatesPath (getIntermediatesPath (config));
  343. const bool isDebug = (bool) config.isDebug().getValue();
  344. const String binaryName (File::createLegalFileName (config.getTargetBinaryName().toString()));
  345. xml.setAttribute ("Name", createConfigName (config));
  346. xml.setAttribute ("OutputDirectory", windowsStylePath (binariesPath));
  347. xml.setAttribute ("IntermediateDirectory", windowsStylePath (intermediatesPath));
  348. xml.setAttribute ("ConfigurationType", (project.isAudioPlugin() || project.isBrowserPlugin())
  349. ? "2" : (project.isLibrary() ? "4" : "1"));
  350. xml.setAttribute ("UseOfMFC", "0");
  351. xml.setAttribute ("ATLMinimizesCRunTimeLibraryUsage", "false");
  352. xml.setAttribute ("CharacterSet", "2");
  353. if (! isDebug)
  354. xml.setAttribute ("WholeProgramOptimization", "1");
  355. createToolElement (xml, "VCPreBuildEventTool");
  356. XmlElement* customBuild = createToolElement (xml, "VCCustomBuildTool");
  357. if (isRTAS())
  358. {
  359. RelativePath rsrFile (getJucePathFromTargetFolder().getChildFile ("extras/audio plugins/wrapper/RTAS/juce_RTAS_WinResources.rsr"));
  360. customBuild->setAttribute ("CommandLine", "copy /Y \"" + rsrFile.toWindowsStyle() + "\" \"$(TargetPath)\".rsr");
  361. customBuild->setAttribute ("Outputs", "\"$(TargetPath)\".rsr");
  362. }
  363. createToolElement (xml, "VCXMLDataGeneratorTool");
  364. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  365. if (! project.isLibrary())
  366. {
  367. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  368. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  369. midl->setAttribute ("MkTypLibCompatible", "true");
  370. midl->setAttribute ("SuppressStartupBanner", "true");
  371. midl->setAttribute ("TargetEnvironment", "1");
  372. midl->setAttribute ("TypeLibraryName", windowsStylePath (intermediatesPath + "/" + binaryName + ".tlb"));
  373. midl->setAttribute ("HeaderFileName", "");
  374. }
  375. {
  376. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  377. const int optimiseLevel = (int) config.getOptimisationLevel().getValue();
  378. compiler->setAttribute ("Optimization", optimiseLevel <= 1 ? "0" : (optimiseLevel == 2 ? "2" : "3"));
  379. if (isDebug)
  380. {
  381. compiler->setAttribute ("BufferSecurityCheck", "");
  382. compiler->setAttribute ("DebugInformationFormat", "4");
  383. }
  384. else
  385. {
  386. compiler->setAttribute ("InlineFunctionExpansion", "1");
  387. compiler->setAttribute ("StringPooling", "true");
  388. }
  389. compiler->setAttribute ("AdditionalIncludeDirectories", getHeaderSearchPaths (config).joinIntoString (";"));
  390. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  391. compiler->setAttribute ("RuntimeLibrary", isRTAS() ? (isDebug ? 3 : 2) // MT DLL
  392. : (isDebug ? 1 : 0)); // MT static
  393. compiler->setAttribute ("RuntimeTypeInfo", "true");
  394. compiler->setAttribute ("UsePrecompiledHeader", "0");
  395. compiler->setAttribute ("PrecompiledHeaderFile", windowsStylePath (intermediatesPath + "/" + binaryName + ".pch"));
  396. compiler->setAttribute ("AssemblerListingLocation", windowsStylePath (intermediatesPath + "/"));
  397. compiler->setAttribute ("ObjectFile", windowsStylePath (intermediatesPath + "/"));
  398. compiler->setAttribute ("ProgramDataBaseFileName", windowsStylePath (intermediatesPath + "/"));
  399. compiler->setAttribute ("WarningLevel", "3");
  400. compiler->setAttribute ("SuppressStartupBanner", "true");
  401. if (getExtraCompilerFlags().toString().isNotEmpty())
  402. compiler->setAttribute ("AdditionalOptions", getExtraCompilerFlags().toString().trim());
  403. }
  404. createToolElement (xml, "VCManagedResourceCompilerTool");
  405. {
  406. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  407. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  408. }
  409. createToolElement (xml, "VCPreLinkEventTool");
  410. if (! project.isLibrary())
  411. {
  412. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  413. linker->setAttribute ("OutputFile", windowsStylePath (binariesPath + "/" + config.getTargetBinaryName().toString() + getTargetBinarySuffix()));
  414. linker->setAttribute ("SuppressStartupBanner", "true");
  415. if (project.getJuceLinkageMode() == Project::useLinkedJuce)
  416. linker->setAttribute ("AdditionalLibraryDirectories", getJucePathFromTargetFolder().getChildFile ("bin").toWindowsStyle());
  417. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  418. linker->setAttribute ("GenerateDebugInformation", isDebug ? "true" : "false");
  419. linker->setAttribute ("ProgramDatabaseFile", windowsStylePath (intermediatesPath + "/" + binaryName + ".pdb"));
  420. linker->setAttribute ("SubSystem", project.isCommandLineApp() ? "1" : "2");
  421. if (! isDebug)
  422. {
  423. linker->setAttribute ("GenerateManifest", "false");
  424. linker->setAttribute ("OptimizeReferences", "2");
  425. linker->setAttribute ("EnableCOMDATFolding", "2");
  426. }
  427. linker->setAttribute ("RandomizedBaseAddress", "1");
  428. linker->setAttribute ("DataExecutionPrevention", "0");
  429. linker->setAttribute ("TargetMachine", "1");
  430. String extraLinkerOptions (getExtraLinkerFlags().toString());
  431. if (isRTAS())
  432. {
  433. extraLinkerOptions += " /FORCE:multiple";
  434. linker->setAttribute ("DelayLoadDLLs", "DAE.dll; DigiExt.dll; DSI.dll; PluginLib.dll; DSPManager.dll");
  435. linker->setAttribute ("ModuleDefinitionFile", getJucePathFromTargetFolder()
  436. .getChildFile ("extras/audio plugins/wrapper/RTAS/juce_RTAS_WinExports.def")
  437. .toWindowsStyle());
  438. }
  439. if (extraLinkerOptions.isNotEmpty())
  440. linker->setAttribute ("AdditionalOptions", extraLinkerOptions.trim());
  441. }
  442. else
  443. {
  444. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  445. librarian->setAttribute ("OutputFile", windowsStylePath (binariesPath + "/" + config.getTargetBinaryName().toString() + getTargetBinarySuffix()));
  446. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  447. }
  448. createToolElement (xml, "VCALinkTool");
  449. createToolElement (xml, "VCManifestTool");
  450. createToolElement (xml, "VCXDCMakeTool");
  451. {
  452. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  453. bscMake->setAttribute ("SuppressStartupBanner", "true");
  454. bscMake->setAttribute ("OutputFile", windowsStylePath (intermediatesPath + "/" + binaryName + ".bsc"));
  455. }
  456. createToolElement (xml, "VCFxCopTool");
  457. if (! project.isLibrary())
  458. createToolElement (xml, "VCAppVerifierTool");
  459. createToolElement (xml, "VCPostBuildEventTool");
  460. }
  461. void createConfigs (XmlElement& configs)
  462. {
  463. for (int i = 0; i < project.getNumConfigurations(); ++i)
  464. {
  465. Project::BuildConfiguration config (project.getConfiguration (i));
  466. createConfig (*configs.createNewChildElement ("Configuration"), config);
  467. }
  468. }
  469. const String createConfigName (const Project::BuildConfiguration& config) const
  470. {
  471. return config.getName().toString() + "|Win32";
  472. }
  473. //==============================================================================
  474. void writeSolutionFile (OutputStream& out)
  475. {
  476. out << newLine << "Microsoft Visual Studio Solution File, Format Version ";
  477. switch (version)
  478. {
  479. case visualStudio2005: out << "8.00" << newLine << "# Visual C++ Express 2005"; break;
  480. case visualStudio2008: out << "10.00" << newLine << "# Visual C++ Express 2008"; break;
  481. default: jassertfalse; break;
  482. }
  483. out << newLine << "Project(\"" << createGUID (project.getProjectName().toString() + "sln_guid") << "\") = \"" << project.getProjectName().toString() << "\", \""
  484. << getVCProjFile().getFileName() << "\", \"" << projectGUID << '"' << newLine
  485. << "EndProject" << newLine
  486. << "Global" << newLine
  487. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  488. int i;
  489. for (i = 0; i < project.getNumConfigurations(); ++i)
  490. {
  491. Project::BuildConfiguration config (project.getConfiguration (i));
  492. out << "\t\t" << createConfigName (config) << " = " << createConfigName (config) << newLine;
  493. }
  494. out << "\tEndGlobalSection" << newLine
  495. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  496. for (i = 0; i < project.getNumConfigurations(); ++i)
  497. {
  498. Project::BuildConfiguration config (project.getConfiguration (i));
  499. out << "\t\t" << projectGUID << "." << createConfigName (config) << ".ActiveCfg = " << createConfigName (config) << newLine;
  500. out << "\t\t" << projectGUID << "." << createConfigName (config) << ".Build.0 = " << createConfigName (config) << newLine;
  501. }
  502. out << "\tEndGlobalSection" << newLine
  503. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  504. << "\t\tHideSolutionNode = FALSE" << newLine
  505. << "\tEndGlobalSection" << newLine
  506. << "EndGlobal" << newLine;
  507. }
  508. //==============================================================================
  509. const String createConfigNameVC6 (const Project::BuildConfiguration& config) const
  510. {
  511. return project.getProjectName().toString() + " - Win32 " + config.getName().toString();
  512. }
  513. void writeVC6Project (OutputStream& out)
  514. {
  515. const String defaultConfigName (createConfigNameVC6 (project.getConfiguration (0)));
  516. const bool isDLL = project.isAudioPlugin() || project.isBrowserPlugin();
  517. String targetType, targetCode;
  518. if (isDLL) { targetType = "\"Win32 (x86) Dynamic-Link Library\""; targetCode = "0x0102"; }
  519. else if (project.isLibrary()) { targetType = "\"Win32 (x86) Static Library\""; targetCode = "0x0104"; }
  520. else if (project.isCommandLineApp()) { targetType = "\"Win32 (x86) Console Application\""; targetCode = "0x0103"; }
  521. else { targetType = "\"Win32 (x86) Application\""; targetCode = "0x0101"; }
  522. out << "# Microsoft Developer Studio Project File - Name=\"" << project.getProjectName()
  523. << "\" - Package Owner=<4>" << newLine
  524. << "# Microsoft Developer Studio Generated Build File, Format Version 6.00" << newLine
  525. << "# ** DO NOT EDIT **" << newLine
  526. << "# TARGTYPE " << targetType << " " << targetCode << newLine
  527. << "CFG=" << defaultConfigName << newLine
  528. << "!MESSAGE This is not a valid makefile. To build this project using NMAKE," << newLine
  529. << "!MESSAGE use the Export Makefile command and run" << newLine
  530. << "!MESSAGE " << newLine
  531. << "!MESSAGE NMAKE /f \"" << project.getProjectName() << ".mak.\"" << newLine
  532. << "!MESSAGE " << newLine
  533. << "!MESSAGE You can specify a configuration when running NMAKE" << newLine
  534. << "!MESSAGE by defining the macro CFG on the command line. For example:" << newLine
  535. << "!MESSAGE " << newLine
  536. << "!MESSAGE NMAKE /f \"" << project.getProjectName() << ".mak\" CFG=\"" << defaultConfigName << '"' << newLine
  537. << "!MESSAGE " << newLine
  538. << "!MESSAGE Possible choices for configuration are:" << newLine
  539. << "!MESSAGE " << newLine;
  540. int i;
  541. for (i = 0; i < project.getNumConfigurations(); ++i)
  542. out << "!MESSAGE \"" << createConfigNameVC6 (project.getConfiguration (i)) << "\" (based on " << targetType << ")" << newLine;
  543. out << "!MESSAGE " << newLine
  544. << "# Begin Project" << newLine
  545. << "# PROP AllowPerConfigDependencies 0" << newLine
  546. << "# PROP Scc_ProjName \"\"" << newLine
  547. << "# PROP Scc_LocalPath \"\"" << newLine
  548. << "CPP=cl.exe" << newLine
  549. << "MTL=midl.exe" << newLine
  550. << "RSC=rc.exe" << newLine;
  551. String targetList;
  552. for (i = 0; i < project.getNumConfigurations(); ++i)
  553. {
  554. const Project::BuildConfiguration config (project.getConfiguration (i));
  555. const String configName (createConfigNameVC6 (config));
  556. targetList << "# Name \"" << configName << '"' << newLine;
  557. const String binariesPath (getConfigTargetPath (config));
  558. const String targetBinary (windowsStylePath (binariesPath + "/" + config.getTargetBinaryName().toString() + getTargetBinarySuffix()));
  559. const String optimisationFlag (((int) config.getOptimisationLevel().getValue() <= 1) ? "Od" : (config.getOptimisationLevel() == 2 ? "O2" : "O3"));
  560. const String defines (getPreprocessorDefs (config, " /D "));
  561. const bool isDebug = (bool) config.isDebug().getValue();
  562. const String extraDebugFlags (isDebug ? "/Gm /ZI /GZ" : "");
  563. out << (i == 0 ? "!IF" : "!ELSEIF") << " \"$(CFG)\" == \"" << configName << '"' << newLine
  564. << "# PROP BASE Use_MFC 0" << newLine
  565. << "# PROP BASE Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  566. << "# PROP BASE Output_Dir \"" << binariesPath << '"' << newLine
  567. << "# PROP BASE Intermediate_Dir \"" << getIntermediatesPath (config) << '"' << newLine
  568. << "# PROP BASE Target_Dir \"\"" << newLine
  569. << "# PROP Use_MFC 0" << newLine
  570. << "# PROP Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  571. << "# PROP Output_Dir \"" << binariesPath << '"' << newLine
  572. << "# PROP Intermediate_Dir \"" << getIntermediatesPath (config) << '"' << newLine
  573. << "# PROP Ignore_Export_Lib 0" << newLine
  574. << "# PROP Target_Dir \"\"" << newLine
  575. << "# ADD BASE CPP /nologo /W3 /GX /" << optimisationFlag << " /D " << defines
  576. << " /YX /FD /c " << extraDebugFlags << " /Zm1024" << newLine
  577. << "# ADD CPP /nologo " << (isDebug ? "/MTd" : "/MT") << " /W3 /GR /GX /" << optimisationFlag
  578. << " /I " << getHeaderSearchPaths (config).joinIntoString (" /I ")
  579. << " /D " << defines << " /D \"_UNICODE\" /D \"UNICODE\" /FD /c /Zm1024 " << extraDebugFlags
  580. << " " << getExtraCompilerFlags().toString().trim() << newLine;
  581. if (! isDebug)
  582. out << "# SUBTRACT CPP /YX" << newLine;
  583. if (! project.isLibrary())
  584. out << "# ADD BASE MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine
  585. << "# ADD MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine;
  586. out << "# ADD BASE RSC /l 0x40c /d " << defines << newLine
  587. << "# ADD RSC /l 0x40c /d " << defines << newLine
  588. << "BSC32=bscmake.exe" << newLine
  589. << "# ADD BASE BSC32 /nologo" << newLine
  590. << "# ADD BSC32 /nologo" << newLine;
  591. if (project.isLibrary())
  592. {
  593. out << "LIB32=link.exe -lib" << newLine
  594. << "# ADD BASE LIB32 /nologo" << newLine
  595. << "# ADD LIB32 /nologo /out:\"" << targetBinary << '"' << newLine;
  596. }
  597. else
  598. {
  599. out << "LINK32=link.exe" << newLine
  600. << "# 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
  601. << "# ADD LINK32 \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\LIB\\shell32.lib\" " // This is avoid debug information corruption when mixing Platform SDK
  602. << "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "
  603. << (isDebug ? " /debug" : "")
  604. << " /nologo /machine:I386 /out:\"" << targetBinary << "\" "
  605. << (isDLL ? "/dll" : (project.isCommandLineApp() ? "/subsystem:console "
  606. : "/subsystem:windows "))
  607. << getExtraLinkerFlags().toString().trim() << newLine;
  608. }
  609. }
  610. out << "!ENDIF" << newLine
  611. << "# Begin Target" << newLine
  612. << targetList;
  613. writeFilesVC6 (out, project.getMainGroup());
  614. writeGroupVC6 (out, project.getJuceCodeGroupName(), juceWrapperFiles);
  615. writeGroupVC6 (out, "Juce VST Wrapper", getVSTFilesRequired());
  616. out << "# End Target" << newLine
  617. << "# End Project" << newLine;
  618. }
  619. void writeFileVC6 (OutputStream& out, const RelativePath& file, const bool excludeFromBuild)
  620. {
  621. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  622. out << "# Begin Source File" << newLine
  623. << "SOURCE=" << file.toWindowsStyle().quoted() << newLine;
  624. if (excludeFromBuild)
  625. out << "# PROP Exclude_From_Build 1" << newLine;
  626. out << "# End Source File" << newLine;
  627. }
  628. void writeFilesVC6 (OutputStream& out, const Project::Item& projectItem)
  629. {
  630. if (projectItem.isGroup())
  631. {
  632. out << "# Begin Group \"" << projectItem.getName() << '"' << newLine
  633. << "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"" << newLine;
  634. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  635. writeFilesVC6 (out, projectItem.getChild (i));
  636. out << "# End Group" << newLine;
  637. }
  638. else if (projectItem.shouldBeAddedToTargetProject())
  639. {
  640. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  641. writeFileVC6 (out, path, projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()));
  642. }
  643. }
  644. void writeGroupVC6 (OutputStream& out, const String& groupName, const Array<RelativePath>& files)
  645. {
  646. if (files.size() > 0)
  647. {
  648. out << "# Begin Group \"" << groupName << '"' << newLine;
  649. for (int i = 0; i < files.size(); ++i)
  650. if (files.getReference(i).hasFileExtension ("cpp;c;h"))
  651. writeFileVC6 (out, files.getReference(i), false);
  652. out << "# End Group" << newLine;
  653. }
  654. }
  655. void writeDSWFile (OutputStream& out)
  656. {
  657. out << "Microsoft Developer Studio Workspace File, Format Version 6.00 " << newLine;
  658. if (! project.isUsingWrapperFiles())
  659. {
  660. out << "Project: \"JUCE\"= ..\\JUCE.dsp - Package Owner=<4>" << newLine
  661. << "Package=<5>" << newLine
  662. << "{{{" << newLine
  663. << "}}}" << newLine
  664. << "Package=<4>" << newLine
  665. << "{{{" << newLine
  666. << "}}}" << newLine;
  667. }
  668. out << "Project: \"" << project.getProjectName() << "\" = .\\" << getDSPFile().getFileName() << " - Package Owner=<4>" << newLine
  669. << "Package=<5>" << newLine
  670. << "{{{" << newLine
  671. << "}}}" << newLine
  672. << "Package=<4>" << newLine
  673. << "{{{" << newLine;
  674. if (! project.isUsingWrapperFiles())
  675. {
  676. out << " Begin Project Dependency" << newLine
  677. << " Project_Dep_Name JUCE" << newLine
  678. << " End Project Dependency" << newLine;
  679. }
  680. out << "}}}" << newLine
  681. << "Global:" << newLine
  682. << "Package=<5>" << newLine
  683. << "{{{" << newLine
  684. << "}}}" << newLine
  685. << "Package=<3>" << newLine
  686. << "{{{" << newLine
  687. << "}}}" << newLine;
  688. }
  689. MSVCProjectExporter (const MSVCProjectExporter&);
  690. MSVCProjectExporter& operator= (const MSVCProjectExporter&);
  691. };
  692. #endif // __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__