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.

1016 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. //==============================================================================
  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. createDependencyPathProperties (props);
  242. props.add (new TextPropertyComponent (extraPPDefsValue, "Extra Preprocessor Definitions", 32768, true),
  243. "Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, "
  244. "or new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  245. props.add (new TextPropertyComponent (extraCompilerFlagsValue, "Extra Compiler Flags", 8192, true),
  246. "Extra command-line flags to be passed to the compiler. This string can contain references to preprocessor definitions in the "
  247. "form ${NAME_OF_DEFINITION}, which will be replaced with their values.");
  248. props.add (new TextPropertyComponent (extraLinkerFlagsValue, "Extra Linker Flags", 8192, true),
  249. "Extra command-line flags to be passed to the linker. You might want to use this for adding additional libraries. "
  250. "This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, which will be replaced with their values.");
  251. props.add (new TextPropertyComponent (externalLibrariesValue, "External Libraries to Link", 8192, true),
  252. "Additional libraries to link (one per line). You should not add any platform specific decoration to these names. "
  253. "This string can contain references to preprocessor definitions in the form ${NAME_OF_VALUE}, which will be replaced with their values.");
  254. if (! isVisualStudio())
  255. props.add (new ChoicePropertyComponent (gnuExtensionsValue, "GNU Compiler Extensions"),
  256. "Enabling this will use the GNU C++ language standard variant for compilation.");
  257. createIconProperties (props);
  258. }
  259. createExporterProperties (props);
  260. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  261. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  262. }
  263. void ProjectExporter::createDependencyPathProperties (PropertyListBuilder& props)
  264. {
  265. if (shouldBuildTargetType (ProjectType::Target::VST3PlugIn) && project.shouldBuildVST3())
  266. {
  267. if (dynamic_cast<DependencyPathValueSource*> (&getAAXPathValue().getValueSource()) != nullptr)
  268. props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), getVST3PathValue(), "VST3 SDK Folder"),
  269. "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. "
  270. "This can be an absolute path, or a path relative to the Projucer project file.");
  271. }
  272. if (shouldBuildTargetType (ProjectType::Target::AAXPlugIn) && project.shouldBuildAAX())
  273. {
  274. if (dynamic_cast<DependencyPathValueSource*> (&getAAXPathValue().getValueSource()) != nullptr)
  275. props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), getAAXPathValue(), "AAX SDK Folder"),
  276. "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.");
  277. }
  278. if (shouldBuildTargetType (ProjectType::Target::RTASPlugIn) && project.shouldBuildRTAS())
  279. {
  280. if (dynamic_cast<DependencyPathValueSource*> (&getRTASPathValue().getValueSource()) != nullptr)
  281. props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), getRTASPathValue(), "RTAS SDK Folder"),
  282. "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.");
  283. }
  284. }
  285. void ProjectExporter::createIconProperties (PropertyListBuilder& props)
  286. {
  287. OwnedArray<Project::Item> images;
  288. project.findAllImageItems (images);
  289. StringArray choices;
  290. Array<var> ids;
  291. choices.add ("<None>");
  292. ids.add (var());
  293. for (int i = 0; i < images.size(); ++i)
  294. {
  295. choices.add (images.getUnchecked(i)->getName());
  296. ids.add (images.getUnchecked(i)->getID());
  297. }
  298. props.add (new ChoicePropertyComponent (smallIconValue, "Icon (Small)", choices, ids),
  299. "Sets an icon to use for the executable.");
  300. props.add (new ChoicePropertyComponent (bigIconValue, "Icon (Large)", choices, ids),
  301. "Sets an icon to use for the executable.");
  302. }
  303. //==============================================================================
  304. void ProjectExporter::addSettingsForProjectType (const ProjectType& type)
  305. {
  306. addVSTPathsIfPluginOrHost();
  307. if (type.isAudioPlugin())
  308. addCommonAudioPluginSettings();
  309. addPlatformSpecificSettingsForProjectType (type);
  310. }
  311. void ProjectExporter::addVSTPathsIfPluginOrHost()
  312. {
  313. if (shouldBuildTargetType (ProjectType::Target::VST3PlugIn) || project.isVST3PluginHost()
  314. || shouldBuildTargetType (ProjectType::Target::VSTPlugIn) || project.isVSTPluginHost())
  315. addVST3FolderToPath();
  316. }
  317. void ProjectExporter::addCommonAudioPluginSettings()
  318. {
  319. if (shouldBuildTargetType (ProjectType::Target::AAXPlugIn))
  320. addAAXFoldersToPath();
  321. // Note: RTAS paths are platform-dependent, impl -> addPlatformSpecificSettingsForProjectType
  322. }
  323. RelativePath ProjectExporter::getInternalVST3SDKPath()
  324. {
  325. return getModuleFolderRelativeToProject ("juce_audio_processors")
  326. .getChildFile ("format_types")
  327. .getChildFile ("VST3_SDK");
  328. }
  329. void ProjectExporter::addVST3FolderToPath()
  330. {
  331. auto vst3Folder = getVST3PathValue().toString();
  332. if (vst3Folder.isNotEmpty())
  333. addToExtraSearchPaths (RelativePath (vst3Folder, RelativePath::projectFolder), 0);
  334. else
  335. addToExtraSearchPaths (getInternalVST3SDKPath(), 0);
  336. }
  337. void ProjectExporter::addAAXFoldersToPath()
  338. {
  339. auto aaxFolder = getAAXPathValue().toString();
  340. if (aaxFolder.isNotEmpty())
  341. {
  342. RelativePath aaxFolderPath (aaxFolder, RelativePath::projectFolder);
  343. addToExtraSearchPaths (aaxFolderPath);
  344. addToExtraSearchPaths (aaxFolderPath.getChildFile ("Interfaces"));
  345. addToExtraSearchPaths (aaxFolderPath.getChildFile ("Interfaces").getChildFile ("ACF"));
  346. }
  347. }
  348. //==============================================================================
  349. StringPairArray ProjectExporter::getAllPreprocessorDefs (const BuildConfiguration& config, const ProjectType::Target::Type targetType) const
  350. {
  351. auto defs = mergePreprocessorDefs (config.getAllPreprocessorDefs(),
  352. parsePreprocessorDefs (getExporterPreprocessorDefsString()));
  353. addDefaultPreprocessorDefs (defs);
  354. addTargetSpecificPreprocessorDefs (defs, targetType);
  355. return defs;
  356. }
  357. StringPairArray ProjectExporter::getAllPreprocessorDefs() const
  358. {
  359. auto defs = mergePreprocessorDefs (project.getPreprocessorDefs(),
  360. parsePreprocessorDefs (getExporterPreprocessorDefsString()));
  361. addDefaultPreprocessorDefs (defs);
  362. return defs;
  363. }
  364. void ProjectExporter::addTargetSpecificPreprocessorDefs (StringPairArray& defs, const ProjectType::Target::Type targetType) const
  365. {
  366. std::pair<String, ProjectType::Target::Type> targetFlags[] = {
  367. {"JucePlugin_Build_VST", ProjectType::Target::VSTPlugIn},
  368. {"JucePlugin_Build_VST3", ProjectType::Target::VST3PlugIn},
  369. {"JucePlugin_Build_AU", ProjectType::Target::AudioUnitPlugIn},
  370. {"JucePlugin_Build_AUv3", ProjectType::Target::AudioUnitv3PlugIn},
  371. {"JucePlugin_Build_RTAS", ProjectType::Target::RTASPlugIn},
  372. {"JucePlugin_Build_AAX", ProjectType::Target::AAXPlugIn},
  373. {"JucePlugin_Build_Standalone", ProjectType::Target::StandalonePlugIn},
  374. {"JucePlugin_Build_Unity", ProjectType::Target::UnityPlugIn}
  375. };
  376. if (targetType == ProjectType::Target::SharedCodeTarget)
  377. {
  378. for (auto& flag : targetFlags)
  379. defs.set (flag.first, (shouldBuildTargetType (flag.second) ? "1" : "0"));
  380. defs.set ("JUCE_SHARED_CODE", "1");
  381. }
  382. else if (targetType != ProjectType::Target::unspecified)
  383. {
  384. for (auto& flag : targetFlags)
  385. defs.set (flag.first, (targetType == flag.second ? "1" : "0"));
  386. }
  387. }
  388. void ProjectExporter::addDefaultPreprocessorDefs (StringPairArray& defs) const
  389. {
  390. defs.set (getExporterIdentifierMacro(), "1");
  391. defs.set ("JUCE_APP_VERSION", project.getVersionString());
  392. defs.set ("JUCE_APP_VERSION_HEX", project.getVersionAsHex());
  393. }
  394. String ProjectExporter::replacePreprocessorTokens (const ProjectExporter::BuildConfiguration& config,
  395. const String& sourceString) const
  396. {
  397. return replacePreprocessorDefs (getAllPreprocessorDefs (config, ProjectType::Target::unspecified), sourceString);
  398. }
  399. void ProjectExporter::copyMainGroupFromProject()
  400. {
  401. jassert (itemGroups.size() == 0);
  402. itemGroups.add (project.getMainGroup().createCopy());
  403. }
  404. Project::Item& ProjectExporter::getModulesGroup()
  405. {
  406. if (modulesGroup == nullptr)
  407. {
  408. jassert (itemGroups.size() > 0); // must call copyMainGroupFromProject before this.
  409. itemGroups.add (Project::Item::createGroup (project, "JUCE Modules", "__modulesgroup__", true));
  410. modulesGroup = &(itemGroups.getReference (itemGroups.size() - 1));
  411. }
  412. return *modulesGroup;
  413. }
  414. void ProjectExporter::addProjectPathToBuildPathList (StringArray& pathList, const RelativePath& pathFromProjectFolder, int index) const
  415. {
  416. auto localPath = RelativePath (rebaseFromProjectFolderToBuildTarget (pathFromProjectFolder));
  417. auto path = isVisualStudio() ? localPath.toWindowsStyle() : localPath.toUnixStyle();
  418. if (! pathList.contains (path))
  419. pathList.insert (index, path);
  420. }
  421. void ProjectExporter::addToModuleLibPaths (const RelativePath& pathFromProjectFolder)
  422. {
  423. addProjectPathToBuildPathList (moduleLibSearchPaths, pathFromProjectFolder);
  424. }
  425. void ProjectExporter::addToExtraSearchPaths (const RelativePath& pathFromProjectFolder, int index)
  426. {
  427. addProjectPathToBuildPathList (extraSearchPaths, pathFromProjectFolder, index);
  428. }
  429. Value ProjectExporter::getPathForModuleValue (const String& moduleID)
  430. {
  431. auto* um = getUndoManager();
  432. auto paths = settings.getOrCreateChildWithName (Ids::MODULEPATHS, um);
  433. auto m = paths.getChildWithProperty (Ids::ID, moduleID);
  434. if (! m.isValid())
  435. {
  436. m = ValueTree (Ids::MODULEPATH);
  437. m.setProperty (Ids::ID, moduleID, um);
  438. paths.appendChild (m, um);
  439. }
  440. return m.getPropertyAsValue (Ids::path, um);
  441. }
  442. String ProjectExporter::getPathForModuleString (const String& moduleID) const
  443. {
  444. auto exporterPath = settings.getChildWithName (Ids::MODULEPATHS)
  445. .getChildWithProperty (Ids::ID, moduleID) [Ids::path].toString();
  446. if (exporterPath.isEmpty() || project.getEnabledModules().shouldUseGlobalPath (moduleID))
  447. {
  448. auto id = isJUCEModule (moduleID) ? Ids::defaultJuceModulePath
  449. : Ids::defaultUserModulePath;
  450. if (TargetOS::getThisOS() != getTargetOSForExporter())
  451. return getAppSettings().getFallbackPathForOS (id, getTargetOSForExporter()).toString();
  452. if (id == Ids::defaultJuceModulePath)
  453. return getAppSettings().getStoredPath (Ids::defaultJuceModulePath).toString();
  454. return getAppSettings().getStoredPath (Ids::defaultUserModulePath).toString();
  455. }
  456. return exporterPath;
  457. }
  458. void ProjectExporter::removePathForModule (const String& moduleID)
  459. {
  460. auto paths = settings.getChildWithName (Ids::MODULEPATHS);
  461. auto m = paths.getChildWithProperty (Ids::ID, moduleID);
  462. paths.removeChild (m, project.getUndoManagerFor (settings));
  463. }
  464. TargetOS::OS ProjectExporter::getTargetOSForExporter() const
  465. {
  466. auto targetOS = TargetOS::unknown;
  467. if (isWindows()) targetOS = TargetOS::windows;
  468. else if (isOSX() || isiOS()) targetOS = TargetOS::osx;
  469. else if (isLinux()) targetOS = TargetOS::linux;
  470. else if (isAndroid() || isCLion()) targetOS = TargetOS::getThisOS();
  471. return targetOS;
  472. }
  473. RelativePath ProjectExporter::getModuleFolderRelativeToProject (const String& moduleID) const
  474. {
  475. if (project.getEnabledModules().shouldCopyModuleFilesLocally (moduleID).getValue())
  476. return RelativePath (project.getRelativePathForFile (project.getLocalModuleFolder (moduleID)),
  477. RelativePath::projectFolder);
  478. auto path = getPathForModuleString (moduleID);
  479. if (path.isEmpty())
  480. return getLegacyModulePath (moduleID).getChildFile (moduleID);
  481. return RelativePath (path, RelativePath::projectFolder).getChildFile (moduleID);
  482. }
  483. String ProjectExporter::getLegacyModulePath() const
  484. {
  485. return getSettingString ("juceFolder");
  486. }
  487. RelativePath ProjectExporter::getLegacyModulePath (const String& moduleID) const
  488. {
  489. if (project.getEnabledModules().state.getChildWithProperty (Ids::ID, moduleID) ["useLocalCopy"])
  490. return RelativePath (project.getRelativePathForFile (project.getGeneratedCodeFolder()
  491. .getChildFile ("modules")
  492. .getChildFile (moduleID)), RelativePath::projectFolder);
  493. auto oldJucePath = getLegacyModulePath();
  494. if (oldJucePath.isEmpty())
  495. return RelativePath();
  496. RelativePath p (oldJucePath, RelativePath::projectFolder);
  497. if (p.getFileName() != "modules")
  498. p = p.getChildFile ("modules");
  499. return p.getChildFile (moduleID);
  500. }
  501. void ProjectExporter::updateOldModulePaths()
  502. {
  503. auto oldPath = getLegacyModulePath();
  504. if (oldPath.isNotEmpty())
  505. {
  506. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  507. {
  508. auto modID = project.getEnabledModules().getModuleID(i);
  509. getPathForModuleValue (modID) = getLegacyModulePath (modID).getParentDirectory().toUnixStyle();
  510. }
  511. settings.removeProperty ("juceFolder", nullptr);
  512. }
  513. }
  514. static bool areCompatibleExporters (const ProjectExporter& p1, const ProjectExporter& p2)
  515. {
  516. return (p1.isVisualStudio() && p2.isVisualStudio())
  517. || (p1.isXcode() && p2.isXcode())
  518. || (p1.isMakefile() && p2.isMakefile())
  519. || (p1.isAndroidStudio() && p2.isAndroidStudio())
  520. || (p1.isCodeBlocks() && p2.isCodeBlocks() && p1.isWindows() != p2.isLinux());
  521. }
  522. void ProjectExporter::createDefaultModulePaths()
  523. {
  524. for (Project::ExporterIterator exporter (project); exporter.next();)
  525. {
  526. if (areCompatibleExporters (*this, *exporter))
  527. {
  528. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  529. {
  530. auto modID = project.getEnabledModules().getModuleID (i);
  531. getPathForModuleValue (modID) = exporter->getPathForModuleValue (modID).getValue();
  532. }
  533. return;
  534. }
  535. }
  536. for (Project::ExporterIterator exporter (project); exporter.next();)
  537. {
  538. if (exporter->canLaunchProject())
  539. {
  540. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  541. {
  542. auto modID = project.getEnabledModules().getModuleID (i);
  543. getPathForModuleValue (modID) = exporter->getPathForModuleValue (modID).getValue();
  544. }
  545. return;
  546. }
  547. }
  548. for (int i = project.getEnabledModules().getNumModules(); --i >= 0;)
  549. {
  550. auto modID = project.getEnabledModules().getModuleID (i);
  551. getPathForModuleValue (modID) = "../../juce";
  552. }
  553. }
  554. //==============================================================================
  555. ValueTree ProjectExporter::getConfigurations() const
  556. {
  557. return settings.getChildWithName (Ids::CONFIGURATIONS);
  558. }
  559. int ProjectExporter::getNumConfigurations() const
  560. {
  561. return getConfigurations().getNumChildren();
  562. }
  563. ProjectExporter::BuildConfiguration::Ptr ProjectExporter::getConfiguration (int index) const
  564. {
  565. return createBuildConfig (getConfigurations().getChild (index));
  566. }
  567. bool ProjectExporter::hasConfigurationNamed (const String& nameToFind) const
  568. {
  569. auto configs = getConfigurations();
  570. for (int i = configs.getNumChildren(); --i >= 0;)
  571. if (configs.getChild(i) [Ids::name].toString() == nameToFind)
  572. return true;
  573. return false;
  574. }
  575. String ProjectExporter::getUniqueConfigName (String nm) const
  576. {
  577. auto nameRoot = nm;
  578. while (CharacterFunctions::isDigit (nameRoot.getLastCharacter()))
  579. nameRoot = nameRoot.dropLastCharacters (1);
  580. nameRoot = nameRoot.trim();
  581. int suffix = 2;
  582. while (hasConfigurationNamed (name))
  583. nm = nameRoot + " " + String (suffix++);
  584. return nm;
  585. }
  586. void ProjectExporter::addNewConfigurationFromExisting (const BuildConfiguration& configToCopy)
  587. {
  588. auto configs = getConfigurations();
  589. if (! configs.isValid())
  590. {
  591. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  592. configs = getConfigurations();
  593. }
  594. ValueTree newConfig (Ids::CONFIGURATION);
  595. newConfig = configToCopy.config.createCopy();
  596. newConfig.setProperty (Ids::name, configToCopy.getName(), nullptr);
  597. configs.appendChild (newConfig, project.getUndoManagerFor (configs));
  598. }
  599. void ProjectExporter::addNewConfiguration (bool isDebugConfig)
  600. {
  601. auto configs = getConfigurations();
  602. if (! configs.isValid())
  603. {
  604. settings.addChild (ValueTree (Ids::CONFIGURATIONS), 0, project.getUndoManagerFor (settings));
  605. configs = getConfigurations();
  606. }
  607. ValueTree newConfig (Ids::CONFIGURATION);
  608. newConfig.setProperty (Ids::isDebug, isDebugConfig, project.getUndoManagerFor (settings));
  609. configs.appendChild (newConfig, project.getUndoManagerFor (settings));
  610. }
  611. void ProjectExporter::BuildConfiguration::removeFromExporter()
  612. {
  613. ValueTree configs (config.getParent());
  614. configs.removeChild (config, project.getUndoManagerFor (configs));
  615. }
  616. void ProjectExporter::createDefaultConfigs()
  617. {
  618. settings.getOrCreateChildWithName (Ids::CONFIGURATIONS, nullptr);
  619. for (int i = 0; i < 2; ++i)
  620. {
  621. auto isDebug = i == 0;
  622. addNewConfiguration (isDebug);
  623. BuildConfiguration::Ptr config (getConfiguration (i));
  624. config->getValue (Ids::name) = (isDebug ? "Debug" : "Release");
  625. }
  626. }
  627. Drawable* ProjectExporter::getBigIcon() const
  628. {
  629. return project.getMainGroup().findItemWithID (settings [Ids::bigIcon]).loadAsImageFile();
  630. }
  631. Drawable* ProjectExporter::getSmallIcon() const
  632. {
  633. return project.getMainGroup().findItemWithID (settings [Ids::smallIcon]).loadAsImageFile();
  634. }
  635. Image ProjectExporter::getBestIconForSize (int size, bool returnNullIfNothingBigEnough) const
  636. {
  637. Drawable* im = nullptr;
  638. std::unique_ptr<Drawable> im1 (getSmallIcon());
  639. std::unique_ptr<Drawable> im2 (getBigIcon());
  640. if (im1 != nullptr && im2 != nullptr)
  641. {
  642. if (im1->getWidth() >= size && im2->getWidth() >= size)
  643. im = im1->getWidth() < im2->getWidth() ? im1.get() : im2.get();
  644. else if (im1->getWidth() >= size)
  645. im = im1.get();
  646. else if (im2->getWidth() >= size)
  647. im = im2.get();
  648. }
  649. else
  650. {
  651. im = im1 != nullptr ? im1.get() : im2.get();
  652. }
  653. if (im == nullptr)
  654. return {};
  655. if (returnNullIfNothingBigEnough && im->getWidth() < size && im->getHeight() < size)
  656. return {};
  657. return rescaleImageForIcon (*im, size);
  658. }
  659. Image ProjectExporter::rescaleImageForIcon (Drawable& d, const int size)
  660. {
  661. if (auto* drawableImage = dynamic_cast<DrawableImage*> (&d))
  662. {
  663. auto im = SoftwareImageType().convert (drawableImage->getImage());
  664. if (im.getWidth() == size && im.getHeight() == size)
  665. return im;
  666. // (scale it down in stages for better resampling)
  667. while (im.getWidth() > 2 * size && im.getHeight() > 2 * size)
  668. im = im.rescaled (im.getWidth() / 2,
  669. im.getHeight() / 2);
  670. Image newIm (Image::ARGB, size, size, true, SoftwareImageType());
  671. Graphics g (newIm);
  672. g.drawImageWithin (im, 0, 0, size, size,
  673. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  674. return newIm;
  675. }
  676. Image im (Image::ARGB, size, size, true, SoftwareImageType());
  677. Graphics g (im);
  678. d.drawWithin (g, im.getBounds().toFloat(), RectanglePlacement::centred, 1.0f);
  679. return im;
  680. }
  681. //==============================================================================
  682. ProjectExporter::ConfigIterator::ConfigIterator (ProjectExporter& e)
  683. : index (-1), exporter (e)
  684. {
  685. }
  686. bool ProjectExporter::ConfigIterator::next()
  687. {
  688. if (++index >= exporter.getNumConfigurations())
  689. return false;
  690. config = exporter.getConfiguration (index);
  691. return true;
  692. }
  693. ProjectExporter::ConstConfigIterator::ConstConfigIterator (const ProjectExporter& exporter_)
  694. : index (-1), exporter (exporter_)
  695. {
  696. }
  697. bool ProjectExporter::ConstConfigIterator::next()
  698. {
  699. if (++index >= exporter.getNumConfigurations())
  700. return false;
  701. config = exporter.getConfiguration (index);
  702. return true;
  703. }
  704. //==============================================================================
  705. ProjectExporter::BuildConfiguration::BuildConfiguration (Project& p, const ValueTree& configNode, const ProjectExporter& e)
  706. : config (configNode), project (p), exporter (e),
  707. isDebugValue (config, Ids::isDebug, getUndoManager(), getValue (Ids::isDebug)),
  708. configNameValue (config, Ids::name, getUndoManager(), "Build Configuration"),
  709. targetNameValue (config, Ids::targetName, getUndoManager(), project.getProjectFilenameRootString()),
  710. targetBinaryPathValue (config, Ids::binaryPath, getUndoManager()),
  711. optimisationLevelValue (config, Ids::optimisation, getUndoManager()),
  712. linkTimeOptimisationValue (config, Ids::linkTimeOptimisation, getUndoManager(), ! isDebug()),
  713. ppDefinesValue (config, Ids::defines, getUndoManager()),
  714. headerSearchPathValue (config, Ids::headerPath, getUndoManager()),
  715. librarySearchPathValue (config, Ids::libraryPath, getUndoManager()),
  716. userNotesValue (config, Ids::userNotes, getUndoManager())
  717. {
  718. }
  719. ProjectExporter::BuildConfiguration::~BuildConfiguration()
  720. {
  721. }
  722. String ProjectExporter::BuildConfiguration::getGCCOptimisationFlag() const
  723. {
  724. switch (getOptimisationLevelInt())
  725. {
  726. case gccO0: return "0";
  727. case gccO1: return "1";
  728. case gccO2: return "2";
  729. case gccO3: return "3";
  730. case gccOs: return "s";
  731. case gccOfast: return "fast";
  732. default: break;
  733. }
  734. return "0";
  735. }
  736. void ProjectExporter::BuildConfiguration::addGCCOptimisationProperty (PropertyListBuilder& props)
  737. {
  738. props.add (new ChoicePropertyComponent (optimisationLevelValue, "Optimisation",
  739. { "-O0 (no optimisation)", "-Os (minimise code size)", "-O1 (fast)", "-O2 (faster)",
  740. "-O3 (fastest with safe optimisations)", "-Ofast (uses aggressive optimisations)" },
  741. { gccO0, gccOs, gccO1, gccO2, gccO3, gccOfast }),
  742. "The optimisation level for this configuration");
  743. }
  744. void ProjectExporter::BuildConfiguration::createPropertyEditors (PropertyListBuilder& props)
  745. {
  746. if (exporter.supportsUserDefinedConfigurations())
  747. props.add (new TextPropertyComponent (configNameValue, "Name", 96, false),
  748. "The name of this configuration.");
  749. props.add (new ChoicePropertyComponent (isDebugValue, "Debug Mode"),
  750. "If enabled, this means that the configuration should be built with debug symbols.");
  751. props.add (new TextPropertyComponent (targetNameValue, "Binary Name", 256, false),
  752. "The filename to use for the destination binary executable file. If you don't add a suffix to this name, "
  753. "a suitable platform-specific suffix will be added automatically.");
  754. props.add (new TextPropertyComponent (targetBinaryPathValue, "Binary Location", 1024, false),
  755. "The folder in which the finished binary should be placed. Leave this blank to cause the binary to be placed "
  756. "in its default location in the build folder.");
  757. props.addSearchPathProperty (headerSearchPathValue, "Header Search Paths", "Extra header search paths.");
  758. props.addSearchPathProperty (librarySearchPathValue, "Extra Library Search Paths", "Extra library search paths.");
  759. props.add (new TextPropertyComponent (ppDefinesValue, "Preprocessor Definitions", 32768, true),
  760. "Extra preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  761. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  762. props.add (new ChoicePropertyComponent (linkTimeOptimisationValue, "Link-Time Optimisation"),
  763. "Enable this to perform link-time code optimisation. This is recommended for release builds.");
  764. createConfigProperties (props);
  765. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  766. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  767. }
  768. StringPairArray ProjectExporter::BuildConfiguration::getAllPreprocessorDefs() const
  769. {
  770. return mergePreprocessorDefs (project.getPreprocessorDefs(),
  771. parsePreprocessorDefs (getBuildConfigPreprocessorDefsString()));
  772. }
  773. StringPairArray ProjectExporter::BuildConfiguration::getUniquePreprocessorDefs() const
  774. {
  775. auto perConfigurationDefs = parsePreprocessorDefs (getBuildConfigPreprocessorDefsString());
  776. auto globalDefs = project.getPreprocessorDefs();
  777. for (int i = 0; i < globalDefs.size(); ++i)
  778. {
  779. auto globalKey = globalDefs.getAllKeys()[i];
  780. int idx = perConfigurationDefs.getAllKeys().indexOf (globalKey);
  781. if (idx >= 0)
  782. {
  783. auto globalValue = globalDefs.getAllValues()[i];
  784. if (globalValue == perConfigurationDefs.getAllValues()[idx])
  785. perConfigurationDefs.remove (idx);
  786. }
  787. }
  788. return perConfigurationDefs;
  789. }
  790. StringArray ProjectExporter::BuildConfiguration::getHeaderSearchPaths() const
  791. {
  792. return getSearchPathsFromString (getHeaderSearchPathString() + ';' + project.getHeaderSearchPathsString());
  793. }
  794. StringArray ProjectExporter::BuildConfiguration::getLibrarySearchPaths() const
  795. {
  796. auto separator = exporter.isVisualStudio() ? "\\" : "/";
  797. auto s = getSearchPathsFromString (getLibrarySearchPathString());
  798. for (auto path : exporter.moduleLibSearchPaths)
  799. s.add (path + separator + getModuleLibraryArchName());
  800. return s;
  801. }
  802. String ProjectExporter::getExternalLibraryFlags (const BuildConfiguration& config) const
  803. {
  804. auto libraries = StringArray::fromTokens (getExternalLibrariesString(), ";\n", "\"'");
  805. libraries.removeEmptyStrings (true);
  806. if (libraries.size() != 0)
  807. return replacePreprocessorTokens (config, "-l" + libraries.joinIntoString (" -l")).trim();
  808. return {};
  809. }