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.

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