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.

786 lines
26KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "jucer_Module.h"
  18. #include "jucer_ProjectType.h"
  19. #include "../Project Saving/jucer_ProjectExporter.h"
  20. #include "../Project Saving/jucer_ProjectSaver.h"
  21. #include "jucer_AudioPluginModule.h"
  22. //==============================================================================
  23. ModuleList::ModuleList()
  24. {
  25. }
  26. ModuleList::ModuleList (const ModuleList& other)
  27. : moduleFolder (other.moduleFolder)
  28. {
  29. modules.addCopiesOf (other.modules);
  30. }
  31. ModuleList& ModuleList::operator= (const ModuleList& other)
  32. {
  33. moduleFolder = other.moduleFolder;
  34. modules.clear();
  35. modules.addCopiesOf (other.modules);
  36. return *this;
  37. }
  38. bool ModuleList::operator== (const ModuleList& other) const
  39. {
  40. if (modules.size() != other.modules.size())
  41. return false;
  42. for (int i = modules.size(); --i >= 0;)
  43. {
  44. const Module* m1 = modules.getUnchecked(i);
  45. const Module* m2 = other.findModuleInfo (m1->uid);
  46. if (m2 == nullptr || *m1 != *m2)
  47. return false;
  48. }
  49. return true;
  50. }
  51. bool ModuleList::isLocalModulesFolderValid()
  52. {
  53. return isModulesFolder (getModulesFolderForJuceOrModulesFolder (getLocalModulesFolder (nullptr)));
  54. }
  55. static int getVersionElement (const String& v, int index)
  56. {
  57. StringArray parts;
  58. parts.addTokens (v, "., ", String::empty);
  59. return parts [parts.size() - index - 1].getIntValue();
  60. }
  61. static int getJuceVersion (const String& v)
  62. {
  63. return getVersionElement (v, 2) * 100000
  64. + getVersionElement (v, 1) * 1000
  65. + getVersionElement (v, 0);
  66. }
  67. static int getBuiltJuceVersion()
  68. {
  69. return JUCE_MAJOR_VERSION * 100000
  70. + JUCE_MINOR_VERSION * 1000
  71. + JUCE_BUILDNUMBER;
  72. }
  73. bool ModuleList::isLibraryNewerThanIntrojucer()
  74. {
  75. ModuleList list;
  76. list.rescan (getModulesFolderForJuceOrModulesFolder (getLocalModulesFolder (nullptr)));
  77. for (int i = list.modules.size(); --i >= 0;)
  78. {
  79. const Module* m = list.modules.getUnchecked(i);
  80. if (m->uid.startsWith ("juce_")
  81. && getJuceVersion (m->version) > getBuiltJuceVersion())
  82. return true;
  83. }
  84. return false;
  85. }
  86. bool ModuleList::isJuceFolder (const File& folder)
  87. {
  88. return folder.getFileName().containsIgnoreCase ("juce")
  89. && isModulesFolder (folder.getChildFile ("modules"));
  90. }
  91. bool ModuleList::isModulesFolder (const File& folder)
  92. {
  93. return folder.getFileName().equalsIgnoreCase ("modules")
  94. && folder.isDirectory();
  95. }
  96. bool ModuleList::isJuceOrModulesFolder (const File& folder)
  97. {
  98. return isJuceFolder (folder) || isModulesFolder (folder);
  99. }
  100. File ModuleList::getModulesFolderForJuceOrModulesFolder (const File& f)
  101. {
  102. if (f.getFileName() != "modules" && f.isDirectory() && f.getChildFile ("modules").isDirectory())
  103. return f.getChildFile ("modules");
  104. return f;
  105. }
  106. File ModuleList::getModulesFolderForExporter (const ProjectExporter& exporter)
  107. {
  108. File f (exporter.getProject().resolveFilename (exporter.getJuceFolderString()));
  109. f = getModulesFolderForJuceOrModulesFolder (f);
  110. return f;
  111. }
  112. File ModuleList::getDefaultModulesFolder (Project* project)
  113. {
  114. if (project != nullptr)
  115. {
  116. for (Project::ExporterIterator exporter (*project); exporter.next();)
  117. {
  118. const File f (getModulesFolderForExporter (*exporter));
  119. if (ModuleList::isModulesFolder (f))
  120. return f;
  121. }
  122. }
  123. // Fall back to a default..
  124. #if JUCE_WINDOWS
  125. return File::getSpecialLocation (File::userDocumentsDirectory)
  126. #else
  127. return File::getSpecialLocation (File::userHomeDirectory)
  128. #endif
  129. .getChildFile ("juce")
  130. .getChildFile ("modules");
  131. }
  132. File ModuleList::getLocalModulesFolder (Project* project)
  133. {
  134. File defaultJuceFolder (getDefaultModulesFolder (project));
  135. File f (getGlobalProperties().getValue ("lastJuceFolder", defaultJuceFolder.getFullPathName()));
  136. f = getModulesFolderForJuceOrModulesFolder (f);
  137. if ((! ModuleList::isModulesFolder (f)) && ModuleList::isModulesFolder (defaultJuceFolder))
  138. f = defaultJuceFolder;
  139. return f;
  140. }
  141. void ModuleList::setLocalModulesFolder (const File& file)
  142. {
  143. //jassert (FileHelpers::isJuceFolder (file));
  144. getGlobalProperties().setValue ("lastJuceFolder", file.getFullPathName());
  145. }
  146. struct ModuleSorter
  147. {
  148. static int compareElements (const ModuleList::Module* m1, const ModuleList::Module* m2)
  149. {
  150. return m1->uid.compareIgnoreCase (m2->uid);
  151. }
  152. };
  153. void ModuleList::sort()
  154. {
  155. ModuleSorter sorter;
  156. modules.sort (sorter);
  157. }
  158. void ModuleList::rescan()
  159. {
  160. rescan (moduleFolder);
  161. }
  162. Result ModuleList::rescan (const File& newModulesFolder)
  163. {
  164. modules.clear();
  165. moduleFolder = getModulesFolderForJuceOrModulesFolder (newModulesFolder);
  166. if (moduleFolder.isDirectory())
  167. {
  168. DirectoryIterator iter (moduleFolder, false, "*", File::findDirectories);
  169. while (iter.next())
  170. {
  171. const File moduleDef (iter.getFile().getLinkedTarget()
  172. .getChildFile (LibraryModule::getInfoFileName()));
  173. if (moduleDef.exists())
  174. {
  175. LibraryModule m (moduleDef);
  176. if (! m.isValid())
  177. return Result::fail ("Failed to load module manifest: " + moduleDef.getFullPathName());
  178. Module* info = new Module();
  179. modules.add (info);
  180. info->uid = m.getID();
  181. info->version = m.getVersion();
  182. info->name = m.moduleInfo ["name"];
  183. info->description = m.moduleInfo ["description"];
  184. info->file = moduleDef;
  185. }
  186. }
  187. }
  188. sort();
  189. return Result::ok();
  190. }
  191. bool ModuleList::loadFromWebsite()
  192. {
  193. modules.clear();
  194. URL baseURL ("http://www.juce.com/juce/modules");
  195. URL url (baseURL.getChildURL ("modulelist.php"));
  196. var infoList (JSON::parse (url.readEntireTextStream (false)));
  197. if (infoList.isArray())
  198. {
  199. const Array<var>* moduleList = infoList.getArray();
  200. for (int i = 0; i < moduleList->size(); ++i)
  201. {
  202. const var& m = moduleList->getReference(i);
  203. const String file (m ["file"].toString());
  204. if (file.isNotEmpty())
  205. {
  206. var moduleInfo (m ["info"]);
  207. LibraryModule lm (moduleInfo);
  208. if (lm.isValid())
  209. {
  210. Module* info = new Module();
  211. modules.add (info);
  212. info->uid = lm.getID();
  213. info->version = lm.getVersion();
  214. info->name = lm.getName();
  215. info->description = lm.getDescription();
  216. info->url = baseURL.getChildURL (file);
  217. }
  218. }
  219. }
  220. }
  221. sort();
  222. return infoList.isArray();
  223. }
  224. LibraryModule* ModuleList::Module::create() const
  225. {
  226. return new LibraryModule (file);
  227. }
  228. bool ModuleList::Module::operator== (const Module& other) const
  229. {
  230. return uid == other.uid
  231. && version == other.version
  232. && name == other.name
  233. && description == other.description
  234. && file == other.file
  235. && url == other.url;
  236. }
  237. bool ModuleList::Module::operator!= (const Module& other) const
  238. {
  239. return ! operator== (other);
  240. }
  241. LibraryModule* ModuleList::loadModule (const String& uid) const
  242. {
  243. if (const Module* const m = findModuleInfo (uid))
  244. return m->create();
  245. return nullptr;
  246. }
  247. const ModuleList::Module* ModuleList::findModuleInfo (const String& uid) const
  248. {
  249. for (int i = modules.size(); --i >= 0;)
  250. if (modules.getUnchecked(i)->uid == uid)
  251. return modules.getUnchecked(i);
  252. return nullptr;
  253. }
  254. void ModuleList::getDependencies (const String& moduleID, StringArray& dependencies) const
  255. {
  256. ScopedPointer<LibraryModule> m (loadModule (moduleID));
  257. if (m != nullptr)
  258. {
  259. const var depsArray (m->moduleInfo ["dependencies"]);
  260. if (const Array<var>* const deps = depsArray.getArray())
  261. {
  262. for (int i = 0; i < deps->size(); ++i)
  263. {
  264. const var& d = deps->getReference(i);
  265. String uid (d ["id"].toString());
  266. String version (d ["version"].toString());
  267. if (! dependencies.contains (uid, true))
  268. {
  269. dependencies.add (uid);
  270. getDependencies (uid, dependencies);
  271. }
  272. }
  273. }
  274. }
  275. }
  276. void ModuleList::createDependencies (const String& moduleID, OwnedArray<LibraryModule>&) const
  277. {
  278. ScopedPointer<LibraryModule> m (loadModule (moduleID));
  279. if (m != nullptr)
  280. {
  281. const var depsArray (m->moduleInfo ["dependencies"]);
  282. if (const Array<var>* const deps = depsArray.getArray())
  283. {
  284. for (int i = 0; i < deps->size(); ++i)
  285. {
  286. const var& d = deps->getReference(i);
  287. String uid (d ["id"].toString());
  288. String version (d ["version"].toString());
  289. //xxx to do - also need to find version conflicts
  290. jassertfalse;
  291. }
  292. }
  293. }
  294. }
  295. StringArray ModuleList::getExtraDependenciesNeeded (Project& project, const ModuleList::Module& m)
  296. {
  297. StringArray dependencies, extraDepsNeeded;
  298. getDependencies (m.uid, dependencies);
  299. for (int i = 0; i < dependencies.size(); ++i)
  300. if ((! project.isModuleEnabled (dependencies[i])) && dependencies[i] != m.uid)
  301. extraDepsNeeded.add (dependencies[i]);
  302. return extraDepsNeeded;
  303. }
  304. //==============================================================================
  305. LibraryModule::LibraryModule (const File& file)
  306. : moduleInfo (JSON::parse (file)),
  307. moduleFile (file),
  308. moduleFolder (file.getParentDirectory())
  309. {
  310. }
  311. LibraryModule::LibraryModule (const var& info)
  312. : moduleInfo (info)
  313. {
  314. }
  315. bool LibraryModule::isValid() const { return getID().isNotEmpty(); }
  316. bool LibraryModule::isPluginClient() const { return getID() == "juce_audio_plugin_client"; }
  317. bool LibraryModule::isAUPluginHost (const Project& project) const { return getID() == "juce_audio_processors" && project.isConfigFlagEnabled ("JUCE_PLUGINHOST_AU"); }
  318. bool LibraryModule::isVSTPluginHost (const Project& project) const { return getID() == "juce_audio_processors" && project.isConfigFlagEnabled ("JUCE_PLUGINHOST_VST"); }
  319. File LibraryModule::getInclude (const File& folder) const
  320. {
  321. return folder.getChildFile (moduleInfo ["include"]);
  322. }
  323. RelativePath LibraryModule::getModuleRelativeToProject (ProjectExporter& exporter) const
  324. {
  325. RelativePath p (exporter.getJuceFolderString(), RelativePath::projectFolder);
  326. if (p.getFileName() != "modules")
  327. p = p.getChildFile ("modules");
  328. return p.getChildFile (getID());
  329. }
  330. RelativePath LibraryModule::getModuleOrLocalCopyRelativeToProject (ProjectExporter& exporter, const File& localModuleFolder) const
  331. {
  332. if (exporter.getProject().shouldCopyModuleFilesLocally (getID()).getValue())
  333. return RelativePath (exporter.getProject().getRelativePathForFile (localModuleFolder), RelativePath::projectFolder);
  334. return getModuleRelativeToProject (exporter);
  335. }
  336. //==============================================================================
  337. void LibraryModule::writeIncludes (ProjectSaver& projectSaver, OutputStream& out)
  338. {
  339. const File localModuleFolder (projectSaver.getLocalModuleFolder (*this));
  340. const File localHeader (getInclude (localModuleFolder));
  341. if (projectSaver.getProject().shouldCopyModuleFilesLocally (getID()).getValue())
  342. {
  343. projectSaver.copyFolder (moduleFolder, localModuleFolder);
  344. }
  345. else
  346. {
  347. localModuleFolder.createDirectory();
  348. createLocalHeaderWrapper (projectSaver, getInclude (moduleFolder), localHeader);
  349. }
  350. out << CodeHelpers::createIncludeStatement (localHeader, projectSaver.getGeneratedCodeFolder().getChildFile ("AppConfig.h")) << newLine;
  351. }
  352. static void writeGuardedInclude (OutputStream& out, StringArray paths, StringArray guards)
  353. {
  354. StringArray uniquePaths (paths);
  355. uniquePaths.removeDuplicates (false);
  356. if (uniquePaths.size() == 1)
  357. {
  358. out << "#include " << paths[0] << newLine;
  359. }
  360. else
  361. {
  362. for (int i = paths.size(); --i >= 0;)
  363. {
  364. for (int j = i; --j >= 0;)
  365. {
  366. if (paths[i] == paths[j] && guards[i] == guards[j])
  367. {
  368. paths.remove (i);
  369. guards.remove (i);
  370. }
  371. }
  372. }
  373. for (int i = 0; i < paths.size(); ++i)
  374. {
  375. out << (i == 0 ? "#if " : "#elif ") << guards[i] << newLine
  376. << " #include " << paths[i] << newLine;
  377. }
  378. out << "#else" << newLine
  379. << " #error \"This file is designed to be used in an Introjucer-generated project!\"" << newLine
  380. << "#endif" << newLine;
  381. }
  382. }
  383. void LibraryModule::createLocalHeaderWrapper (ProjectSaver& projectSaver, const File& originalHeader, const File& localHeader) const
  384. {
  385. Project& project = projectSaver.getProject();
  386. MemoryOutputStream out;
  387. out << "// This is an auto-generated file to redirect any included" << newLine
  388. << "// module headers to the correct external folder." << newLine
  389. << newLine;
  390. StringArray paths, guards;
  391. for (Project::ExporterIterator exporter (project); exporter.next();)
  392. {
  393. const RelativePath headerFromProject (getModuleRelativeToProject (*exporter)
  394. .getChildFile (originalHeader.getFileName()));
  395. const RelativePath fileFromHere (headerFromProject.rebased (project.getFile().getParentDirectory(),
  396. localHeader.getParentDirectory(), RelativePath::unknown));
  397. paths.add (fileFromHere.toUnixStyle().quoted());
  398. guards.add ("defined (" + exporter->getExporterIdentifierMacro() + ")");
  399. }
  400. writeGuardedInclude (out, paths, guards);
  401. out << newLine;
  402. projectSaver.replaceFileIfDifferent (localHeader, out);
  403. }
  404. //==============================================================================
  405. File LibraryModule::getLocalFolderFor (Project& project) const
  406. {
  407. if (project.shouldCopyModuleFilesLocally (getID()).getValue())
  408. return project.getGeneratedCodeFolder().getChildFile ("modules").getChildFile (getID());
  409. return moduleFolder;
  410. }
  411. void LibraryModule::prepareExporter (ProjectExporter& exporter, ProjectSaver& projectSaver) const
  412. {
  413. Project& project = exporter.getProject();
  414. File localFolder (moduleFolder);
  415. if (project.shouldCopyModuleFilesLocally (getID()).getValue())
  416. localFolder = projectSaver.getLocalModuleFolder (*this);
  417. {
  418. Array<File> compiled;
  419. findAndAddCompiledCode (exporter, projectSaver, localFolder, compiled);
  420. if (project.shouldShowAllModuleFilesInProject (getID()).getValue())
  421. addBrowsableCode (exporter, compiled, localFolder);
  422. }
  423. if (isVSTPluginHost (project))
  424. VSTHelpers::addVSTFolderToPath (exporter, exporter.extraSearchPaths);
  425. if (exporter.isXcode())
  426. {
  427. if (isAUPluginHost (project))
  428. exporter.xcodeFrameworks.addTokens ("AudioUnit CoreAudioKit", false);
  429. const String frameworks (moduleInfo [exporter.isOSX() ? "OSXFrameworks" : "iOSFrameworks"].toString());
  430. exporter.xcodeFrameworks.addTokens (frameworks, ", ", String::empty);
  431. }
  432. else if (exporter.isLinux())
  433. {
  434. const String libs (moduleInfo ["LinuxLibs"].toString());
  435. exporter.linuxLibs.addTokens (libs, ", ", String::empty);
  436. exporter.linuxLibs.trim();
  437. exporter.linuxLibs.sort (false);
  438. exporter.linuxLibs.removeDuplicates (false);
  439. }
  440. else if (exporter.isCodeBlocks())
  441. {
  442. const String libs (moduleInfo ["mingwLibs"].toString());
  443. exporter.mingwLibs.addTokens (libs, ", ", String::empty);
  444. exporter.mingwLibs.trim();
  445. exporter.mingwLibs.sort (false);
  446. exporter.mingwLibs.removeDuplicates (false);
  447. }
  448. if (isPluginClient())
  449. {
  450. if (shouldBuildVST (project).getValue()) VSTHelpers::prepareExporter (exporter, projectSaver);
  451. if (shouldBuildAU (project).getValue()) AUHelpers::prepareExporter (exporter, projectSaver);
  452. if (shouldBuildAAX (project).getValue()) AAXHelpers::prepareExporter (exporter, projectSaver, localFolder);
  453. if (shouldBuildRTAS (project).getValue()) RTASHelpers::prepareExporter (exporter, projectSaver, localFolder);
  454. }
  455. }
  456. void LibraryModule::createPropertyEditors (ProjectExporter& exporter, PropertyListBuilder& props) const
  457. {
  458. if (isVSTPluginHost (exporter.getProject()))
  459. VSTHelpers::createVSTPathEditor (exporter, props);
  460. if (isPluginClient())
  461. {
  462. if (shouldBuildVST (exporter.getProject()).getValue()) VSTHelpers::createPropertyEditors (exporter, props);
  463. if (shouldBuildRTAS (exporter.getProject()).getValue()) RTASHelpers::createPropertyEditors (exporter, props);
  464. if (shouldBuildAAX (exporter.getProject()).getValue()) AAXHelpers::createPropertyEditors (exporter, props);
  465. }
  466. }
  467. void LibraryModule::getConfigFlags (Project& project, OwnedArray<Project::ConfigFlag>& flags) const
  468. {
  469. const File header (getInclude (moduleFolder));
  470. jassert (header.exists());
  471. StringArray lines;
  472. header.readLines (lines);
  473. for (int i = 0; i < lines.size(); ++i)
  474. {
  475. String line (lines[i].trim());
  476. if (line.startsWith ("/**") && line.containsIgnoreCase ("Config:"))
  477. {
  478. ScopedPointer <Project::ConfigFlag> config (new Project::ConfigFlag());
  479. config->sourceModuleID = getID();
  480. config->symbol = line.fromFirstOccurrenceOf (":", false, false).trim();
  481. if (config->symbol.length() > 2)
  482. {
  483. ++i;
  484. while (! (lines[i].contains ("*/") || lines[i].contains ("@see")))
  485. {
  486. if (lines[i].trim().isNotEmpty())
  487. config->description = config->description.trim() + " " + lines[i].trim();
  488. ++i;
  489. }
  490. config->description = config->description.upToFirstOccurrenceOf ("*/", false, false);
  491. config->value.referTo (project.getConfigFlag (config->symbol));
  492. flags.add (config.release());
  493. }
  494. }
  495. }
  496. }
  497. //==============================================================================
  498. static bool exporterTargetMatches (const String& test, String target)
  499. {
  500. StringArray validTargets;
  501. validTargets.addTokens (target, ",;", "");
  502. validTargets.trim();
  503. validTargets.removeEmptyStrings();
  504. if (validTargets.size() == 0)
  505. return true;
  506. for (int i = validTargets.size(); --i >= 0;)
  507. {
  508. const String& targetName = validTargets[i];
  509. if (targetName == test
  510. || (targetName.startsWithChar ('!') && test != targetName.substring (1).trimStart()))
  511. return true;
  512. }
  513. return false;
  514. }
  515. bool LibraryModule::fileTargetMatches (ProjectExporter& exporter, const String& target)
  516. {
  517. if (exporter.isXcode()) return exporterTargetMatches ("xcode", target);
  518. if (exporter.isWindows()) return exporterTargetMatches ("msvc", target);
  519. if (exporter.isLinux()) return exporterTargetMatches ("linux", target);
  520. if (exporter.isAndroid()) return exporterTargetMatches ("android", target);
  521. if (exporter.isCodeBlocks()) return exporterTargetMatches ("mingw", target);
  522. return target.isEmpty();
  523. }
  524. void LibraryModule::findWildcardMatches (const File& localModuleFolder, const String& wildcardPath, Array<File>& result) const
  525. {
  526. String path (wildcardPath.upToLastOccurrenceOf ("/", false, false));
  527. String wildCard (wildcardPath.fromLastOccurrenceOf ("/", false, false));
  528. Array<File> tempList;
  529. FileSorter sorter;
  530. DirectoryIterator iter (localModuleFolder.getChildFile (path), false, wildCard);
  531. bool isHiddenFile;
  532. while (iter.next (nullptr, &isHiddenFile, nullptr, nullptr, nullptr, nullptr))
  533. if (! isHiddenFile)
  534. tempList.addSorted (sorter, iter.getFile());
  535. result.addArray (tempList);
  536. }
  537. void LibraryModule::findAndAddCompiledCode (ProjectExporter& exporter, ProjectSaver& projectSaver,
  538. const File& localModuleFolder, Array<File>& result) const
  539. {
  540. const var compileArray (moduleInfo ["compile"]); // careful to keep this alive while the array is in use!
  541. if (const Array<var>* const files = compileArray.getArray())
  542. {
  543. for (int i = 0; i < files->size(); ++i)
  544. {
  545. const var& file = files->getReference(i);
  546. const String filename (file ["file"].toString());
  547. if (filename.isNotEmpty()
  548. && fileTargetMatches (exporter, file ["target"].toString()))
  549. {
  550. const File compiledFile (localModuleFolder.getChildFile (filename));
  551. result.add (compiledFile);
  552. Project::Item item (projectSaver.addFileToGeneratedGroup (compiledFile));
  553. if (file ["warnings"].toString().equalsIgnoreCase ("disabled"))
  554. item.getShouldInhibitWarningsValue() = true;
  555. if (file ["stdcall"])
  556. item.getShouldUseStdCallValue() = true;
  557. }
  558. }
  559. }
  560. }
  561. void LibraryModule::getLocalCompiledFiles (const File& localModuleFolder, Array<File>& result) const
  562. {
  563. const var compileArray (moduleInfo ["compile"]); // careful to keep this alive while the array is in use!
  564. if (const Array<var>* const files = compileArray.getArray())
  565. {
  566. for (int i = 0; i < files->size(); ++i)
  567. {
  568. const var& file = files->getReference(i);
  569. const String filename (file ["file"].toString());
  570. if (filename.isNotEmpty()
  571. #if JUCE_MAC
  572. && exporterTargetMatches ("xcode", file ["target"].toString())
  573. #elif JUCE_WINDOWS
  574. && exporterTargetMatches ("msvc", file ["target"].toString())
  575. #elif JUCE_LINUX
  576. && exporterTargetMatches ("linux", file ["target"].toString())
  577. #endif
  578. )
  579. {
  580. result.add (localModuleFolder.getChildFile (filename));
  581. }
  582. }
  583. }
  584. }
  585. static void addFileWithGroups (Project::Item& group, const RelativePath& file, const String& path)
  586. {
  587. const int slash = path.indexOfChar (File::separator);
  588. if (slash >= 0)
  589. {
  590. const String topLevelGroup (path.substring (0, slash));
  591. const String remainingPath (path.substring (slash + 1));
  592. Project::Item newGroup (group.getOrCreateSubGroup (topLevelGroup));
  593. addFileWithGroups (newGroup, file, remainingPath);
  594. }
  595. else
  596. {
  597. if (! group.containsChildForFile (file))
  598. group.addRelativeFile (file, -1, false);
  599. }
  600. }
  601. void LibraryModule::findBrowseableFiles (const File& localModuleFolder, Array<File>& filesFound) const
  602. {
  603. const var filesArray (moduleInfo ["browse"]);
  604. if (const Array<var>* const files = filesArray.getArray())
  605. for (int i = 0; i < files->size(); ++i)
  606. findWildcardMatches (localModuleFolder, files->getReference(i), filesFound);
  607. }
  608. void LibraryModule::addBrowsableCode (ProjectExporter& exporter, const Array<File>& compiled, const File& localModuleFolder) const
  609. {
  610. if (sourceFiles.size() == 0)
  611. findBrowseableFiles (localModuleFolder, sourceFiles);
  612. Project::Item sourceGroup (Project::Item::createGroup (exporter.getProject(), getID(), "__mainsourcegroup" + getID()));
  613. const RelativePath moduleFromProject (getModuleOrLocalCopyRelativeToProject (exporter, localModuleFolder));
  614. for (int i = 0; i < sourceFiles.size(); ++i)
  615. {
  616. const String pathWithinModule (FileHelpers::getRelativePathFrom (sourceFiles.getReference(i), localModuleFolder));
  617. // (Note: in exporters like MSVC we have to avoid adding the same file twice, even if one of those instances
  618. // is flagged as being excluded from the build, because this overrides the other and it fails to compile)
  619. if (exporter.canCopeWithDuplicateFiles() || ! compiled.contains (sourceFiles.getReference(i)))
  620. addFileWithGroups (sourceGroup,
  621. moduleFromProject.getChildFile (pathWithinModule),
  622. pathWithinModule);
  623. }
  624. sourceGroup.addFile (localModuleFolder.getChildFile (FileHelpers::getRelativePathFrom (moduleFile, moduleFolder)), -1, false);
  625. sourceGroup.addFile (getInclude (localModuleFolder), -1, false);
  626. exporter.getModulesGroup().state.addChild (sourceGroup.state.createCopy(), -1, nullptr);
  627. }