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.

891 lines
42KB

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