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.

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