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.

745 lines
28KB

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