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.

890 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. const String getOSTestMacro() { return "(defined (_WIN32) || defined (_WIN64))"; }
  91. void launchProject()
  92. {
  93. getSLNFile().startAsProcess();
  94. }
  95. void createPropertyEditors (Array <PropertyComponent*>& props)
  96. {
  97. ProjectExporter::createPropertyEditors (props);
  98. if (project.isLibrary())
  99. {
  100. static const char* const libTypes[] = { "Static Library (.lib)", "Dynamic Library (.dll)", 0 };
  101. props.add (new ChoicePropertyComponent (getLibraryType(), "Library Type", StringArray (libTypes)));
  102. props.add (new TextPropertyComponent (getSetting ("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 ("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 (! FileUtils::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 (! FileUtils::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 (! FileUtils::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 (! FileUtils::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 ("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 ("WIN32");
  288. defines.add ("_WINDOWS");
  289. defines.add (config.isDebug().getValue() ? "_DEBUG" : "NDEBUG");
  290. if (project.isCommandLineApp())
  291. defines.add ("_CONSOLE");
  292. if (project.isLibrary())
  293. defines.add ("_LIB");
  294. if (isRTAS())
  295. {
  296. RelativePath rtasFolder (getRTASFolder().toString(), RelativePath::unknown);
  297. defines.add ("JucePlugin_WinBag_path="
  298. + CodeFormatting::addEscapeChars (rtasFolder.getChildFile ("WinBag")
  299. .toWindowsStyle().quoted()));
  300. }
  301. defines.addArray (config.parsePreprocessorDefs());
  302. defines.addArray (parsePreprocessorDefs());
  303. return defines.joinIntoString (joinString);
  304. }
  305. const StringArray getHeaderSearchPaths (const Project::BuildConfiguration& config) const
  306. {
  307. StringArray searchPaths (config.getHeaderSearchPaths());
  308. if (project.shouldAddVSTFolderToPath() && getVSTFolder().toString().isNotEmpty())
  309. searchPaths.add (RelativePath (getVSTFolder().toString(), RelativePath::projectFolder)
  310. .rebased (project.getFile().getParentDirectory(), getTargetFolder(), RelativePath::buildTargetFolder)
  311. .toWindowsStyle());
  312. if (project.isAudioPlugin())
  313. searchPaths.add (juceWrapperFiles[0].getParentDirectory().toWindowsStyle());
  314. if (isRTAS())
  315. {
  316. static const char* rtasIncludePaths[] = { "AlturaPorts/TDMPlugins/PluginLibrary/EffectClasses",
  317. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses",
  318. "AlturaPorts/TDMPlugins/PluginLibrary/ProcessClasses/Interfaces",
  319. "AlturaPorts/TDMPlugins/PluginLibrary/Utilities",
  320. "AlturaPorts/TDMPlugins/PluginLibrary/RTASP_Adapt",
  321. "AlturaPorts/TDMPlugins/PluginLibrary/CoreClasses",
  322. "AlturaPorts/TDMPlugins/PluginLibrary/Controls",
  323. "AlturaPorts/TDMPlugins/PluginLibrary/Meters",
  324. "AlturaPorts/TDMPlugins/PluginLibrary/ViewClasses",
  325. "AlturaPorts/TDMPlugins/PluginLibrary/DSPClasses",
  326. "AlturaPorts/TDMPlugins/PluginLibrary/Interfaces",
  327. "AlturaPorts/TDMPlugins/common",
  328. "AlturaPorts/TDMPlugins/common/Platform",
  329. "AlturaPorts/TDMPlugins/SignalProcessing/Public",
  330. "AlturaPorts/TDMPlugIns/DSPManager/Interfaces",
  331. "AlturaPorts/SADriver/Interfaces",
  332. "AlturaPorts/DigiPublic/Interfaces",
  333. "AlturaPorts/Fic/Interfaces/DAEClient",
  334. "AlturaPorts/NewFileLibs/Cmn",
  335. "AlturaPorts/NewFileLibs/DOA",
  336. "AlturaPorts/AlturaSource/PPC_H",
  337. "AlturaPorts/AlturaSource/AppSupport",
  338. "AvidCode/AVX2sdk/AVX/avx2/avx2sdk/inc",
  339. "xplat/AVX/avx2/avx2sdk/inc" };
  340. RelativePath sdkFolder (getRTASFolder().toString(), RelativePath::projectFolder);
  341. sdkFolder = sdkFolder.rebased (project.getFile().getParentDirectory(), getTargetFolder(), RelativePath::buildTargetFolder);
  342. for (int i = 0; i < numElementsInArray (rtasIncludePaths); ++i)
  343. searchPaths.add (sdkFolder.getChildFile (rtasIncludePaths[i]).toWindowsStyle());
  344. }
  345. return searchPaths;
  346. }
  347. XmlElement* createToolElement (XmlElement& parent, const String& toolName) const
  348. {
  349. XmlElement* const e = parent.createNewChildElement ("Tool");
  350. e->setAttribute ("Name", toolName);
  351. return e;
  352. }
  353. const String getBinaryFileForConfig (const Project::BuildConfiguration& config) const
  354. {
  355. const String targetBinary (getSetting (config.isDebug().getValue() ? "libraryName_Debug" : "libraryName_Release").toString().trim());
  356. if (targetBinary.isNotEmpty())
  357. return targetBinary;
  358. return config.getTargetBinaryName().toString() + getTargetBinarySuffix();
  359. }
  360. void createConfig (XmlElement& xml, const Project::BuildConfiguration& config) const
  361. {
  362. String binariesPath (getConfigTargetPath (config));
  363. String intermediatesPath (getIntermediatesPath (config));
  364. const bool isDebug = (bool) config.isDebug().getValue();
  365. const String binaryName (File::createLegalFileName (config.getTargetBinaryName().toString()));
  366. xml.setAttribute ("Name", createConfigName (config));
  367. xml.setAttribute ("OutputDirectory", FileUtils::windowsStylePath (binariesPath));
  368. xml.setAttribute ("IntermediateDirectory", FileUtils::windowsStylePath (intermediatesPath));
  369. xml.setAttribute ("ConfigurationType", (project.isAudioPlugin() || project.isBrowserPlugin() || isLibraryDLL())
  370. ? "2" : (project.isLibrary() ? "4" : "1"));
  371. xml.setAttribute ("UseOfMFC", "0");
  372. xml.setAttribute ("ATLMinimizesCRunTimeLibraryUsage", "false");
  373. xml.setAttribute ("CharacterSet", "2");
  374. if (! isDebug)
  375. xml.setAttribute ("WholeProgramOptimization", "1");
  376. createToolElement (xml, "VCPreBuildEventTool");
  377. XmlElement* customBuild = createToolElement (xml, "VCCustomBuildTool");
  378. if (isRTAS())
  379. {
  380. RelativePath rsrFile (getJucePathFromTargetFolder().getChildFile ("extras/audio plugins/wrapper/RTAS/juce_RTAS_WinResources.rsr"));
  381. customBuild->setAttribute ("CommandLine", "copy /Y \"" + rsrFile.toWindowsStyle() + "\" \"$(TargetPath)\".rsr");
  382. customBuild->setAttribute ("Outputs", "\"$(TargetPath)\".rsr");
  383. }
  384. createToolElement (xml, "VCXMLDataGeneratorTool");
  385. createToolElement (xml, "VCWebServiceProxyGeneratorTool");
  386. if (! project.isLibrary())
  387. {
  388. XmlElement* midl = createToolElement (xml, "VCMIDLTool");
  389. midl->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  390. midl->setAttribute ("MkTypLibCompatible", "true");
  391. midl->setAttribute ("SuppressStartupBanner", "true");
  392. midl->setAttribute ("TargetEnvironment", "1");
  393. midl->setAttribute ("TypeLibraryName", FileUtils::windowsStylePath (intermediatesPath + "/" + binaryName + ".tlb"));
  394. midl->setAttribute ("HeaderFileName", "");
  395. }
  396. {
  397. XmlElement* compiler = createToolElement (xml, "VCCLCompilerTool");
  398. const int optimiseLevel = (int) config.getOptimisationLevel().getValue();
  399. compiler->setAttribute ("Optimization", optimiseLevel <= 1 ? "0" : (optimiseLevel == 2 ? "2" : "3"));
  400. if (isDebug)
  401. {
  402. compiler->setAttribute ("BufferSecurityCheck", "");
  403. compiler->setAttribute ("DebugInformationFormat", project.isLibrary() ? "3" : "4");
  404. }
  405. else
  406. {
  407. compiler->setAttribute ("InlineFunctionExpansion", "1");
  408. compiler->setAttribute ("StringPooling", "true");
  409. }
  410. compiler->setAttribute ("AdditionalIncludeDirectories", getHeaderSearchPaths (config).joinIntoString (";"));
  411. compiler->setAttribute ("PreprocessorDefinitions", getPreprocessorDefs (config, ";"));
  412. compiler->setAttribute ("RuntimeLibrary", isRTAS() ? (isDebug ? 3 : 2) // MT DLL
  413. : (isDebug ? 1 : 0)); // MT static
  414. compiler->setAttribute ("RuntimeTypeInfo", "true");
  415. compiler->setAttribute ("UsePrecompiledHeader", "0");
  416. compiler->setAttribute ("PrecompiledHeaderFile", FileUtils::windowsStylePath (intermediatesPath + "/" + binaryName + ".pch"));
  417. compiler->setAttribute ("AssemblerListingLocation", FileUtils::windowsStylePath (intermediatesPath + "/"));
  418. compiler->setAttribute ("ObjectFile", FileUtils::windowsStylePath (intermediatesPath + "/"));
  419. compiler->setAttribute ("ProgramDataBaseFileName", FileUtils::windowsStylePath (intermediatesPath + "/"));
  420. compiler->setAttribute ("WarningLevel", project.isLibrary() ? "4" : "3");
  421. compiler->setAttribute ("SuppressStartupBanner", "true");
  422. if (getExtraCompilerFlags().toString().isNotEmpty())
  423. compiler->setAttribute ("AdditionalOptions", getExtraCompilerFlags().toString().trim());
  424. }
  425. createToolElement (xml, "VCManagedResourceCompilerTool");
  426. {
  427. XmlElement* resCompiler = createToolElement (xml, "VCResourceCompilerTool");
  428. resCompiler->setAttribute ("PreprocessorDefinitions", isDebug ? "_DEBUG" : "NDEBUG");
  429. }
  430. createToolElement (xml, "VCPreLinkEventTool");
  431. const String outputFileName (getBinaryFileForConfig (config));
  432. if (! project.isLibrary())
  433. {
  434. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  435. linker->setAttribute ("OutputFile", FileUtils::windowsStylePath (binariesPath + "/" + outputFileName));
  436. linker->setAttribute ("SuppressStartupBanner", "true");
  437. if (project.getJuceLinkageMode() == Project::useLinkedJuce)
  438. linker->setAttribute ("AdditionalLibraryDirectories", getJucePathFromTargetFolder().getChildFile ("bin").toWindowsStyle());
  439. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  440. linker->setAttribute ("GenerateDebugInformation", isDebug ? "true" : "false");
  441. linker->setAttribute ("ProgramDatabaseFile", FileUtils::windowsStylePath (intermediatesPath + "/" + binaryName + ".pdb"));
  442. linker->setAttribute ("SubSystem", project.isCommandLineApp() ? "1" : "2");
  443. if (! isDebug)
  444. {
  445. linker->setAttribute ("GenerateManifest", "false");
  446. linker->setAttribute ("OptimizeReferences", "2");
  447. linker->setAttribute ("EnableCOMDATFolding", "2");
  448. }
  449. linker->setAttribute ("TargetMachine", "1"); // (64-bit build = 5)
  450. String extraLinkerOptions (getExtraLinkerFlags().toString());
  451. if (isRTAS())
  452. {
  453. extraLinkerOptions += " /FORCE:multiple";
  454. linker->setAttribute ("DelayLoadDLLs", "DAE.dll; DigiExt.dll; DSI.dll; PluginLib.dll; DSPManager.dll");
  455. linker->setAttribute ("ModuleDefinitionFile", getJucePathFromTargetFolder()
  456. .getChildFile ("extras/audio plugins/wrapper/RTAS/juce_RTAS_WinExports.def")
  457. .toWindowsStyle());
  458. }
  459. if (extraLinkerOptions.isNotEmpty())
  460. linker->setAttribute ("AdditionalOptions", extraLinkerOptions.trim());
  461. }
  462. else
  463. {
  464. if (isLibraryDLL())
  465. {
  466. XmlElement* linker = createToolElement (xml, "VCLinkerTool");
  467. String extraLinkerOptions (getExtraLinkerFlags().toString());
  468. extraLinkerOptions << " /IMPLIB:" << FileUtils::windowsStylePath (binariesPath + "/" + outputFileName.upToLastOccurrenceOf (".", false, false) + ".lib");
  469. linker->setAttribute ("AdditionalOptions", extraLinkerOptions.trim());
  470. linker->setAttribute ("OutputFile", FileUtils::windowsStylePath (binariesPath + "/" + outputFileName));
  471. linker->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  472. }
  473. else
  474. {
  475. XmlElement* librarian = createToolElement (xml, "VCLibrarianTool");
  476. librarian->setAttribute ("OutputFile", FileUtils::windowsStylePath (binariesPath + "/" + outputFileName));
  477. librarian->setAttribute ("IgnoreDefaultLibraryNames", isDebug ? "libcmt.lib, msvcrt.lib" : "");
  478. }
  479. }
  480. createToolElement (xml, "VCALinkTool");
  481. createToolElement (xml, "VCManifestTool");
  482. createToolElement (xml, "VCXDCMakeTool");
  483. {
  484. XmlElement* bscMake = createToolElement (xml, "VCBscMakeTool");
  485. bscMake->setAttribute ("SuppressStartupBanner", "true");
  486. bscMake->setAttribute ("OutputFile", FileUtils::windowsStylePath (intermediatesPath + "/" + binaryName + ".bsc"));
  487. }
  488. createToolElement (xml, "VCFxCopTool");
  489. if (! project.isLibrary())
  490. createToolElement (xml, "VCAppVerifierTool");
  491. createToolElement (xml, "VCPostBuildEventTool");
  492. }
  493. void createConfigs (XmlElement& configs)
  494. {
  495. for (int i = 0; i < project.getNumConfigurations(); ++i)
  496. {
  497. Project::BuildConfiguration config (project.getConfiguration (i));
  498. createConfig (*configs.createNewChildElement ("Configuration"), config);
  499. }
  500. }
  501. const String createConfigName (const Project::BuildConfiguration& config) const
  502. {
  503. return config.getName().toString() + "|Win32";
  504. }
  505. //==============================================================================
  506. void writeSolutionFile (OutputStream& out)
  507. {
  508. out << newLine << "Microsoft Visual Studio Solution File, Format Version ";
  509. switch (version)
  510. {
  511. case visualStudio2005: out << "8.00" << newLine << "# Visual C++ Express 2005"; break;
  512. case visualStudio2008: out << "10.00" << newLine << "# Visual C++ Express 2008"; break;
  513. default: jassertfalse; break;
  514. }
  515. out << newLine << "Project(\"" << createGUID (project.getProjectName().toString() + "sln_guid") << "\") = \"" << project.getProjectName().toString() << "\", \""
  516. << getVCProjFile().getFileName() << "\", \"" << projectGUID << '"' << newLine
  517. << "EndProject" << newLine
  518. << "Global" << newLine
  519. << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" << newLine;
  520. int i;
  521. for (i = 0; i < project.getNumConfigurations(); ++i)
  522. {
  523. Project::BuildConfiguration config (project.getConfiguration (i));
  524. out << "\t\t" << createConfigName (config) << " = " << createConfigName (config) << newLine;
  525. }
  526. out << "\tEndGlobalSection" << newLine
  527. << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" << newLine;
  528. for (i = 0; i < project.getNumConfigurations(); ++i)
  529. {
  530. Project::BuildConfiguration config (project.getConfiguration (i));
  531. out << "\t\t" << projectGUID << "." << createConfigName (config) << ".ActiveCfg = " << createConfigName (config) << newLine;
  532. out << "\t\t" << projectGUID << "." << createConfigName (config) << ".Build.0 = " << createConfigName (config) << newLine;
  533. }
  534. out << "\tEndGlobalSection" << newLine
  535. << "\tGlobalSection(SolutionProperties) = preSolution" << newLine
  536. << "\t\tHideSolutionNode = FALSE" << newLine
  537. << "\tEndGlobalSection" << newLine
  538. << "EndGlobal" << newLine;
  539. }
  540. //==============================================================================
  541. const String createConfigNameVC6 (const Project::BuildConfiguration& config) const
  542. {
  543. return project.getProjectName().toString() + " - Win32 " + config.getName().toString();
  544. }
  545. void writeVC6Project (OutputStream& out)
  546. {
  547. const String defaultConfigName (createConfigNameVC6 (project.getConfiguration (0)));
  548. const bool isDLL = project.isAudioPlugin() || project.isBrowserPlugin();
  549. String targetType, targetCode;
  550. if (isDLL) { targetType = "\"Win32 (x86) Dynamic-Link Library\""; targetCode = "0x0102"; }
  551. else if (project.isLibrary()) { targetType = "\"Win32 (x86) Static Library\""; targetCode = "0x0104"; }
  552. else if (project.isCommandLineApp()) { targetType = "\"Win32 (x86) Console Application\""; targetCode = "0x0103"; }
  553. else { targetType = "\"Win32 (x86) Application\""; targetCode = "0x0101"; }
  554. out << "# Microsoft Developer Studio Project File - Name=\"" << project.getProjectName()
  555. << "\" - Package Owner=<4>" << newLine
  556. << "# Microsoft Developer Studio Generated Build File, Format Version 6.00" << newLine
  557. << "# ** DO NOT EDIT **" << newLine
  558. << "# TARGTYPE " << targetType << " " << targetCode << newLine
  559. << "CFG=" << defaultConfigName << newLine
  560. << "!MESSAGE This is not a valid makefile. To build this project using NMAKE," << newLine
  561. << "!MESSAGE use the Export Makefile command and run" << newLine
  562. << "!MESSAGE " << newLine
  563. << "!MESSAGE NMAKE /f \"" << project.getProjectName() << ".mak.\"" << newLine
  564. << "!MESSAGE " << newLine
  565. << "!MESSAGE You can specify a configuration when running NMAKE" << newLine
  566. << "!MESSAGE by defining the macro CFG on the command line. For example:" << newLine
  567. << "!MESSAGE " << newLine
  568. << "!MESSAGE NMAKE /f \"" << project.getProjectName() << ".mak\" CFG=\"" << defaultConfigName << '"' << newLine
  569. << "!MESSAGE " << newLine
  570. << "!MESSAGE Possible choices for configuration are:" << newLine
  571. << "!MESSAGE " << newLine;
  572. int i;
  573. for (i = 0; i < project.getNumConfigurations(); ++i)
  574. out << "!MESSAGE \"" << createConfigNameVC6 (project.getConfiguration (i)) << "\" (based on " << targetType << ")" << newLine;
  575. out << "!MESSAGE " << newLine
  576. << "# Begin Project" << newLine
  577. << "# PROP AllowPerConfigDependencies 0" << newLine
  578. << "# PROP Scc_ProjName \"\"" << newLine
  579. << "# PROP Scc_LocalPath \"\"" << newLine
  580. << "CPP=cl.exe" << newLine
  581. << "MTL=midl.exe" << newLine
  582. << "RSC=rc.exe" << newLine;
  583. String targetList;
  584. for (i = 0; i < project.getNumConfigurations(); ++i)
  585. {
  586. const Project::BuildConfiguration config (project.getConfiguration (i));
  587. const String configName (createConfigNameVC6 (config));
  588. targetList << "# Name \"" << configName << '"' << newLine;
  589. const String binariesPath (getConfigTargetPath (config));
  590. const String targetBinary (FileUtils::windowsStylePath (binariesPath + "/" + getBinaryFileForConfig (config)));
  591. const String optimisationFlag (((int) config.getOptimisationLevel().getValue() <= 1) ? "Od" : (config.getOptimisationLevel() == 2 ? "O2" : "O3"));
  592. const String defines (getPreprocessorDefs (config, " /D "));
  593. const bool isDebug = (bool) config.isDebug().getValue();
  594. const String extraDebugFlags (isDebug ? "/Gm /ZI /GZ" : "");
  595. out << (i == 0 ? "!IF" : "!ELSEIF") << " \"$(CFG)\" == \"" << configName << '"' << newLine
  596. << "# PROP BASE Use_MFC 0" << newLine
  597. << "# PROP BASE Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  598. << "# PROP BASE Output_Dir \"" << binariesPath << '"' << newLine
  599. << "# PROP BASE Intermediate_Dir \"" << getIntermediatesPath (config) << '"' << newLine
  600. << "# PROP BASE Target_Dir \"\"" << newLine
  601. << "# PROP Use_MFC 0" << newLine
  602. << "# PROP Use_Debug_Libraries " << (isDebug ? "1" : "0") << newLine
  603. << "# PROP Output_Dir \"" << binariesPath << '"' << newLine
  604. << "# PROP Intermediate_Dir \"" << getIntermediatesPath (config) << '"' << newLine
  605. << "# PROP Ignore_Export_Lib 0" << newLine
  606. << "# PROP Target_Dir \"\"" << newLine
  607. << "# ADD BASE CPP /nologo /W3 /GX /" << optimisationFlag << " /D " << defines
  608. << " /YX /FD /c " << extraDebugFlags << " /Zm1024" << newLine
  609. << "# ADD CPP /nologo " << (isDebug ? "/MTd" : "/MT") << " /W3 /GR /GX /" << optimisationFlag
  610. << " /I " << getHeaderSearchPaths (config).joinIntoString (" /I ")
  611. << " /D " << defines << " /D \"_UNICODE\" /D \"UNICODE\" /FD /c /Zm1024 " << extraDebugFlags
  612. << " " << getExtraCompilerFlags().toString().trim() << newLine;
  613. if (! isDebug)
  614. out << "# SUBTRACT CPP /YX" << newLine;
  615. if (! project.isLibrary())
  616. out << "# ADD BASE MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine
  617. << "# ADD MTL /nologo /D " << defines << " /mktyplib203 /win32" << newLine;
  618. out << "# ADD BASE RSC /l 0x40c /d " << defines << newLine
  619. << "# ADD RSC /l 0x40c /d " << defines << newLine
  620. << "BSC32=bscmake.exe" << newLine
  621. << "# ADD BASE BSC32 /nologo" << newLine
  622. << "# ADD BSC32 /nologo" << newLine;
  623. if (project.isLibrary())
  624. {
  625. out << "LIB32=link.exe -lib" << newLine
  626. << "# ADD BASE LIB32 /nologo" << newLine
  627. << "# ADD LIB32 /nologo /out:\"" << targetBinary << '"' << newLine;
  628. }
  629. else
  630. {
  631. out << "LINK32=link.exe" << newLine
  632. << "# 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
  633. << "# ADD LINK32 \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\LIB\\shell32.lib\" " // This is avoid debug information corruption when mixing Platform SDK
  634. << "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "
  635. << (isDebug ? " /debug" : "")
  636. << " /nologo /machine:I386 /out:\"" << targetBinary << "\" "
  637. << (isDLL ? "/dll" : (project.isCommandLineApp() ? "/subsystem:console "
  638. : "/subsystem:windows "))
  639. << getExtraLinkerFlags().toString().trim() << newLine;
  640. }
  641. }
  642. out << "!ENDIF" << newLine
  643. << "# Begin Target" << newLine
  644. << targetList;
  645. writeFilesVC6 (out, project.getMainGroup());
  646. writeGroupVC6 (out, project.getJuceCodeGroupName(), juceWrapperFiles);
  647. writeGroupVC6 (out, "Juce VST Wrapper", getVSTFilesRequired());
  648. out << "# End Target" << newLine
  649. << "# End Project" << newLine;
  650. }
  651. void writeFileVC6 (OutputStream& out, const RelativePath& file, const bool excludeFromBuild)
  652. {
  653. jassert (file.getRoot() == RelativePath::buildTargetFolder);
  654. out << "# Begin Source File" << newLine
  655. << "SOURCE=" << file.toWindowsStyle().quoted() << newLine;
  656. if (excludeFromBuild)
  657. out << "# PROP Exclude_From_Build 1" << newLine;
  658. out << "# End Source File" << newLine;
  659. }
  660. void writeFilesVC6 (OutputStream& out, const Project::Item& projectItem)
  661. {
  662. if (projectItem.isGroup())
  663. {
  664. out << "# Begin Group \"" << projectItem.getName() << '"' << newLine
  665. << "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"" << newLine;
  666. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  667. writeFilesVC6 (out, projectItem.getChild (i));
  668. out << "# End Group" << newLine;
  669. }
  670. else if (projectItem.shouldBeAddedToTargetProject())
  671. {
  672. const RelativePath path (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  673. writeFileVC6 (out, path, projectItem.shouldBeAddedToBinaryResources() || (shouldFileBeCompiledByDefault (path) && ! projectItem.shouldBeCompiled()));
  674. }
  675. }
  676. void writeGroupVC6 (OutputStream& out, const String& groupName, const Array<RelativePath>& files)
  677. {
  678. if (files.size() > 0)
  679. {
  680. out << "# Begin Group \"" << groupName << '"' << newLine;
  681. for (int i = 0; i < files.size(); ++i)
  682. if (files.getReference(i).hasFileExtension ("cpp;c;h"))
  683. writeFileVC6 (out, files.getReference(i), false);
  684. out << "# End Group" << newLine;
  685. }
  686. }
  687. void writeDSWFile (OutputStream& out)
  688. {
  689. out << "Microsoft Developer Studio Workspace File, Format Version 6.00 " << newLine;
  690. if (! project.isUsingWrapperFiles())
  691. {
  692. out << "Project: \"JUCE\"= ..\\JUCE.dsp - Package Owner=<4>" << newLine
  693. << "Package=<5>" << newLine
  694. << "{{{" << newLine
  695. << "}}}" << newLine
  696. << "Package=<4>" << newLine
  697. << "{{{" << newLine
  698. << "}}}" << newLine;
  699. }
  700. out << "Project: \"" << project.getProjectName() << "\" = .\\" << getDSPFile().getFileName() << " - Package Owner=<4>" << newLine
  701. << "Package=<5>" << newLine
  702. << "{{{" << newLine
  703. << "}}}" << newLine
  704. << "Package=<4>" << newLine
  705. << "{{{" << newLine;
  706. if (! project.isUsingWrapperFiles())
  707. {
  708. out << " Begin Project Dependency" << newLine
  709. << " Project_Dep_Name JUCE" << newLine
  710. << " End Project Dependency" << newLine;
  711. }
  712. out << "}}}" << newLine
  713. << "Global:" << newLine
  714. << "Package=<5>" << newLine
  715. << "{{{" << newLine
  716. << "}}}" << newLine
  717. << "Package=<3>" << newLine
  718. << "{{{" << newLine
  719. << "}}}" << newLine;
  720. }
  721. MSVCProjectExporter (const MSVCProjectExporter&);
  722. MSVCProjectExporter& operator= (const MSVCProjectExporter&);
  723. };
  724. #endif // __JUCER_PROJECTEXPORT_MSVC_JUCEHEADER__