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.

969 lines
39KB

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