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.

778 lines
29KB

  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. #pragma once
  20. //==============================================================================
  21. class CodeBlocksProjectExporter : public ProjectExporter
  22. {
  23. public:
  24. enum CodeBlocksOS
  25. {
  26. windowsTarget,
  27. linuxTarget
  28. };
  29. //==============================================================================
  30. static const char* getNameWindows() noexcept { return "Code::Blocks (Windows)"; }
  31. static const char* getNameLinux() noexcept { return "Code::Blocks (Linux)"; }
  32. static const char* getName (CodeBlocksOS os) noexcept
  33. {
  34. if (os == windowsTarget) return getNameWindows();
  35. if (os == linuxTarget) return getNameLinux();
  36. // currently no other OSes supported by Codeblocks exporter!
  37. jassertfalse;
  38. return "Code::Blocks (Unknown OS)";
  39. }
  40. //==============================================================================
  41. static const char* getValueTreeTypeName (CodeBlocksOS os)
  42. {
  43. if (os == windowsTarget) return "CODEBLOCKS_WINDOWS";
  44. if (os == linuxTarget) return "CODEBLOCKS_LINUX";
  45. // currently no other OSes supported by Codeblocks exporter!
  46. jassertfalse;
  47. return "CODEBLOCKS_UNKNOWN_OS";
  48. }
  49. //==============================================================================
  50. static String getTargetFolderName (CodeBlocksOS os)
  51. {
  52. if (os == windowsTarget) return "CodeBlocksWindows";
  53. if (os == linuxTarget) return "CodeBlocksLinux";
  54. // currently no other OSes supported by Codeblocks exporter!
  55. jassertfalse;
  56. return "CodeBlocksUnknownOS";
  57. }
  58. //==============================================================================
  59. static CodeBlocksProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  60. {
  61. // this will also import legacy jucer files where CodeBlocks only worked for Windows,
  62. // had valueTreetTypeName "CODEBLOCKS", and there was no OS distinction
  63. if (settings.hasType (getValueTreeTypeName (windowsTarget)) || settings.hasType ("CODEBLOCKS"))
  64. return new CodeBlocksProjectExporter (project, settings, windowsTarget);
  65. if (settings.hasType (getValueTreeTypeName (linuxTarget)))
  66. return new CodeBlocksProjectExporter (project, settings, linuxTarget);
  67. return nullptr;
  68. }
  69. //==============================================================================
  70. CodeBlocksProjectExporter (Project& p, const ValueTree& t, CodeBlocksOS codeBlocksOs)
  71. : ProjectExporter (p, t), os (codeBlocksOs)
  72. {
  73. name = getName (os);
  74. if (getTargetLocationString().isEmpty())
  75. getTargetLocationValue() = getDefaultBuildsRootFolder() + getTargetFolderName (os);
  76. }
  77. //==============================================================================
  78. bool canLaunchProject() override { return false; }
  79. bool launchProject() override { return false; }
  80. bool usesMMFiles() const override { return false; }
  81. bool canCopeWithDuplicateFiles() override { return false; }
  82. bool supportsUserDefinedConfigurations() const override { return true; }
  83. bool isXcode() const override { return false; }
  84. bool isVisualStudio() const override { return false; }
  85. bool isCodeBlocks() const override { return true; }
  86. bool isMakefile() const override { return false; }
  87. bool isAndroidStudio() const override { return false; }
  88. bool isAndroid() const override { return false; }
  89. bool isWindows() const override { return os == windowsTarget; }
  90. bool isLinux() const override { return os == linuxTarget; }
  91. bool isOSX() const override { return false; }
  92. bool isiOS() const override { return false; }
  93. bool supportsTargetType (ProjectType::Target::Type type) const override
  94. {
  95. switch (type)
  96. {
  97. case ProjectType::Target::StandalonePlugIn:
  98. case ProjectType::Target::GUIApp:
  99. case ProjectType::Target::ConsoleApp:
  100. case ProjectType::Target::StaticLibrary:
  101. case ProjectType::Target::SharedCodeTarget:
  102. case ProjectType::Target::AggregateTarget:
  103. case ProjectType::Target::VSTPlugIn:
  104. case ProjectType::Target::DynamicLibrary:
  105. return true;
  106. default:
  107. break;
  108. }
  109. return false;
  110. }
  111. void createExporterProperties (PropertyListBuilder&) override
  112. {
  113. }
  114. //==============================================================================
  115. void create (const OwnedArray<LibraryModule>&) const override
  116. {
  117. const File cbpFile (getTargetFolder().getChildFile (project.getProjectFilenameRoot())
  118. .withFileExtension (".cbp"));
  119. XmlElement xml ("CodeBlocks_project_file");
  120. addVersion (xml);
  121. createProject (*xml.createNewChildElement ("Project"));
  122. writeXmlOrThrow (xml, cbpFile, "UTF-8", 10);
  123. }
  124. //==============================================================================
  125. void addPlatformSpecificSettingsForProjectType (const ProjectType&) override
  126. {
  127. // add shared code target first as order matters for Codeblocks
  128. if (shouldBuildTargetType (ProjectType::Target::SharedCodeTarget))
  129. targets.add (new CodeBlocksTarget (*this, ProjectType::Target::SharedCodeTarget));
  130. //ProjectType::Target::SharedCodeTarget
  131. callForAllSupportedTargets ([this] (ProjectType::Target::Type targetType)
  132. {
  133. if (targetType == ProjectType::Target::SharedCodeTarget)
  134. return;
  135. if (auto* target = new CodeBlocksTarget (*this, targetType))
  136. {
  137. if (targetType == ProjectType::Target::AggregateTarget)
  138. targets.insert (0, target);
  139. else
  140. targets.add (target);
  141. }
  142. });
  143. // If you hit this assert, you tried to generate a project for an exporter
  144. // that does not support any of your targets!
  145. jassert (targets.size() > 0);
  146. }
  147. //==============================================================================
  148. void initialiseDependencyPathValues() override
  149. {
  150. DependencyPathOS pathOS = isLinux() ? TargetOS::linux
  151. : TargetOS::windows;
  152. vst3Path.referTo (Value (new DependencyPathValueSource (getSetting (Ids::vst3Folder), Ids::vst3Path, pathOS)));
  153. if (! isLinux())
  154. {
  155. aaxPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::aaxFolder), Ids::aaxPath, pathOS)));
  156. rtasPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::rtasFolder), Ids::rtasPath, pathOS)));
  157. }
  158. }
  159. private:
  160. //==============================================================================
  161. class CodeBlocksBuildConfiguration : public BuildConfiguration
  162. {
  163. public:
  164. CodeBlocksBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  165. : BuildConfiguration (p, settings, e)
  166. {
  167. if (getArchitectureType().toString().isEmpty())
  168. getArchitectureType() = static_cast<const char* const> ("-m64");
  169. }
  170. Value getArchitectureType()
  171. {
  172. const auto archID = exporter.isWindows() ? Ids::windowsCodeBlocksArchitecture
  173. : Ids::linuxCodeBlocksArchitecture;
  174. return getValue (archID);
  175. }
  176. var getArchitectureTypeVar() const
  177. {
  178. const auto archID = exporter.isWindows() ? Ids::windowsCodeBlocksArchitecture
  179. : Ids::linuxCodeBlocksArchitecture;
  180. return config [archID];
  181. }
  182. var getDefaultOptimisationLevel() const override { return var ((int) (isDebug() ? gccO0 : gccO3)); }
  183. void createConfigProperties (PropertyListBuilder& props) override
  184. {
  185. addGCCOptimisationProperty (props);
  186. static const char* const archNames[] = { "32-bit (-m32)", "64-bit (-m64)", "ARM v6", "ARM v7" };
  187. const var archFlags[] = { "-m32", "-m64", "-march=armv6", "-march=armv7" };
  188. props.add (new ChoicePropertyComponent (getArchitectureType(), "Architecture",
  189. StringArray (archNames, numElementsInArray (archNames)),
  190. Array<var> (archFlags, numElementsInArray (archFlags))));
  191. }
  192. String getModuleLibraryArchName() const override
  193. {
  194. const String archFlag = getArchitectureTypeVar();
  195. const auto prefix = String ("-march=");
  196. if (archFlag.startsWith (prefix))
  197. return String ("/") + archFlag.substring (prefix.length());
  198. else if (archFlag == "-m64")
  199. return "/x86_64";
  200. else if (archFlag == "-m32")
  201. return "/i386";
  202. jassertfalse;
  203. return {};
  204. }
  205. };
  206. BuildConfiguration::Ptr createBuildConfig (const ValueTree& tree) const override
  207. {
  208. return new CodeBlocksBuildConfiguration (project, tree, *this);
  209. }
  210. //==============================================================================
  211. class CodeBlocksTarget : public ProjectType::Target
  212. {
  213. public:
  214. CodeBlocksTarget (CodeBlocksProjectExporter&, ProjectType::Target::Type typeToUse)
  215. : ProjectType::Target (typeToUse)
  216. {}
  217. String getTargetNameForConfiguration (const BuildConfiguration& config) const
  218. {
  219. if (type == ProjectType::Target::AggregateTarget)
  220. return config.getName();
  221. return getName() + String (" | ") + config.getName();
  222. }
  223. String getTargetSuffix() const
  224. {
  225. auto fileType = getTargetFileType();
  226. switch (fileType)
  227. {
  228. case executable: return {};
  229. case staticLibrary: return ".a";
  230. case sharedLibraryOrDLL: return ".so";
  231. case pluginBundle:
  232. switch (type)
  233. {
  234. case VST3PlugIn: return ".vst3";
  235. case VSTPlugIn: return ".so";
  236. default: break;
  237. }
  238. return ".so";
  239. default:
  240. break;
  241. }
  242. return {};
  243. }
  244. bool isDynamicLibrary() const
  245. {
  246. return (type == DynamicLibrary || type == VST3PlugIn
  247. || type == VSTPlugIn || type == AAXPlugIn);
  248. }
  249. };
  250. //==============================================================================
  251. StringArray getPackages() const
  252. {
  253. StringArray result (linuxPackages);
  254. static String guiExtrasModule ("juce_gui_extra");
  255. if (project.getModules().isModuleEnabled (guiExtrasModule)
  256. && project.isConfigFlagEnabled ("JUCE_WEB_BROWSER", true))
  257. {
  258. result.add ("webkit2gtk-4.0");
  259. result.add ("gtk+-x11-3.0");
  260. }
  261. result.removeDuplicates (false);
  262. return result;
  263. }
  264. void addVersion (XmlElement& xml) const
  265. {
  266. XmlElement* fileVersion = xml.createNewChildElement ("FileVersion");
  267. fileVersion->setAttribute ("major", 1);
  268. fileVersion->setAttribute ("minor", 6);
  269. }
  270. void addOptions (XmlElement& xml) const
  271. {
  272. xml.createNewChildElement ("Option")->setAttribute ("title", project.getTitle());
  273. xml.createNewChildElement ("Option")->setAttribute ("pch_mode", 2);
  274. xml.createNewChildElement ("Option")->setAttribute ("compiler", "gcc");
  275. }
  276. StringArray getDefines (const BuildConfiguration& config, CodeBlocksTarget& target) const
  277. {
  278. StringPairArray defines;
  279. if (isWindows())
  280. {
  281. defines.set ("__MINGW__", "1");
  282. defines.set ("__MINGW_EXTENSION", String());
  283. }
  284. else
  285. {
  286. defines.set ("LINUX", "1");
  287. }
  288. if (config.isDebug())
  289. {
  290. defines.set ("DEBUG", "1");
  291. defines.set ("_DEBUG", "1");
  292. }
  293. else
  294. {
  295. defines.set ("NDEBUG", "1");
  296. }
  297. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config, target.type));
  298. StringArray defs;
  299. for (int i = 0; i < defines.size(); ++i)
  300. defs.add (defines.getAllKeys()[i] + "=" + defines.getAllValues()[i]);
  301. return getCleanedStringArray (defs);
  302. }
  303. StringArray getCompilerFlags (const BuildConfiguration& config, CodeBlocksTarget& target) const
  304. {
  305. StringArray flags;
  306. if (const auto codeBlocksConfig = dynamic_cast<const CodeBlocksBuildConfiguration*> (&config))
  307. flags.add (codeBlocksConfig->getArchitectureTypeVar());
  308. flags.add ("-O" + config.getGCCOptimisationFlag());
  309. {
  310. auto cppStandard = config.project.getCppStandardValue().toString();
  311. if (cppStandard == "latest")
  312. cppStandard = "1z";
  313. cppStandard = "-std=" + String (shouldUseGNUExtensions() ? "gnu++" : "c++") + cppStandard;
  314. flags.add (cppStandard);
  315. }
  316. flags.add ("-mstackrealign");
  317. if (config.isDebug())
  318. flags.add ("-g");
  319. flags.addTokens (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim(),
  320. " \n", "\"'");
  321. {
  322. const StringArray defines (getDefines (config, target));
  323. for (int i = 0; i < defines.size(); ++i)
  324. {
  325. String def (defines[i]);
  326. if (! def.containsChar ('='))
  327. def << '=';
  328. flags.add ("-D" + def);
  329. }
  330. }
  331. if (config.exporter.isLinux())
  332. {
  333. if (target.isDynamicLibrary() || getProject().getProjectType().isAudioPlugin())
  334. flags.add ("-fPIC");
  335. const auto packages = getPackages();
  336. if (packages.size() > 0)
  337. {
  338. auto pkgconfigFlags = String ("`pkg-config --cflags");
  339. for (auto p : packages)
  340. pkgconfigFlags << " " << p;
  341. pkgconfigFlags << "`";
  342. flags.add (pkgconfigFlags);
  343. }
  344. if (linuxLibs.contains("pthread"))
  345. flags.add ("-pthread");
  346. }
  347. return getCleanedStringArray (flags);
  348. }
  349. StringArray getLinkerFlags (const BuildConfiguration& config, CodeBlocksTarget& target) const
  350. {
  351. StringArray flags (makefileExtraLinkerFlags);
  352. if (const auto codeBlocksConfig = dynamic_cast<const CodeBlocksBuildConfiguration*> (&config))
  353. flags.add (codeBlocksConfig->getArchitectureTypeVar());
  354. if (! config.isDebug())
  355. flags.add ("-s");
  356. flags.addTokens (replacePreprocessorTokens (config, getExtraLinkerFlagsString()).trim(),
  357. " \n", "\"'");
  358. if (getProject().getProjectType().isAudioPlugin() && target.type != ProjectType::Target::SharedCodeTarget)
  359. flags.add ("-l" + config.getTargetBinaryNameString());
  360. const auto packages = getPackages();
  361. if (config.exporter.isLinux() && packages.size() > 0)
  362. {
  363. if (target.isDynamicLibrary())
  364. flags.add ("-shared");
  365. auto pkgconfigLibs = String ("`pkg-config --libs");
  366. for (auto p : packages)
  367. pkgconfigLibs << " " << p;
  368. pkgconfigLibs << "`";
  369. flags.add (pkgconfigLibs);
  370. }
  371. return getCleanedStringArray (flags);
  372. }
  373. StringArray getIncludePaths (const BuildConfiguration& config) const
  374. {
  375. StringArray paths;
  376. paths.add (".");
  377. paths.addArray (extraSearchPaths);
  378. paths.addArray (config.getHeaderSearchPaths());
  379. if (! isWindows())
  380. {
  381. paths.add ("/usr/include/freetype2");
  382. // Replace ~ character with $(HOME) environment variable
  383. for (auto& path : paths)
  384. path = path.replace ("~", "$(HOME)");
  385. }
  386. return getCleanedStringArray (paths);
  387. }
  388. static int getTypeIndex (const ProjectType::Target::Type& type)
  389. {
  390. switch (type)
  391. {
  392. case ProjectType::Target::GUIApp:
  393. case ProjectType::Target::StandalonePlugIn:
  394. return 0;
  395. case ProjectType::Target::ConsoleApp:
  396. return 1;
  397. case ProjectType::Target::StaticLibrary:
  398. case ProjectType::Target::SharedCodeTarget:
  399. return 2;
  400. case ProjectType::Target::DynamicLibrary:
  401. case ProjectType::Target::VSTPlugIn:
  402. case ProjectType::Target::VST3PlugIn:
  403. return 3;
  404. default:
  405. break;
  406. }
  407. return 0;
  408. }
  409. String getOutputPathForTarget (CodeBlocksTarget& target, const BuildConfiguration& config) const
  410. {
  411. String outputPath;
  412. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  413. {
  414. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  415. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  416. outputPath = config.getTargetBinaryRelativePathString();
  417. }
  418. else
  419. {
  420. outputPath ="bin/" + File::createLegalFileName (config.getName().trim());
  421. }
  422. return outputPath + "/" + replacePreprocessorTokens (config, config.getTargetBinaryNameString() + target.getTargetSuffix());
  423. }
  424. String getSharedCodePath (const BuildConfiguration& config) const
  425. {
  426. const String outputPath = getOutputPathForTarget (getTargetWithType (ProjectType::Target::SharedCodeTarget), config);
  427. RelativePath path (outputPath, RelativePath::buildTargetFolder);
  428. const String autoPrefixedFilename = "lib" + path.getFileName();
  429. return path.getParentDirectory().getChildFile (autoPrefixedFilename).toUnixStyle();
  430. }
  431. void createBuildTarget (XmlElement& xml, CodeBlocksTarget& target, const BuildConfiguration& config) const
  432. {
  433. xml.setAttribute ("title", target.getTargetNameForConfiguration (config));
  434. {
  435. XmlElement* output = xml.createNewChildElement ("Option");
  436. output->setAttribute ("output", getOutputPathForTarget (target, config));
  437. const bool keepPrefix = (target.type == ProjectType::Target::VSTPlugIn || target.type == ProjectType::Target::VST3PlugIn
  438. || target.type == ProjectType::Target::AAXPlugIn || target.type == ProjectType::Target::RTASPlugIn);
  439. output->setAttribute ("prefix_auto", keepPrefix ? 0 : 1);
  440. output->setAttribute ("extension_auto", 0);
  441. }
  442. xml.createNewChildElement ("Option")
  443. ->setAttribute ("object_output", "obj/" + File::createLegalFileName (config.getName().trim()));
  444. xml.createNewChildElement ("Option")->setAttribute ("type", getTypeIndex (target.type));
  445. xml.createNewChildElement ("Option")->setAttribute ("compiler", "gcc");
  446. if (getProject().getProjectType().isAudioPlugin() && target.type != ProjectType::Target::SharedCodeTarget)
  447. xml.createNewChildElement ("Option")->setAttribute ("external_deps", getSharedCodePath (config));
  448. {
  449. XmlElement* const compiler = xml.createNewChildElement ("Compiler");
  450. {
  451. const StringArray compilerFlags (getCompilerFlags (config, target));
  452. for (auto flag : compilerFlags)
  453. setAddOption (*compiler, "option", flag);
  454. }
  455. {
  456. const StringArray includePaths (getIncludePaths (config));
  457. for (auto path : includePaths)
  458. setAddOption (*compiler, "directory", path);
  459. }
  460. }
  461. {
  462. XmlElement* const linker = xml.createNewChildElement ("Linker");
  463. const StringArray linkerFlags (getLinkerFlags (config, target));
  464. for (auto flag : linkerFlags)
  465. setAddOption (*linker, "option", flag);
  466. const StringArray& libs = isWindows() ? mingwLibs : linuxLibs;
  467. for (auto lib : libs)
  468. setAddOption (*linker, "library", lib);
  469. StringArray librarySearchPaths (config.getLibrarySearchPaths());
  470. if (getProject().getProjectType().isAudioPlugin() && target.type != ProjectType::Target::SharedCodeTarget)
  471. librarySearchPaths.add (RelativePath (getSharedCodePath (config), RelativePath::buildTargetFolder).getParentDirectory().toUnixStyle());
  472. for (auto path : librarySearchPaths)
  473. {
  474. setAddOption (*linker, "directory", replacePreprocessorDefs (getAllPreprocessorDefs(), path));
  475. }
  476. }
  477. }
  478. void addBuild (XmlElement& xml) const
  479. {
  480. XmlElement* const build = xml.createNewChildElement ("Build");
  481. for (ConstConfigIterator config (*this); config.next();)
  482. {
  483. for (auto target : targets)
  484. if (target->type != ProjectType::Target::AggregateTarget)
  485. createBuildTarget (*build->createNewChildElement ("Target"), *target, *config);
  486. }
  487. }
  488. void addVirtualTargets (XmlElement& xml) const
  489. {
  490. XmlElement* const virtualTargets = xml.createNewChildElement ("VirtualTargets");
  491. for (ConstConfigIterator config (*this); config.next();)
  492. {
  493. StringArray allTargets;
  494. for (auto target : targets)
  495. if (target->type != ProjectType::Target::AggregateTarget)
  496. allTargets.add (target->getTargetNameForConfiguration (*config));
  497. for (auto target : targets)
  498. {
  499. if (target->type == ProjectType::Target::AggregateTarget)
  500. {
  501. auto* configTarget = virtualTargets->createNewChildElement ("Add");
  502. configTarget->setAttribute ("alias", config->getName());
  503. configTarget->setAttribute ("targets", allTargets.joinIntoString (";"));
  504. }
  505. }
  506. }
  507. }
  508. void addProjectCompilerOptions (XmlElement& xml) const
  509. {
  510. XmlElement* const compiler = xml.createNewChildElement ("Compiler");
  511. setAddOption (*compiler, "option", "-Wall");
  512. setAddOption (*compiler, "option", "-Wno-strict-aliasing");
  513. setAddOption (*compiler, "option", "-Wno-strict-overflow");
  514. }
  515. void addProjectLinkerOptions (XmlElement& xml) const
  516. {
  517. XmlElement* const linker = xml.createNewChildElement ("Linker");
  518. StringArray libs;
  519. if (isWindows())
  520. {
  521. static const char* defaultLibs[] = { "gdi32", "user32", "kernel32", "comctl32" };
  522. libs = StringArray (defaultLibs, numElementsInArray (defaultLibs));
  523. }
  524. libs.addTokens (getExternalLibrariesString(), ";\n", "\"'");
  525. libs = getCleanedStringArray (libs);
  526. for (int i = 0; i < libs.size(); ++i)
  527. setAddOption (*linker, "library", replacePreprocessorDefs (getAllPreprocessorDefs(), libs[i]));
  528. }
  529. CodeBlocksTarget& getTargetWithType (ProjectType::Target::Type type) const
  530. {
  531. CodeBlocksTarget* nonAggregrateTarget = nullptr;
  532. for (auto* target : targets)
  533. {
  534. if (target->type == type)
  535. return *target;
  536. if (target->type != ProjectType::Target::AggregateTarget)
  537. nonAggregrateTarget = target;
  538. }
  539. // this project has no valid targets
  540. jassert (nonAggregrateTarget != nullptr);
  541. return *nonAggregrateTarget;
  542. }
  543. // Returns SharedCode target for multi-target projects, otherwise it returns
  544. // the single target
  545. CodeBlocksTarget& getMainTarget() const
  546. {
  547. if (getProject().getProjectType().isAudioPlugin())
  548. return getTargetWithType (ProjectType::Target::SharedCodeTarget);
  549. for (auto* target : targets)
  550. if (target->type != ProjectType::Target::AggregateTarget)
  551. return *target;
  552. jassertfalse;
  553. return *targets[0];
  554. }
  555. CodeBlocksTarget& getTargetForProjectItem (const Project::Item& projectItem) const
  556. {
  557. if (getProject().getProjectType().isAudioPlugin())
  558. {
  559. if (! projectItem.shouldBeCompiled())
  560. return getTargetWithType (ProjectType::Target::SharedCodeTarget);
  561. return getTargetWithType (getProject().getTargetTypeFromFilePath (projectItem.getFile(), true));
  562. }
  563. return getMainTarget();
  564. }
  565. void addCompileUnits (const Project::Item& projectItem, XmlElement& xml) const
  566. {
  567. if (projectItem.isGroup())
  568. {
  569. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  570. addCompileUnits (projectItem.getChild(i), xml);
  571. }
  572. else if (projectItem.shouldBeAddedToTargetProject())
  573. {
  574. const RelativePath file (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  575. XmlElement* unit = xml.createNewChildElement ("Unit");
  576. unit->setAttribute ("filename", file.toUnixStyle());
  577. for (ConstConfigIterator config (*this); config.next();)
  578. {
  579. const String& targetName = getTargetForProjectItem (projectItem).getTargetNameForConfiguration (*config);
  580. unit->createNewChildElement ("Option")->setAttribute ("target", targetName);
  581. }
  582. if (! projectItem.shouldBeCompiled())
  583. {
  584. unit->createNewChildElement ("Option")->setAttribute ("compile", 0);
  585. unit->createNewChildElement ("Option")->setAttribute ("link", 0);
  586. }
  587. }
  588. }
  589. void addCompileUnits (XmlElement& xml) const
  590. {
  591. for (int i = 0; i < getAllGroups().size(); ++i)
  592. addCompileUnits (getAllGroups().getReference(i), xml);
  593. }
  594. void createProject (XmlElement& xml) const
  595. {
  596. addOptions (xml);
  597. addBuild (xml);
  598. addVirtualTargets (xml);
  599. addProjectCompilerOptions (xml);
  600. addProjectLinkerOptions (xml);
  601. addCompileUnits (xml);
  602. }
  603. void setAddOption (XmlElement& xml, const String& nm, const String& value) const
  604. {
  605. xml.createNewChildElement ("Add")->setAttribute (nm, value);
  606. }
  607. CodeBlocksOS os;
  608. OwnedArray<CodeBlocksTarget> targets;
  609. JUCE_DECLARE_NON_COPYABLE (CodeBlocksProjectExporter)
  610. };