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.

880 lines
35KB

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