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.

749 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. #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. void addVersion (XmlElement& xml) const
  252. {
  253. XmlElement* fileVersion = xml.createNewChildElement ("FileVersion");
  254. fileVersion->setAttribute ("major", 1);
  255. fileVersion->setAttribute ("minor", 6);
  256. }
  257. void addOptions (XmlElement& xml) const
  258. {
  259. xml.createNewChildElement ("Option")->setAttribute ("title", project.getTitle());
  260. xml.createNewChildElement ("Option")->setAttribute ("pch_mode", 2);
  261. xml.createNewChildElement ("Option")->setAttribute ("compiler", "gcc");
  262. }
  263. StringArray getDefines (const BuildConfiguration& config, CodeBlocksTarget& target) const
  264. {
  265. StringPairArray defines;
  266. if (isCodeBlocks() && isWindows())
  267. {
  268. defines.set ("__MINGW__", "1");
  269. defines.set ("__MINGW_EXTENSION", String());
  270. }
  271. else
  272. {
  273. defines.set ("LINUX", "1");
  274. }
  275. if (config.isDebug())
  276. {
  277. defines.set ("DEBUG", "1");
  278. defines.set ("_DEBUG", "1");
  279. }
  280. else
  281. {
  282. defines.set ("NDEBUG", "1");
  283. }
  284. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config, target.type));
  285. StringArray defs;
  286. for (int i = 0; i < defines.size(); ++i)
  287. defs.add (defines.getAllKeys()[i] + "=" + defines.getAllValues()[i]);
  288. return getCleanedStringArray (defs);
  289. }
  290. StringArray getCompilerFlags (const BuildConfiguration& config, CodeBlocksTarget& target) const
  291. {
  292. StringArray flags;
  293. if (const auto codeBlocksConfig = dynamic_cast<const CodeBlocksBuildConfiguration*> (&config))
  294. flags.add (codeBlocksConfig->getArchitectureTypeVar());
  295. flags.add ("-O" + config.getGCCOptimisationFlag());
  296. {
  297. auto cppStandard = config.project.getCppStandardValue().toString();
  298. if (cppStandard == "latest")
  299. cppStandard = "1z";
  300. cppStandard = "-std=" + String (shouldUseGNUExtensions() ? "gnu++" : "c++") + cppStandard;
  301. flags.add (cppStandard);
  302. }
  303. flags.add ("-mstackrealign");
  304. if (config.isDebug())
  305. flags.add ("-g");
  306. flags.addTokens (replacePreprocessorTokens (config, getExtraCompilerFlagsString()).trim(),
  307. " \n", "\"'");
  308. {
  309. const StringArray defines (getDefines (config, target));
  310. for (int i = 0; i < defines.size(); ++i)
  311. {
  312. String def (defines[i]);
  313. if (! def.containsChar ('='))
  314. def << '=';
  315. flags.add ("-D" + def);
  316. }
  317. }
  318. if (config.exporter.isLinux())
  319. {
  320. if (target.isDynamicLibrary() || getProject().getProjectType().isAudioPlugin())
  321. flags.add ("-fPIC");
  322. if (linuxPackages.size() > 0)
  323. {
  324. auto pkgconfigFlags = String ("`pkg-config --cflags");
  325. for (auto p : linuxPackages)
  326. pkgconfigFlags << " " << p;
  327. pkgconfigFlags << "`";
  328. flags.add (pkgconfigFlags);
  329. }
  330. if (linuxLibs.contains("pthread"))
  331. flags.add ("-pthread");
  332. }
  333. return getCleanedStringArray (flags);
  334. }
  335. StringArray getLinkerFlags (const BuildConfiguration& config, CodeBlocksTarget& target) const
  336. {
  337. StringArray flags (makefileExtraLinkerFlags);
  338. if (const auto codeBlocksConfig = dynamic_cast<const CodeBlocksBuildConfiguration*> (&config))
  339. flags.add (codeBlocksConfig->getArchitectureTypeVar());
  340. if (! config.isDebug())
  341. flags.add ("-s");
  342. flags.addTokens (replacePreprocessorTokens (config, getExtraLinkerFlagsString()).trim(),
  343. " \n", "\"'");
  344. if (getProject().getProjectType().isAudioPlugin() && target.type != ProjectType::Target::SharedCodeTarget)
  345. flags.add ("-l" + config.getTargetBinaryNameString());
  346. if (config.exporter.isLinux() && linuxPackages.size() > 0)
  347. {
  348. if (target.isDynamicLibrary())
  349. flags.add ("-shared");
  350. auto pkgconfigLibs = String ("`pkg-config --libs");
  351. for (auto p : linuxPackages)
  352. pkgconfigLibs << " " << p;
  353. pkgconfigLibs << "`";
  354. flags.add (pkgconfigLibs);
  355. }
  356. return getCleanedStringArray (flags);
  357. }
  358. StringArray getIncludePaths (const BuildConfiguration& config) const
  359. {
  360. StringArray paths;
  361. paths.add (".");
  362. paths.addArray (extraSearchPaths);
  363. paths.addArray (config.getHeaderSearchPaths());
  364. if (! (isCodeBlocks() && isWindows()))
  365. paths.add ("/usr/include/freetype2");
  366. return getCleanedStringArray (paths);
  367. }
  368. static int getTypeIndex (const ProjectType::Target::Type& type)
  369. {
  370. switch (type)
  371. {
  372. case ProjectType::Target::GUIApp:
  373. case ProjectType::Target::StandalonePlugIn:
  374. return 0;
  375. case ProjectType::Target::ConsoleApp:
  376. return 1;
  377. case ProjectType::Target::StaticLibrary:
  378. case ProjectType::Target::SharedCodeTarget:
  379. return 2;
  380. case ProjectType::Target::DynamicLibrary:
  381. case ProjectType::Target::VSTPlugIn:
  382. case ProjectType::Target::VST3PlugIn:
  383. return 3;
  384. default:
  385. break;
  386. }
  387. return 0;
  388. }
  389. String getOutputPathForTarget (CodeBlocksTarget& target, const BuildConfiguration& config) const
  390. {
  391. String outputPath;
  392. if (config.getTargetBinaryRelativePathString().isNotEmpty())
  393. {
  394. RelativePath binaryPath (config.getTargetBinaryRelativePathString(), RelativePath::projectFolder);
  395. binaryPath = binaryPath.rebased (projectFolder, getTargetFolder(), RelativePath::buildTargetFolder);
  396. outputPath = config.getTargetBinaryRelativePathString();
  397. }
  398. else
  399. {
  400. outputPath ="bin/" + File::createLegalFileName (config.getName().trim());
  401. }
  402. return outputPath + "/" + replacePreprocessorTokens (config, config.getTargetBinaryNameString() + target.getTargetSuffix());
  403. }
  404. String getSharedCodePath (const BuildConfiguration& config) const
  405. {
  406. const String outputPath = getOutputPathForTarget (getTargetWithType (ProjectType::Target::SharedCodeTarget), config);
  407. RelativePath path (outputPath, RelativePath::buildTargetFolder);
  408. const String autoPrefixedFilename = "lib" + path.getFileName();
  409. return path.getParentDirectory().getChildFile (autoPrefixedFilename).toUnixStyle();
  410. }
  411. void createBuildTarget (XmlElement& xml, CodeBlocksTarget& target, const BuildConfiguration& config) const
  412. {
  413. xml.setAttribute ("title", target.getTargetNameForConfiguration (config));
  414. {
  415. XmlElement* output = xml.createNewChildElement ("Option");
  416. output->setAttribute ("output", getOutputPathForTarget (target, config));
  417. const bool keepPrefix = (target.type == ProjectType::Target::VSTPlugIn || target.type == ProjectType::Target::VST3PlugIn
  418. || target.type == ProjectType::Target::AAXPlugIn || target.type == ProjectType::Target::RTASPlugIn);
  419. output->setAttribute ("prefix_auto", keepPrefix ? 0 : 1);
  420. output->setAttribute ("extension_auto", 0);
  421. }
  422. xml.createNewChildElement ("Option")
  423. ->setAttribute ("object_output", "obj/" + File::createLegalFileName (config.getName().trim()));
  424. xml.createNewChildElement ("Option")->setAttribute ("type", getTypeIndex (target.type));
  425. xml.createNewChildElement ("Option")->setAttribute ("compiler", "gcc");
  426. if (getProject().getProjectType().isAudioPlugin() && target.type != ProjectType::Target::SharedCodeTarget)
  427. xml.createNewChildElement ("Option")->setAttribute ("external_deps", getSharedCodePath (config));
  428. {
  429. XmlElement* const compiler = xml.createNewChildElement ("Compiler");
  430. {
  431. const StringArray compilerFlags (getCompilerFlags (config, target));
  432. for (auto flag : compilerFlags)
  433. setAddOption (*compiler, "option", flag);
  434. }
  435. {
  436. const StringArray includePaths (getIncludePaths (config));
  437. for (auto path : includePaths)
  438. setAddOption (*compiler, "directory", path);
  439. }
  440. }
  441. {
  442. XmlElement* const linker = xml.createNewChildElement ("Linker");
  443. const StringArray linkerFlags (getLinkerFlags (config, target));
  444. for (auto flag : linkerFlags)
  445. setAddOption (*linker, "option", flag);
  446. const StringArray& libs = isWindows() ? mingwLibs : linuxLibs;
  447. for (auto lib : libs)
  448. setAddOption (*linker, "library", lib);
  449. StringArray librarySearchPaths (config.getLibrarySearchPaths());
  450. if (getProject().getProjectType().isAudioPlugin() && target.type != ProjectType::Target::SharedCodeTarget)
  451. librarySearchPaths.add (RelativePath (getSharedCodePath (config), RelativePath::buildTargetFolder).getParentDirectory().toUnixStyle());
  452. for (auto path : librarySearchPaths)
  453. {
  454. setAddOption (*linker, "directory", replacePreprocessorDefs (getAllPreprocessorDefs(), path));
  455. }
  456. }
  457. }
  458. void addBuild (XmlElement& xml) const
  459. {
  460. XmlElement* const build = xml.createNewChildElement ("Build");
  461. for (ConstConfigIterator config (*this); config.next();)
  462. {
  463. for (auto target : targets)
  464. if (target->type != ProjectType::Target::AggregateTarget)
  465. createBuildTarget (*build->createNewChildElement ("Target"), *target, *config);
  466. }
  467. }
  468. void addVirtualTargets (XmlElement& xml) const
  469. {
  470. XmlElement* const virtualTargets = xml.createNewChildElement ("VirtualTargets");
  471. for (ConstConfigIterator config (*this); config.next();)
  472. {
  473. StringArray allTargets;
  474. for (auto target : targets)
  475. if (target->type != ProjectType::Target::AggregateTarget)
  476. allTargets.add (target->getTargetNameForConfiguration (*config));
  477. for (auto target : targets)
  478. {
  479. if (target->type == ProjectType::Target::AggregateTarget)
  480. {
  481. auto* configTarget = virtualTargets->createNewChildElement ("Add");
  482. configTarget->setAttribute ("alias", config->getName());
  483. configTarget->setAttribute ("targets", allTargets.joinIntoString (";"));
  484. }
  485. }
  486. }
  487. }
  488. void addProjectCompilerOptions (XmlElement& xml) const
  489. {
  490. XmlElement* const compiler = xml.createNewChildElement ("Compiler");
  491. setAddOption (*compiler, "option", "-Wall");
  492. setAddOption (*compiler, "option", "-Wno-strict-aliasing");
  493. setAddOption (*compiler, "option", "-Wno-strict-overflow");
  494. }
  495. void addProjectLinkerOptions (XmlElement& xml) const
  496. {
  497. XmlElement* const linker = xml.createNewChildElement ("Linker");
  498. StringArray libs;
  499. if (isWindows())
  500. {
  501. static const char* defaultLibs[] = { "gdi32", "user32", "kernel32", "comctl32" };
  502. libs = StringArray (defaultLibs, numElementsInArray (defaultLibs));
  503. }
  504. libs.addTokens (getExternalLibrariesString(), ";\n", "\"'");
  505. libs = getCleanedStringArray (libs);
  506. for (int i = 0; i < libs.size(); ++i)
  507. setAddOption (*linker, "library", replacePreprocessorDefs (getAllPreprocessorDefs(), libs[i]));
  508. }
  509. CodeBlocksTarget& getTargetWithType (ProjectType::Target::Type type) const
  510. {
  511. CodeBlocksTarget* nonAggregrateTarget = nullptr;
  512. for (auto* target : targets)
  513. {
  514. if (target->type == type)
  515. return *target;
  516. if (target->type != ProjectType::Target::AggregateTarget)
  517. nonAggregrateTarget = target;
  518. }
  519. // this project has no valid targets
  520. jassert (nonAggregrateTarget != nullptr);
  521. return *nonAggregrateTarget;
  522. }
  523. // Returns SharedCode target for multi-target projects, otherwise it returns
  524. // the single target
  525. CodeBlocksTarget& getMainTarget() const
  526. {
  527. if (getProject().getProjectType().isAudioPlugin())
  528. return getTargetWithType (ProjectType::Target::SharedCodeTarget);
  529. for (auto* target : targets)
  530. if (target->type != ProjectType::Target::AggregateTarget)
  531. return *target;
  532. jassertfalse;
  533. return *targets[0];
  534. }
  535. CodeBlocksTarget& getTargetForProjectItem (const Project::Item& projectItem) const
  536. {
  537. if (getProject().getProjectType().isAudioPlugin())
  538. {
  539. if (! projectItem.shouldBeCompiled())
  540. return getTargetWithType (ProjectType::Target::SharedCodeTarget);
  541. return getTargetWithType (getProject().getTargetTypeFromFilePath (projectItem.getFile(), true));
  542. }
  543. return getMainTarget();
  544. }
  545. void addCompileUnits (const Project::Item& projectItem, XmlElement& xml) const
  546. {
  547. if (projectItem.isGroup())
  548. {
  549. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  550. addCompileUnits (projectItem.getChild(i), xml);
  551. }
  552. else if (projectItem.shouldBeAddedToTargetProject())
  553. {
  554. const RelativePath file (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder);
  555. XmlElement* unit = xml.createNewChildElement ("Unit");
  556. unit->setAttribute ("filename", file.toUnixStyle());
  557. for (ConstConfigIterator config (*this); config.next();)
  558. {
  559. const String& targetName = getTargetForProjectItem (projectItem).getTargetNameForConfiguration (*config);
  560. unit->createNewChildElement ("Option")->setAttribute ("target", targetName);
  561. }
  562. if (! projectItem.shouldBeCompiled())
  563. {
  564. unit->createNewChildElement ("Option")->setAttribute ("compile", 0);
  565. unit->createNewChildElement ("Option")->setAttribute ("link", 0);
  566. }
  567. }
  568. }
  569. void addCompileUnits (XmlElement& xml) const
  570. {
  571. for (int i = 0; i < getAllGroups().size(); ++i)
  572. addCompileUnits (getAllGroups().getReference(i), xml);
  573. }
  574. void createProject (XmlElement& xml) const
  575. {
  576. addOptions (xml);
  577. addBuild (xml);
  578. addVirtualTargets (xml);
  579. addProjectCompilerOptions (xml);
  580. addProjectLinkerOptions (xml);
  581. addCompileUnits (xml);
  582. }
  583. void setAddOption (XmlElement& xml, const String& nm, const String& value) const
  584. {
  585. xml.createNewChildElement ("Add")->setAttribute (nm, value);
  586. }
  587. CodeBlocksOS os;
  588. OwnedArray<CodeBlocksTarget> targets;
  589. JUCE_DECLARE_NON_COPYABLE (CodeBlocksProjectExporter)
  590. };