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.

972 lines
39KB

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