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.

882 lines
35KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../jucer_Headers.h"
  18. #include "jucer_ProjectExporter.h"
  19. #include "jucer_ProjectSaver.h"
  20. #include "jucer_ProjectExport_Make.h"
  21. #include "jucer_ProjectExport_MSVC.h"
  22. #include "jucer_ProjectExport_XCode.h"
  23. #include "jucer_ProjectExport_Android.h"
  24. #include "jucer_ProjectExport_CodeBlocks.h"
  25. //==============================================================================
  26. static void addType (Array<ProjectExporter::ExporterTypeInfo>& list,
  27. const char* name, const void* iconData, int iconDataSize)
  28. {
  29. ProjectExporter::ExporterTypeInfo type = { name, iconData, iconDataSize };
  30. list.add (type);
  31. }
  32. Array<ProjectExporter::ExporterTypeInfo> ProjectExporter::getExporterTypes()
  33. {
  34. Array<ProjectExporter::ExporterTypeInfo> types;
  35. addType (types, XCodeProjectExporter::getNameMac(), BinaryData::projectIconXcode_png, BinaryData::projectIconXcode_pngSize);
  36. addType (types, XCodeProjectExporter::getNameiOS(), BinaryData::projectIconXcodeIOS_png, BinaryData::projectIconXcodeIOS_pngSize);
  37. addType (types, MSVCProjectExporterVC2015::getName(), BinaryData::projectIconVisualStudio_png, BinaryData::projectIconVisualStudio_pngSize);
  38. addType (types, MSVCProjectExporterVC2013::getName(), BinaryData::projectIconVisualStudio_png, BinaryData::projectIconVisualStudio_pngSize);
  39. addType (types, MSVCProjectExporterVC2012::getName(), BinaryData::projectIconVisualStudio_png, BinaryData::projectIconVisualStudio_pngSize);
  40. addType (types, MSVCProjectExporterVC2010::getName(), BinaryData::projectIconVisualStudio_png, BinaryData::projectIconVisualStudio_pngSize);
  41. addType (types, MakefileProjectExporter::getNameLinux(), BinaryData::projectIconLinuxMakefile_png, BinaryData::projectIconLinuxMakefile_pngSize);
  42. addType (types, AndroidProjectExporter::getName(), BinaryData::projectIconAndroid_png, BinaryData::projectIconAndroid_pngSize);
  43. addType (types, CodeBlocksProjectExporter::getNameWindows(), BinaryData::projectIconCodeblocks_png, BinaryData::projectIconCodeblocks_pngSize);
  44. addType (types, CodeBlocksProjectExporter::getNameLinux(), BinaryData::projectIconCodeblocks_png, BinaryData::projectIconCodeblocks_pngSize);
  45. return types;
  46. }
  47. ProjectExporter* ProjectExporter::createNewExporter (Project& project, const int index)
  48. {
  49. ProjectExporter* exp = nullptr;
  50. switch (index)
  51. {
  52. case 0: exp = new XCodeProjectExporter (project, ValueTree (XCodeProjectExporter ::getValueTreeTypeName (false)), false); break;
  53. case 1: exp = new XCodeProjectExporter (project, ValueTree (XCodeProjectExporter ::getValueTreeTypeName (true)), true); break;
  54. case 2: exp = new MSVCProjectExporterVC2015 (project, ValueTree (MSVCProjectExporterVC2015 ::getValueTreeTypeName())); break;
  55. case 3: exp = new MSVCProjectExporterVC2013 (project, ValueTree (MSVCProjectExporterVC2013 ::getValueTreeTypeName())); break;
  56. case 4: exp = new MSVCProjectExporterVC2012 (project, ValueTree (MSVCProjectExporterVC2012 ::getValueTreeTypeName())); break;
  57. case 5: exp = new MSVCProjectExporterVC2010 (project, ValueTree (MSVCProjectExporterVC2010 ::getValueTreeTypeName())); break;
  58. case 6: exp = new MakefileProjectExporter (project, ValueTree (MakefileProjectExporter ::getValueTreeTypeName())); break;
  59. case 7: exp = new AndroidProjectExporter (project, ValueTree (AndroidProjectExporter ::getValueTreeTypeName())); break;
  60. case 8: exp = new CodeBlocksProjectExporter (project, ValueTree (CodeBlocksProjectExporter ::getValueTreeTypeName (CodeBlocksProjectExporter::windowsTarget)), CodeBlocksProjectExporter::windowsTarget); break;
  61. case 9: exp = new CodeBlocksProjectExporter (project, ValueTree (CodeBlocksProjectExporter ::getValueTreeTypeName (CodeBlocksProjectExporter::linuxTarget)), CodeBlocksProjectExporter::linuxTarget); break;
  62. default: jassertfalse; return 0;
  63. }
  64. exp->createDefaultConfigs();
  65. exp->createDefaultModulePaths();
  66. return exp;
  67. }
  68. StringArray ProjectExporter::getExporterNames()
  69. {
  70. StringArray s;
  71. Array<ExporterTypeInfo> types (getExporterTypes());
  72. for (int i = 0; i < types.size(); ++i)
  73. s.add (types.getReference(i).name);
  74. return s;
  75. }
  76. String ProjectExporter::getCurrentPlatformExporterName()
  77. {
  78. #if JUCE_MAC
  79. return XCodeProjectExporter::getNameMac();
  80. #elif JUCE_WINDOWS
  81. return MSVCProjectExporterVC2015::getName();
  82. #elif JUCE_LINUX
  83. return MakefileProjectExporter::getNameLinux();
  84. #else
  85. #error // huh?
  86. #endif
  87. }
  88. ProjectExporter* ProjectExporter::createNewExporter (Project& project, const String& name)
  89. {
  90. return createNewExporter (project, getExporterNames().indexOf (name));
  91. }
  92. ProjectExporter* ProjectExporter::createExporter (Project& project, const ValueTree& settings)
  93. {
  94. ProjectExporter* exp = MSVCProjectExporterVC2010 ::createForSettings (project, settings);
  95. if (exp == nullptr) exp = MSVCProjectExporterVC2012 ::createForSettings (project, settings);
  96. if (exp == nullptr) exp = MSVCProjectExporterVC2013 ::createForSettings (project, settings);
  97. if (exp == nullptr) exp = MSVCProjectExporterVC2015 ::createForSettings (project, settings);
  98. if (exp == nullptr) exp = XCodeProjectExporter ::createForSettings (project, settings);
  99. if (exp == nullptr) exp = MakefileProjectExporter ::createForSettings (project, settings);
  100. if (exp == nullptr) exp = AndroidProjectExporter ::createForSettings (project, settings);
  101. if (exp == nullptr) exp = CodeBlocksProjectExporter ::createForSettings (project, settings);
  102. jassert (exp != nullptr);
  103. return exp;
  104. }
  105. bool ProjectExporter::canProjectBeLaunched (Project* project)
  106. {
  107. if (project != nullptr)
  108. {
  109. const char* types[] =
  110. {
  111. #if JUCE_MAC
  112. XCodeProjectExporter::getValueTreeTypeName (false),
  113. XCodeProjectExporter::getValueTreeTypeName (true),
  114. #elif JUCE_WINDOWS
  115. MSVCProjectExporterVC2010::getValueTreeTypeName(),
  116. MSVCProjectExporterVC2012::getValueTreeTypeName(),
  117. MSVCProjectExporterVC2013::getValueTreeTypeName(),
  118. MSVCProjectExporterVC2015::getValueTreeTypeName(),
  119. #elif JUCE_LINUX
  120. // (this doesn't currently launch.. not really sure what it would do on linux)
  121. //MakefileProjectExporter::getValueTreeTypeName(),
  122. #endif
  123. AndroidProjectExporter::getValueTreeTypeName(),
  124. nullptr
  125. };
  126. for (const char** type = types; *type != nullptr; ++type)
  127. if (project->getExporters().getChildWithName (*type).isValid())
  128. return true;
  129. }
  130. return false;
  131. }
  132. //==============================================================================
  133. ProjectExporter::ProjectExporter (Project& p, const ValueTree& state)
  134. : settings (state),
  135. project (p),
  136. projectType (p.getProjectType()),
  137. projectName (p.getTitle()),
  138. projectFolder (p.getProjectFolder())
  139. {
  140. }
  141. ProjectExporter::~ProjectExporter()
  142. {
  143. }
  144. void ProjectExporter::updateDeprecatedProjectSettingsInteractively() {}
  145. File ProjectExporter::getTargetFolder() const
  146. {
  147. return project.resolveFilename (getTargetLocationString());
  148. }
  149. RelativePath ProjectExporter::rebaseFromProjectFolderToBuildTarget (const RelativePath& path) const
  150. {
  151. return path.rebased (project.getProjectFolder(), getTargetFolder(), RelativePath::buildTargetFolder);
  152. }
  153. bool ProjectExporter::shouldFileBeCompiledByDefault (const RelativePath& file) const
  154. {
  155. return file.hasFileExtension (cOrCppFileExtensions)
  156. || file.hasFileExtension (asmFileExtensions);
  157. }
  158. //==============================================================================
  159. void ProjectExporter::createPropertyEditors (PropertyListBuilder& props)
  160. {
  161. props.add (new TextPropertyComponent (getTargetLocationValue(), "Target Project Folder", 2048, false),
  162. "The location of the folder in which the " + name + " project will be created. "
  163. "This path can be absolute, but it's much more sensible to make it relative to the jucer project directory.");
  164. createDependencyPathProperties (props);
  165. props.add (new TextPropertyComponent (getExporterPreprocessorDefs(), "Extra Preprocessor Definitions", 32768, true),
  166. "Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, "
  167. "or new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  168. props.add (new TextPropertyComponent (getExtraCompilerFlags(), "Extra compiler flags", 8192, true),
  169. "Extra command-line flags to be passed to the compiler. This string can contain references to preprocessor definitions in the "
  170. "form ${NAME_OF_DEFINITION}, which will be replaced with their values.");
  171. props.add (new TextPropertyComponent (getExtraLinkerFlags(), "Extra linker flags", 8192, true),
  172. "Extra command-line flags to be passed to the linker. You might want to use this for adding additional libraries. "
  173. "This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, which will be replaced with their values.");
  174. props.add (new TextPropertyComponent (getExternalLibraries(), "External libraries to link", 8192, true),
  175. "Additional libraries to link (one per line). You should not add any platform specific decoration to these names. "
  176. "This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, which will be replaced with their values.");
  177. createIconProperties (props);
  178. createExporterProperties (props);
  179. props.add (new TextPropertyComponent (getUserNotes(), "Notes", 32768, true),
  180. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  181. }
  182. void ProjectExporter::createDependencyPathProperties (PropertyListBuilder& props)
  183. {
  184. if (shouldBuildTargetType (ProjectType::Target::VST3PlugIn) || project.isVST3PluginHost())
  185. {
  186. props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), getVST3PathValue(), "VST3 SDK Folder"),
  187. "If you're building a VST3 plugin or host, this must be the folder containing the VST3 SDK. This can be an absolute path, or a path relative to the Projucer project file.");
  188. }
  189. if (shouldBuildTargetType (ProjectType::Target::AAXPlugIn) && project.shouldBuildAAX())
  190. {
  191. props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), getAAXPathValue(), "AAX SDK Folder"),
  192. "If you're building an AAX plugin, this must be the folder containing the AAX SDK. This can be an absolute path, or a path relative to the Projucer project file.");
  193. }
  194. if (shouldBuildTargetType (ProjectType::Target::RTASPlugIn) && project.shouldBuildRTAS())
  195. {
  196. props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), getRTASPathValue(), "RTAS SDK Folder"),
  197. "If you're building an RTAS, this must be the folder containing the RTAS SDK. This can be an absolute path, or a path relative to the Projucer project file.");
  198. }
  199. }
  200. void ProjectExporter::createIconProperties (PropertyListBuilder& props)
  201. {
  202. OwnedArray<Project::Item> images;
  203. project.findAllImageItems (images);
  204. StringArray choices;
  205. Array<var> ids;
  206. choices.add ("<None>");
  207. ids.add (var());
  208. choices.add (String());
  209. ids.add (var());
  210. for (int i = 0; i < images.size(); ++i)
  211. {
  212. choices.add (images.getUnchecked(i)->getName());
  213. ids.add (images.getUnchecked(i)->getID());
  214. }
  215. props.add (new ChoicePropertyComponent (getSmallIconImageItemID(), "Icon (small)", choices, ids),
  216. "Sets an icon to use for the executable.");
  217. props.add (new ChoicePropertyComponent (getBigIconImageItemID(), "Icon (large)", choices, ids),
  218. "Sets an icon to use for the executable.");
  219. }
  220. //==============================================================================
  221. void ProjectExporter::addSettingsForProjectType (const ProjectType& type)
  222. {
  223. addVSTPathsIfPluginOrHost();
  224. if (type.isAudioPlugin())
  225. addCommonAudioPluginSettings();
  226. addPlatformSpecificSettingsForProjectType (type);
  227. }
  228. void ProjectExporter::addVSTPathsIfPluginOrHost()
  229. {
  230. if (shouldBuildTargetType (ProjectType::Target::VST3PlugIn) || project.isVST3PluginHost())
  231. addVST3FolderToPath();
  232. }
  233. void ProjectExporter::addCommonAudioPluginSettings()
  234. {
  235. if (isLinux()
  236. && (shouldBuildTargetType (ProjectType::Target::VSTPlugIn) || shouldBuildTargetType (ProjectType::Target::VST3PlugIn)))
  237. makefileExtraLinkerFlags.add ("-Wl,--no-undefined");
  238. if (shouldBuildTargetType (ProjectType::Target::AAXPlugIn))
  239. addAAXFoldersToPath();
  240. // Note: RTAS paths are platform-dependent, impl -> addPlatformSpecificSettingsForProjectType
  241. }
  242. void ProjectExporter::addVST3FolderToPath()
  243. {
  244. const String vst3Folder (getVST3PathValue().toString());
  245. if (vst3Folder.isNotEmpty())
  246. addToExtraSearchPaths (RelativePath (vst3Folder, RelativePath::projectFolder), 0);
  247. }
  248. void ProjectExporter::addAAXFoldersToPath()
  249. {
  250. const String aaxFolder = getAAXPathValue().toString();
  251. if (aaxFolder.isNotEmpty())
  252. {
  253. const RelativePath aaxFolderPath (getAAXPathValue().toString(), RelativePath::projectFolder);
  254. addToExtraSearchPaths (aaxFolderPath);
  255. addToExtraSearchPaths (aaxFolderPath.getChildFile ("Interfaces"));
  256. addToExtraSearchPaths (aaxFolderPath.getChildFile ("Interfaces").getChildFile ("ACF"));
  257. }
  258. }
  259. //==============================================================================
  260. StringPairArray ProjectExporter::getAllPreprocessorDefs (const BuildConfiguration& config, const ProjectType::Target::Type targetType) const
  261. {
  262. StringPairArray defs (mergePreprocessorDefs (config.getAllPreprocessorDefs(),
  263. parsePreprocessorDefs (getExporterPreprocessorDefsString())));
  264. addDefaultPreprocessorDefs (defs);
  265. addTargetSpecificPreprocessorDefs (defs, targetType);
  266. return defs;
  267. }
  268. StringPairArray ProjectExporter::getAllPreprocessorDefs() const
  269. {
  270. StringPairArray defs (mergePreprocessorDefs (project.getPreprocessorDefs(),
  271. parsePreprocessorDefs (getExporterPreprocessorDefsString())));
  272. addDefaultPreprocessorDefs (defs);
  273. return defs;
  274. }
  275. void ProjectExporter::addTargetSpecificPreprocessorDefs (StringPairArray& defs, const ProjectType::Target::Type targetType) const
  276. {
  277. std::pair<String, ProjectType::Target::Type> targetFlags[] = {
  278. {"JucePlugin_Build_VST", ProjectType::Target::VSTPlugIn},
  279. {"JucePlugin_Build_VST3", ProjectType::Target::VST3PlugIn},
  280. {"JucePlugin_Build_AU", ProjectType::Target::AudioUnitPlugIn},
  281. {"JucePlugin_Build_AUv3", ProjectType::Target::AudioUnitv3PlugIn},
  282. {"JucePlugin_Build_RTAS", ProjectType::Target::RTASPlugIn},
  283. {"JucePlugin_Build_AAX", ProjectType::Target::AAXPlugIn},
  284. {"JucePlugin_Build_Standalone", ProjectType::Target::StandalonePlugIn}
  285. };
  286. if (targetType == ProjectType::Target::SharedCodeTarget)
  287. {
  288. for (auto& flag : targetFlags)
  289. defs.set (flag.first, (shouldBuildTargetType (flag.second) ? "1" : "0"));
  290. defs.set ("JUCE_SHARED_CODE", "1");
  291. }
  292. else if (targetType != ProjectType::Target::unspecified)
  293. {
  294. for (auto& flag : targetFlags)
  295. defs.set (flag.first, (targetType == flag.second ? "1" : "0"));
  296. }
  297. }
  298. void ProjectExporter::addDefaultPreprocessorDefs (StringPairArray& defs) const
  299. {
  300. defs.set (getExporterIdentifierMacro(), "1");
  301. defs.set ("JUCE_APP_VERSION", project.getVersionString());
  302. defs.set ("JUCE_APP_VERSION_HEX", project.getVersionAsHex());
  303. }
  304. String ProjectExporter::replacePreprocessorTokens (const ProjectExporter::BuildConfiguration& config,
  305. const String& sourceString) const
  306. {
  307. return replacePreprocessorDefs (getAllPreprocessorDefs (config, ProjectType::Target::unspecified), sourceString);
  308. }
  309. void ProjectExporter::copyMainGroupFromProject()
  310. {
  311. jassert (itemGroups.size() == 0);
  312. itemGroups.add (project.getMainGroup().createCopy());
  313. }
  314. Project::Item& ProjectExporter::getModulesGroup()
  315. {
  316. if (modulesGroup == nullptr)
  317. {
  318. jassert (itemGroups.size() > 0); // must call copyMainGroupFromProject before this.
  319. itemGroups.add (Project::Item::createGroup (project, "Juce Modules", "__modulesgroup__", true));
  320. modulesGroup = &(itemGroups.getReference (itemGroups.size() - 1));
  321. }
  322. return *modulesGroup;
  323. }
  324. void ProjectExporter::addProjectPathToBuildPathList (StringArray& pathList, const RelativePath& pathFromProjectFolder, int index) const
  325. {
  326. const auto localPath = RelativePath (rebaseFromProjectFolderToBuildTarget (pathFromProjectFolder));
  327. const auto path = isVisualStudio() ? localPath.toWindowsStyle() : localPath.toUnixStyle();
  328. if (! pathList.contains (path))
  329. pathList.insert (index, path);
  330. }
  331. void ProjectExporter::addToModuleLibPaths (const RelativePath& pathFromProjectFolder)
  332. {
  333. addProjectPathToBuildPathList (moduleLibSearchPaths, pathFromProjectFolder);
  334. }
  335. void ProjectExporter::addToExtraSearchPaths (const RelativePath& pathFromProjectFolder, int index)
  336. {
  337. addProjectPathToBuildPathList (extraSearchPaths, pathFromProjectFolder, index);
  338. }
  339. Value ProjectExporter::getPathForModuleValue (const String& moduleID)
  340. {
  341. UndoManager* um = project.getUndoManagerFor (settings);
  342. ValueTree paths (settings.getOrCreateChildWithName (Ids::MODULEPATHS, um));
  343. ValueTree m (paths.getChildWithProperty (Ids::ID, moduleID));
  344. if (! m.isValid())
  345. {
  346. m = ValueTree (Ids::MODULEPATH);
  347. m.setProperty (Ids::ID, moduleID, um);
  348. paths.addChild (m, -1, um);
  349. }
  350. return m.getPropertyAsValue (Ids::path, um);
  351. }
  352. String ProjectExporter::getPathForModuleString (const String& moduleID) const
  353. {
  354. return settings.getChildWithName (Ids::MODULEPATHS)
  355. .getChildWithProperty (Ids::ID, moduleID) [Ids::path].toString();
  356. }
  357. void ProjectExporter::removePathForModule (const String& moduleID)
  358. {
  359. ValueTree paths (settings.getChildWithName (Ids::MODULEPATHS));
  360. ValueTree m (paths.getChildWithProperty (Ids::ID, moduleID));
  361. paths.removeChild (m, project.getUndoManagerFor (settings));
  362. }
  363. RelativePath ProjectExporter::getModuleFolderRelativeToProject (const String& moduleID) const
  364. {
  365. if (project.getModules().shouldCopyModuleFilesLocally (moduleID).getValue())
  366. return RelativePath (project.getRelativePathForFile (project.getLocalModuleFolder (moduleID)),
  367. RelativePath::projectFolder);
  368. String path (getPathForModuleString (moduleID));
  369. if (path.isEmpty())
  370. return getLegacyModulePath (moduleID).getChildFile (moduleID);
  371. return RelativePath (path, RelativePath::projectFolder).getChildFile (moduleID);
  372. }
  373. String ProjectExporter::getLegacyModulePath() const
  374. {
  375. return getSettingString ("juceFolder");
  376. }
  377. RelativePath ProjectExporter::getLegacyModulePath (const String& moduleID) const
  378. {
  379. if (project.getModules().state.getChildWithProperty (Ids::ID, moduleID) ["useLocalCopy"])
  380. return RelativePath (project.getRelativePathForFile (project.getGeneratedCodeFolder()
  381. .getChildFile ("modules")
  382. .getChildFile (moduleID)), RelativePath::projectFolder);
  383. String oldJucePath (getLegacyModulePath());
  384. if (oldJucePath.isEmpty())
  385. return RelativePath();
  386. RelativePath p (oldJucePath, RelativePath::projectFolder);
  387. if (p.getFileName() != "modules")
  388. p = p.getChildFile ("modules");
  389. return p.getChildFile (moduleID);
  390. }
  391. void ProjectExporter::updateOldModulePaths()
  392. {
  393. String oldPath (getLegacyModulePath());
  394. if (oldPath.isNotEmpty())
  395. {
  396. for (int i = project.getModules().getNumModules(); --i >= 0;)
  397. {
  398. String modID (project.getModules().getModuleID(i));
  399. getPathForModuleValue (modID) = getLegacyModulePath (modID).getParentDirectory().toUnixStyle();
  400. }
  401. settings.removeProperty ("juceFolder", nullptr);
  402. }
  403. }
  404. static bool areCompatibleExporters (const ProjectExporter& p1, const ProjectExporter& p2)
  405. {
  406. return (p1.isVisualStudio() && p2.isVisualStudio())
  407. || (p1.isXcode() && p2.isXcode())
  408. || (p1.isMakefile() && p2.isMakefile())
  409. || (p1.isAndroidStudio() && p2.isAndroidStudio())
  410. || (p1.isCodeBlocks() && p2.isCodeBlocks() && p1.isWindows() != p2.isLinux());
  411. }
  412. void ProjectExporter::createDefaultModulePaths()
  413. {
  414. for (Project::ExporterIterator exporter (project); exporter.next();)
  415. {
  416. if (areCompatibleExporters (*this, *exporter))
  417. {
  418. for (int i = project.getModules().getNumModules(); --i >= 0;)
  419. {
  420. String modID (project.getModules().getModuleID(i));
  421. getPathForModuleValue (modID) = exporter->getPathForModuleValue (modID).getValue();
  422. }
  423. return;
  424. }
  425. }
  426. for (Project::ExporterIterator exporter (project); exporter.next();)
  427. {
  428. if (exporter->canLaunchProject())
  429. {
  430. for (int i = project.getModules().getNumModules(); --i >= 0;)
  431. {
  432. String modID (project.getModules().getModuleID(i));
  433. getPathForModuleValue (modID) = exporter->getPathForModuleValue (modID).getValue();
  434. }
  435. return;
  436. }
  437. }
  438. for (int i = project.getModules().getNumModules(); --i >= 0;)
  439. {
  440. String modID (project.getModules().getModuleID(i));
  441. getPathForModuleValue (modID) = "../../juce";
  442. }
  443. }
  444. //==============================================================================
  445. ValueTree ProjectExporter::getConfigurations() const
  446. {
  447. return settings.getChildWithName (Ids::CONFIGURATIONS);
  448. }
  449. int ProjectExporter::getNumConfigurations() const
  450. {
  451. return getConfigurations().getNumChildren();
  452. }
  453. ProjectExporter::BuildConfiguration::Ptr ProjectExporter::getConfiguration (int index) const
  454. {
  455. return createBuildConfig (getConfigurations().getChild (index));
  456. }
  457. bool ProjectExporter::hasConfigurationNamed (const String& nameToFind) const
  458. {
  459. const ValueTree configs (getConfigurations());
  460. for (int i = configs.getNumChildren(); --i >= 0;)
  461. if (configs.getChild(i) [Ids::name].toString() == nameToFind)
  462. return true;
  463. return false;
  464. }
  465. String ProjectExporter::getUniqueConfigName (String nm) const
  466. {
  467. String nameRoot (nm);
  468. while (CharacterFunctions::isDigit (nameRoot.getLastCharacter()))
  469. nameRoot = nameRoot.dropLastCharacters (1);
  470. nameRoot = nameRoot.trim();
  471. int suffix = 2;
  472. while (hasConfigurationNamed (name))
  473. nm = nameRoot + " " + String (suffix++);
  474. return nm;
  475. }
  476. void ProjectExporter::addNewConfiguration (const BuildConfiguration* configToCopy)
  477. {
  478. const String configName (getUniqueConfigName (configToCopy != nullptr ? configToCopy->config [Ids::name].toString()
  479. : "New Build Configuration"));
  480. ValueTree configs (getConfigurations());
  481. if (! configs.isValid())
  482. {
  483. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  484. configs = getConfigurations();
  485. }
  486. ValueTree newConfig (Ids::CONFIGURATION);
  487. if (configToCopy != nullptr)
  488. newConfig = configToCopy->config.createCopy();
  489. newConfig.setProperty (Ids::name, configName, 0);
  490. configs.addChild (newConfig, -1, project.getUndoManagerFor (configs));
  491. }
  492. void ProjectExporter::BuildConfiguration::removeFromExporter()
  493. {
  494. ValueTree configs (config.getParent());
  495. configs.removeChild (config, project.getUndoManagerFor (configs));
  496. }
  497. void ProjectExporter::createDefaultConfigs()
  498. {
  499. settings.getOrCreateChildWithName (Ids::CONFIGURATIONS, nullptr);
  500. for (int i = 0; i < 2; ++i)
  501. {
  502. addNewConfiguration (nullptr);
  503. BuildConfiguration::Ptr config (getConfiguration (i));
  504. const bool debugConfig = i == 0;
  505. config->getNameValue() = debugConfig ? "Debug" : "Release";
  506. config->isDebugValue() = debugConfig;
  507. config->getOptimisationLevel() = config->getDefaultOptimisationLevel();
  508. config->getTargetBinaryName() = project.getProjectFilenameRoot();
  509. }
  510. }
  511. Drawable* ProjectExporter::getBigIcon() const
  512. {
  513. return project.getMainGroup().findItemWithID (settings [Ids::bigIcon]).loadAsImageFile();
  514. }
  515. Drawable* ProjectExporter::getSmallIcon() const
  516. {
  517. return project.getMainGroup().findItemWithID (settings [Ids::smallIcon]).loadAsImageFile();
  518. }
  519. Image ProjectExporter::getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const
  520. {
  521. Drawable* im = nullptr;
  522. ScopedPointer<Drawable> im1 (getSmallIcon());
  523. ScopedPointer<Drawable> im2 (getBigIcon());
  524. if (im1 != nullptr && im2 != nullptr)
  525. {
  526. if (im1->getWidth() >= size && im2->getWidth() >= size)
  527. im = im1->getWidth() < im2->getWidth() ? im1 : im2;
  528. else if (im1->getWidth() >= size)
  529. im = im1;
  530. else if (im2->getWidth() >= size)
  531. im = im2;
  532. }
  533. else
  534. {
  535. im = im1 != nullptr ? im1 : im2;
  536. }
  537. if (im == nullptr)
  538. return Image();
  539. if (returnNullIfNothingBigEnough && im->getWidth() < size && im->getHeight() < size)
  540. return Image();
  541. return rescaleImageForIcon (*im, size);
  542. }
  543. Image ProjectExporter::rescaleImageForIcon (Drawable& d, const int size)
  544. {
  545. if (DrawableImage* drawableImage = dynamic_cast<DrawableImage*> (&d))
  546. {
  547. Image im = SoftwareImageType().convert (drawableImage->getImage());
  548. if (size == im.getWidth() && size == im.getHeight())
  549. return im;
  550. // (scale it down in stages for better resampling)
  551. while (im.getWidth() > 2 * size && im.getHeight() > 2 * size)
  552. im = im.rescaled (im.getWidth() / 2,
  553. im.getHeight() / 2);
  554. Image newIm (Image::ARGB, size, size, true, SoftwareImageType());
  555. Graphics g (newIm);
  556. g.drawImageWithin (im, 0, 0, size, size,
  557. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  558. return newIm;
  559. }
  560. Image im (Image::ARGB, size, size, true, SoftwareImageType());
  561. Graphics g (im);
  562. d.drawWithin (g, im.getBounds().toFloat(), RectanglePlacement::centred, 1.0f);
  563. return im;
  564. }
  565. //==============================================================================
  566. ProjectExporter::ConfigIterator::ConfigIterator (ProjectExporter& e)
  567. : index (-1), exporter (e)
  568. {
  569. }
  570. bool ProjectExporter::ConfigIterator::next()
  571. {
  572. if (++index >= exporter.getNumConfigurations())
  573. return false;
  574. config = exporter.getConfiguration (index);
  575. return true;
  576. }
  577. ProjectExporter::ConstConfigIterator::ConstConfigIterator (const ProjectExporter& exporter_)
  578. : index (-1), exporter (exporter_)
  579. {
  580. }
  581. bool ProjectExporter::ConstConfigIterator::next()
  582. {
  583. if (++index >= exporter.getNumConfigurations())
  584. return false;
  585. config = exporter.getConfiguration (index);
  586. return true;
  587. }
  588. //==============================================================================
  589. ProjectExporter::BuildConfiguration::BuildConfiguration (Project& p, const ValueTree& configNode, const ProjectExporter& e)
  590. : config (configNode), project (p), exporter (e)
  591. {
  592. }
  593. ProjectExporter::BuildConfiguration::~BuildConfiguration()
  594. {
  595. }
  596. String ProjectExporter::BuildConfiguration::getGCCOptimisationFlag() const
  597. {
  598. switch (getOptimisationLevelInt())
  599. {
  600. case gccO0: return "0";
  601. case gccO1: return "1";
  602. case gccO2: return "2";
  603. case gccO3: return "3";
  604. case gccOs: return "s";
  605. case gccOfast: return "fast";
  606. default: break;
  607. }
  608. return "0";
  609. }
  610. void ProjectExporter::BuildConfiguration::addGCCOptimisationProperty (PropertyListBuilder& props)
  611. {
  612. static const char* optimisationLevels[] = { "-O0 (no optimisation)",
  613. "-Os (minimise code size)",
  614. "-O1 (fast)",
  615. "-O2 (faster)",
  616. "-O3 (fastest with safe optimisations)",
  617. "-Ofast (uses aggressive optimisations)",
  618. nullptr };
  619. static const int optimisationLevelValues[] = { gccO0,
  620. gccOs,
  621. gccO1,
  622. gccO2,
  623. gccO3,
  624. gccOfast,
  625. 0 };
  626. props.add (new ChoicePropertyComponent (getOptimisationLevel(), "Optimisation",
  627. StringArray (optimisationLevels),
  628. Array<var> (optimisationLevelValues)),
  629. "The optimisation level for this configuration");
  630. }
  631. void ProjectExporter::BuildConfiguration::createPropertyEditors (PropertyListBuilder& props)
  632. {
  633. if (exporter.supportsUserDefinedConfigurations())
  634. props.add (new TextPropertyComponent (getNameValue(), "Name", 96, false),
  635. "The name of this configuration.");
  636. props.add (new BooleanPropertyComponent (isDebugValue(), "Debug mode", "Debugging enabled"),
  637. "If enabled, this means that the configuration should be built with debug symbols.");
  638. props.add (new TextPropertyComponent (getTargetBinaryName(), "Binary name", 256, false),
  639. "The filename to use for the destination binary executable file. If you don't add a suffix to this name, "
  640. "a suitable platform-specific suffix will be added automatically.");
  641. props.add (new TextPropertyComponent (getTargetBinaryRelativePath(), "Binary location", 1024, false),
  642. "The folder in which the finished binary should be placed. Leave this blank to cause the binary to be placed "
  643. "in its default location in the build folder.");
  644. props.addSearchPathProperty (getHeaderSearchPathValue(), "Header search paths", "Extra header search paths.");
  645. props.addSearchPathProperty (getLibrarySearchPathValue(), "Extra library search paths", "Extra library search paths.");
  646. props.add (new TextPropertyComponent (getBuildConfigPreprocessorDefs(), "Preprocessor definitions", 32768, true),
  647. "Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  648. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  649. createConfigProperties (props);
  650. props.add (new TextPropertyComponent (getUserNotes(), "Notes", 32768, true),
  651. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  652. }
  653. StringPairArray ProjectExporter::BuildConfiguration::getAllPreprocessorDefs() const
  654. {
  655. return mergePreprocessorDefs (project.getPreprocessorDefs(),
  656. parsePreprocessorDefs (getBuildConfigPreprocessorDefsString()));
  657. }
  658. StringPairArray ProjectExporter::BuildConfiguration::getUniquePreprocessorDefs() const
  659. {
  660. StringPairArray perConfigurationDefs (parsePreprocessorDefs (getBuildConfigPreprocessorDefsString()));
  661. const StringPairArray globalDefs (project.getPreprocessorDefs());
  662. for (int i = 0; i < globalDefs.size(); ++i)
  663. {
  664. String globalKey = globalDefs.getAllKeys()[i];
  665. int idx = perConfigurationDefs.getAllKeys().indexOf (globalKey);
  666. if (idx >= 0)
  667. {
  668. String globalValue = globalDefs.getAllValues()[i];
  669. if (globalValue == perConfigurationDefs.getAllValues()[idx])
  670. perConfigurationDefs.remove (idx);
  671. }
  672. }
  673. return perConfigurationDefs;
  674. }
  675. StringArray ProjectExporter::BuildConfiguration::getHeaderSearchPaths() const
  676. {
  677. return getSearchPathsFromString (getHeaderSearchPathString());
  678. }
  679. StringArray ProjectExporter::BuildConfiguration::getLibrarySearchPaths() const
  680. {
  681. auto separator = exporter.isVisualStudio() ? "\\" : "/";
  682. auto s = getSearchPathsFromString (getLibrarySearchPathString());
  683. for (auto path : exporter.moduleLibSearchPaths)
  684. s.add (path + separator + getLibrarySubdirPath());
  685. return s;
  686. }
  687. String ProjectExporter::BuildConfiguration::getGCCLibraryPathFlags() const
  688. {
  689. String s;
  690. const auto libraryPaths = getSearchPathsFromString (getLibrarySearchPathString());
  691. for (auto path : libraryPaths)
  692. s << " -L" << escapeSpaces (path).replace ("~", "$(HOME)");
  693. for (auto path : exporter.moduleLibSearchPaths)
  694. s << " -L" << escapeSpaces (path).replace ("~", "$(HOME)") << "/" << getLibrarySubdirPath();
  695. return s;
  696. }
  697. String ProjectExporter::getExternalLibraryFlags (const BuildConfiguration& config) const
  698. {
  699. StringArray libraries;
  700. libraries.addTokens (getExternalLibrariesString(), ";\n", "\"'");
  701. libraries.removeEmptyStrings (true);
  702. if (libraries.size() != 0)
  703. return replacePreprocessorTokens (config, "-l" + libraries.joinIntoString (" -l")).trim();
  704. return String();
  705. }