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.

1005 lines
41KB

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