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.

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