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.

1217 lines
57KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. #include "jucer_ProjectExport_CodeBlocks.h"
  20. #include "jucer_ProjectExport_Make.h"
  21. #include "jucer_ProjectExport_Xcode.h"
  22. //==============================================================================
  23. class CLionProjectExporter : public ProjectExporter
  24. {
  25. protected:
  26. //==============================================================================
  27. class CLionBuildConfiguration : public BuildConfiguration
  28. {
  29. public:
  30. CLionBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  31. : BuildConfiguration (p, settings, e)
  32. {
  33. }
  34. void createConfigProperties (PropertyListBuilder&) override {}
  35. String getModuleLibraryArchName() const override { return {}; }
  36. };
  37. BuildConfiguration::Ptr createBuildConfig (const ValueTree& tree) const override
  38. {
  39. return *new CLionBuildConfiguration (project, tree, *this);
  40. }
  41. public:
  42. //==============================================================================
  43. static String getDisplayName() { return "CLion [Deprecated]"; }
  44. static String getValueTreeTypeName() { return "CLION"; }
  45. static String getTargetFolderName() { return "CLion"; }
  46. Identifier getExporterIdentifier() const override { return getValueTreeTypeName(); }
  47. static CLionProjectExporter* createForSettings (Project& projectToUse, const ValueTree& settingsToUse)
  48. {
  49. if (settingsToUse.hasType (getValueTreeTypeName()))
  50. return new CLionProjectExporter (projectToUse, settingsToUse);
  51. return nullptr;
  52. }
  53. static bool isExporterSupported (const ProjectExporter& exporter)
  54. {
  55. return exporter.isMakefile()
  56. || (exporter.isXcode() && ! exporter.isiOS())
  57. || (exporter.isCodeBlocks() && exporter.isWindows());
  58. }
  59. //==============================================================================
  60. CLionProjectExporter (Project& p, const ValueTree& t) : ProjectExporter (p, t)
  61. {
  62. name = getDisplayName();
  63. targetLocationValue.setDefault (getDefaultBuildsRootFolder() + getTargetFolderName());
  64. }
  65. //==============================================================================
  66. bool usesMMFiles() const override { return false; }
  67. bool canCopeWithDuplicateFiles() override { return false; }
  68. bool supportsUserDefinedConfigurations() const override { return false; }
  69. bool isXcode() const override { return false; }
  70. bool isVisualStudio() const override { return false; }
  71. bool isCodeBlocks() const override { return false; }
  72. bool isMakefile() const override { return false; }
  73. bool isAndroidStudio() const override { return false; }
  74. bool isCLion() const override { return true; }
  75. bool isAndroid() const override { return false; }
  76. bool isWindows() const override { return false; }
  77. bool isLinux() const override { return false; }
  78. bool isOSX() const override { return false; }
  79. bool isiOS() const override { return false; }
  80. String getNewLineString() const override { return "\n"; }
  81. bool supportsTargetType (build_tools::ProjectType::Target::Type) const override { return true; }
  82. void addPlatformSpecificSettingsForProjectType (const build_tools::ProjectType&) override {}
  83. //==============================================================================
  84. bool canLaunchProject() override
  85. {
  86. #if JUCE_MAC
  87. static Identifier exporterName (XcodeProjectExporter::getValueTreeTypeNameMac());
  88. #elif JUCE_WINDOWS
  89. static Identifier exporterName (CodeBlocksProjectExporter::getValueTreeTypeNameWindows());
  90. #elif JUCE_LINUX || JUCE_BSD
  91. static Identifier exporterName (MakefileProjectExporter::getValueTreeTypeName());
  92. #else
  93. static Identifier exporterName;
  94. #endif
  95. if (getProject().getExporters().getChildWithName (exporterName).isValid())
  96. return getCLionExecutableOrApp().exists();
  97. return false;
  98. }
  99. bool launchProject() override
  100. {
  101. return getCLionExecutableOrApp().startAsProcess (getTargetFolder().getFullPathName().quoted());
  102. }
  103. String getDescription() override
  104. {
  105. String description;
  106. description << "*****" << newLine
  107. << newLine
  108. << "This exporter is deprecated." << newLine
  109. << newLine
  110. << "CLion can open any CMake-based projects and JUCE's direct CMake support provides a much more "
  111. << "flexible way of configuring CMake. To get started using JUCE with CMake please see the guide in "
  112. << "the 'docs/CMake API.md' file in the JUCE source code." << newLine
  113. << newLine
  114. << "This exporter will no longer be updated and will eventually be removed from the Projucer." << newLine
  115. << newLine
  116. << "*****" << newLine
  117. << newLine
  118. << "This CLion exporter produces a single CMakeLists.txt file with "
  119. << "multiple platform dependent sections, where the configuration for each section "
  120. << "is inherited from other exporters added to this project." << newLine
  121. << newLine
  122. << "The exporters which provide the CLion configuration for the corresponding platform are:" << newLine
  123. << newLine;
  124. for (auto& exporterInfo : getExporterTypeInfos())
  125. {
  126. std::unique_ptr<ProjectExporter> exporter (createNewExporter (getProject(), exporterInfo.identifier));
  127. if (isExporterSupported (*exporter))
  128. description << exporterInfo.displayName << newLine;
  129. }
  130. description << newLine
  131. << "Add these exporters to the project to enable CLion builds." << newLine
  132. << newLine
  133. << "Not all features of all the exporters are currently supported. Notable omissions are AUv3 "
  134. << "plug-ins, embedding resources and fat binaries on MacOS. On Windows the CLion exporter "
  135. << "requires a GCC-based compiler like MinGW.";
  136. return description;
  137. }
  138. void createExporterProperties (PropertyListBuilder& properties) override
  139. {
  140. for (Project::ExporterIterator exporter (getProject()); exporter.next();)
  141. if (isExporterSupported (*exporter))
  142. properties.add (new BooleanPropertyComponent (getExporterEnabledValue (*exporter), "Import settings from exporter", exporter->getUniqueName()),
  143. "If this is enabled then settings from the corresponding exporter will "
  144. "be used in the generated CMakeLists.txt");
  145. }
  146. void createDefaultConfigs() override {}
  147. void create (const OwnedArray<LibraryModule>&) const override
  148. {
  149. // We'll append to this later.
  150. build_tools::writeStreamToFile (getTargetFolder().getChildFile ("CMakeLists.txt"), [this] (MemoryOutputStream& mo)
  151. {
  152. mo.setNewLineString (getNewLineString());
  153. mo << "# Automatically generated CMakeLists, created by the Projucer" << newLine
  154. << "# Do not edit this file! Your changes will be overwritten when you re-save the Projucer project!" << newLine
  155. << newLine;
  156. mo << "cmake_minimum_required (VERSION 3.4.1)" << newLine
  157. << newLine;
  158. mo << "if (NOT CMAKE_BUILD_TYPE)" << newLine
  159. << " set (CMAKE_BUILD_TYPE \"Debug\" CACHE STRING \"Choose the type of build.\" FORCE)" << newLine
  160. << "endif (NOT CMAKE_BUILD_TYPE)" << newLine
  161. << newLine;
  162. });
  163. // CMake has stopped adding PkgInfo files to bundles, so we need to do it manually
  164. build_tools::writeStreamToFile (getTargetFolder().getChildFile ("PkgInfo"),
  165. [] (MemoryOutputStream& mo) { mo << "BNDL????"; });
  166. }
  167. void writeCMakeListsExporterSection (ProjectExporter* exporter) const
  168. {
  169. if (! (isExporterSupported (*exporter) && isExporterEnabled (*exporter)))
  170. return;
  171. MemoryBlock existingContent;
  172. getTargetFolder().getChildFile ("CMakeLists.txt").loadFileAsData (existingContent);
  173. MemoryOutputStream out (existingContent, true);
  174. out.setNewLineString (getNewLineString());
  175. out << "###############################################################################" << newLine
  176. << "# " << exporter->getUniqueName() << newLine
  177. << "###############################################################################" << newLine
  178. << newLine;
  179. if (auto* makefileExporter = dynamic_cast<MakefileProjectExporter*> (exporter))
  180. {
  181. out << "if (UNIX AND NOT APPLE)" << newLine << newLine;
  182. writeCMakeListsMakefileSection (out, *makefileExporter);
  183. }
  184. else if (auto* xcodeExporter = dynamic_cast<XcodeProjectExporter*> (exporter))
  185. {
  186. out << "if (APPLE)" << newLine << newLine;
  187. writeCMakeListsXcodeSection (out, *xcodeExporter);
  188. }
  189. else if (auto* codeBlocksExporter = dynamic_cast<CodeBlocksProjectExporter*> (exporter))
  190. {
  191. out << "if (WIN32)" << newLine << newLine;
  192. writeCMakeListsCodeBlocksSection (out, *codeBlocksExporter);
  193. }
  194. out << "endif()" << newLine << newLine;
  195. build_tools::overwriteFileIfDifferentOrThrow (getTargetFolder().getChildFile ("CMakeLists.txt"), out);
  196. }
  197. private:
  198. //==============================================================================
  199. static File getCLionExecutableOrApp()
  200. {
  201. File clionExeOrApp (getAppSettings()
  202. .getStoredPath (Ids::clionExePath, TargetOS::getThisOS()).get()
  203. .toString()
  204. .replace ("${user.home}", File::getSpecialLocation (File::userHomeDirectory).getFullPathName()));
  205. #if JUCE_MAC
  206. if (clionExeOrApp.getFullPathName().endsWith ("/Contents/MacOS/clion"))
  207. clionExeOrApp = clionExeOrApp.getParentDirectory()
  208. .getParentDirectory()
  209. .getParentDirectory();
  210. #endif
  211. return clionExeOrApp;
  212. }
  213. //==============================================================================
  214. Identifier getExporterEnabledId (const ProjectExporter& exporter) const
  215. {
  216. jassert (isExporterSupported (exporter));
  217. if (exporter.isMakefile()) return Ids::clionMakefileEnabled;
  218. else if (exporter.isXcode()) return Ids::clionXcodeEnabled;
  219. else if (exporter.isCodeBlocks()) return Ids::clionCodeBlocksEnabled;
  220. jassertfalse;
  221. return {};
  222. }
  223. bool isExporterEnabled (const ProjectExporter& exporter) const
  224. {
  225. auto setting = settings[getExporterEnabledId (exporter)];
  226. return setting.isVoid() || setting;
  227. }
  228. Value getExporterEnabledValue (const ProjectExporter& exporter)
  229. {
  230. auto enabledID = getExporterEnabledId (exporter);
  231. getSetting (enabledID) = isExporterEnabled (exporter);
  232. return getSetting (enabledID);
  233. }
  234. //==============================================================================
  235. static bool isWindowsAbsolutePath (const String& path)
  236. {
  237. return path.length() > 1 && path[1] == ':';
  238. }
  239. static bool isUnixAbsolutePath (const String& path)
  240. {
  241. return path.isNotEmpty() && (path[0] == '/' || path[0] == '~' || path.startsWith ("$ENV{HOME}"));
  242. }
  243. //==============================================================================
  244. static String setCMakeVariable (const String& variableName, const String& value)
  245. {
  246. return "set (" + variableName + " \"" + value + "\")";
  247. }
  248. static String addToCMakeVariable (const String& variableName, const String& value)
  249. {
  250. return setCMakeVariable (variableName, "${" + variableName + "} " + value);
  251. }
  252. static String getTargetVarName (build_tools::ProjectType::Target& target)
  253. {
  254. return String (target.getName()).toUpperCase().replaceCharacter (L' ', L'_');
  255. }
  256. template <class Target, class Exporter>
  257. void getFileInfoList (Target& target, Exporter& exporter, const Project::Item& projectItem, std::vector<std::tuple<String, bool, String>>& fileInfoList) const
  258. {
  259. auto targetType = (getProject().isAudioPluginProject() ? target.type : Target::Type::SharedCodeTarget);
  260. if (projectItem.isGroup())
  261. {
  262. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  263. getFileInfoList (target, exporter, projectItem.getChild(i), fileInfoList);
  264. }
  265. else if (projectItem.shouldBeAddedToTargetProject() && projectItem.shouldBeAddedToTargetExporter (*this)
  266. && getProject().getTargetTypeFromFilePath (projectItem.getFile(), true) == targetType )
  267. {
  268. auto path = build_tools::RelativePath (projectItem.getFile(), exporter.getTargetFolder(), build_tools::RelativePath::buildTargetFolder).toUnixStyle();
  269. fileInfoList.push_back (std::make_tuple (path,
  270. projectItem.shouldBeCompiled(),
  271. exporter.compilerFlagSchemesMap[projectItem.getCompilerFlagSchemeString()].get().toString()));
  272. }
  273. }
  274. template <class Exporter>
  275. void writeCMakeTargets (OutputStream& out, Exporter& exporter) const
  276. {
  277. for (auto* target : exporter.targets)
  278. {
  279. if (target->type == build_tools::ProjectType::Target::Type::AggregateTarget
  280. || target->type == build_tools::ProjectType::Target::Type::AudioUnitv3PlugIn)
  281. continue;
  282. String functionName;
  283. StringArray properties;
  284. switch (target->getTargetFileType())
  285. {
  286. case build_tools::ProjectType::Target::TargetFileType::executable:
  287. functionName = "add_executable";
  288. if (exporter.isCodeBlocks() && exporter.isWindows()
  289. && target->type !=
  290. build_tools::ProjectType::Target::Type::ConsoleApp)
  291. properties.add ("WIN32");
  292. break;
  293. case build_tools::ProjectType::Target::TargetFileType::staticLibrary:
  294. case build_tools::ProjectType::Target::TargetFileType::sharedLibraryOrDLL:
  295. case build_tools::ProjectType::Target::TargetFileType::pluginBundle:
  296. functionName = "add_library";
  297. if (target->getTargetFileType() ==
  298. build_tools::ProjectType::Target::TargetFileType::staticLibrary)
  299. properties.add ("STATIC");
  300. else if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::sharedLibraryOrDLL)
  301. properties.add ("SHARED");
  302. else
  303. properties.add ("MODULE");
  304. break;
  305. case build_tools::ProjectType::Target::TargetFileType::macOSAppex:
  306. case build_tools::ProjectType::Target::TargetFileType::unknown:
  307. default:
  308. continue;
  309. }
  310. out << functionName << " (" << getTargetVarName (*target);
  311. if (! properties.isEmpty())
  312. out << " " << properties.joinIntoString (" ");
  313. out << newLine;
  314. std::vector<std::tuple<String, bool, String>> fileInfoList;
  315. for (auto& group : exporter.getAllGroups())
  316. getFileInfoList (*target, exporter, group, fileInfoList);
  317. for (auto& fileInfo : fileInfoList)
  318. out << " " << std::get<0> (fileInfo).quoted() << newLine;
  319. auto isCMakeBundle = exporter.isXcode()
  320. && target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle;
  321. auto pkgInfoPath = String ("PkgInfo").quoted();
  322. if (isCMakeBundle)
  323. out << " " << pkgInfoPath << newLine;
  324. auto xcodeIcnsFilePath = [&]() -> String
  325. {
  326. if (exporter.isXcode()
  327. && target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::executable)
  328. {
  329. StringArray pathComponents = { "..", "MacOSX", "Icon.icns" };
  330. auto xcodeIcnsFile = getTargetFolder();
  331. for (auto& comp : pathComponents)
  332. xcodeIcnsFile = xcodeIcnsFile.getChildFile (comp);
  333. if (xcodeIcnsFile.existsAsFile())
  334. return pathComponents.joinIntoString ("/").quoted();
  335. }
  336. return {};
  337. }();
  338. if (xcodeIcnsFilePath.isNotEmpty())
  339. out << " " << xcodeIcnsFilePath << newLine;
  340. if (exporter.isCodeBlocks()
  341. && target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::executable)
  342. {
  343. StringArray pathComponents = { "..", "CodeBlocksWindows", "resources.rc" };
  344. auto windowsRcFile = getTargetFolder();
  345. for (auto& comp : pathComponents)
  346. windowsRcFile = windowsRcFile.getChildFile (comp);
  347. if (windowsRcFile.existsAsFile())
  348. out << " " << pathComponents.joinIntoString ("/").quoted() << newLine;
  349. }
  350. out << ")" << newLine << newLine;
  351. if (isCMakeBundle)
  352. out << "set_source_files_properties (" << pkgInfoPath << " PROPERTIES MACOSX_PACKAGE_LOCATION .)" << newLine;
  353. if (xcodeIcnsFilePath.isNotEmpty())
  354. out << "set_source_files_properties (" << xcodeIcnsFilePath << " PROPERTIES MACOSX_PACKAGE_LOCATION \"Resources\")" << newLine;
  355. for (auto& fileInfo : fileInfoList)
  356. {
  357. if (std::get<1> (fileInfo))
  358. {
  359. auto extraCompilerFlags = std::get<2> (fileInfo);
  360. if (extraCompilerFlags.isNotEmpty())
  361. out << "set_source_files_properties(" << std::get<0> (fileInfo).quoted() << " PROPERTIES COMPILE_FLAGS " << extraCompilerFlags << " )" << newLine;
  362. }
  363. else
  364. {
  365. out << "set_source_files_properties (" << std::get<0> (fileInfo).quoted() << " PROPERTIES HEADER_FILE_ONLY TRUE)" << newLine;
  366. }
  367. }
  368. out << newLine;
  369. }
  370. }
  371. //==============================================================================
  372. void writeCMakeListsMakefileSection (OutputStream& out, MakefileProjectExporter& exporter) const
  373. {
  374. out << "project (" << getProject().getProjectNameString().quoted() << " C CXX)" << newLine
  375. << newLine;
  376. out << "find_package (PkgConfig REQUIRED)" << newLine;
  377. for (auto& package : exporter.getCompilePackages())
  378. out << "pkg_search_module (" << package.toUpperCase() << " REQUIRED " << package << ")" << newLine;
  379. out << newLine;
  380. writeCMakeTargets (out, exporter);
  381. for (auto* target : exporter.targets)
  382. {
  383. if (target->type == build_tools::ProjectType::Target::Type::AggregateTarget)
  384. continue;
  385. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle)
  386. out << "set_target_properties (" << getTargetVarName (*target) << " PROPERTIES PREFIX \"\")" << newLine;
  387. out << "set_target_properties (" << getTargetVarName (*target) << " PROPERTIES SUFFIX \"" << target->getTargetFileSuffix() << "\")" << newLine
  388. << newLine;
  389. }
  390. for (ProjectExporter::ConstConfigIterator c (exporter); c.next();)
  391. {
  392. auto& config = dynamic_cast<const MakefileProjectExporter::MakeBuildConfiguration&> (*c);
  393. out << "#------------------------------------------------------------------------------" << newLine
  394. << "# Config: " << config.getName() << newLine
  395. << "#------------------------------------------------------------------------------" << newLine
  396. << newLine;
  397. auto buildTypeCondition = String ("CMAKE_BUILD_TYPE STREQUAL " + config.getName());
  398. out << "if (" << buildTypeCondition << ")" << newLine
  399. << newLine;
  400. out << "execute_process (COMMAND uname -m OUTPUT_VARIABLE JUCE_ARCH_LABEL OUTPUT_STRIP_TRAILING_WHITESPACE)" << newLine
  401. << newLine;
  402. out << "include_directories (" << newLine;
  403. for (auto& path : exporter.getHeaderSearchPaths (config))
  404. out << " " << path.quoted() << newLine;
  405. for (auto& package : exporter.getCompilePackages())
  406. out << " ${" << package.toUpperCase() << "_INCLUDE_DIRS}" << newLine;
  407. out << ")" << newLine << newLine;
  408. StringArray cmakeFoundLibraries;
  409. for (auto& library : exporter.getLibraryNames (config))
  410. {
  411. String cmakeLibraryID (library.toUpperCase());
  412. cmakeFoundLibraries.add (String ("${") + cmakeLibraryID + "}");
  413. out << "find_library (" << cmakeLibraryID << " " << library << newLine;
  414. for (auto& path : exporter.getLibrarySearchPaths (config))
  415. out << " " << path.quoted() << newLine;
  416. out << ")" << newLine
  417. << newLine;
  418. }
  419. for (auto* target : exporter.targets)
  420. {
  421. if (target->type == build_tools::ProjectType::Target::Type::AggregateTarget)
  422. continue;
  423. auto targetVarName = getTargetVarName (*target);
  424. out << "set_target_properties (" << targetVarName << " PROPERTIES" << newLine
  425. << " OUTPUT_NAME " << config.getTargetBinaryNameString().quoted() << newLine;
  426. auto cxxStandard = project.getCppStandardString();
  427. if (cxxStandard == "latest")
  428. cxxStandard = project.getLatestNumberedCppStandardString();
  429. out << " CXX_STANDARD " << cxxStandard << newLine;
  430. if (! shouldUseGNUExtensions())
  431. out << " CXX_EXTENSIONS OFF" << newLine;
  432. out << ")" << newLine << newLine;
  433. auto defines = exporter.getDefines (config);
  434. defines.addArray (target->getDefines (config));
  435. out << "target_compile_definitions (" << targetVarName << " PRIVATE" << newLine;
  436. for (auto& key : defines.getAllKeys())
  437. out << " " << key << "=" << defines[key] << newLine;
  438. out << ")" << newLine << newLine;
  439. auto targetFlags = target->getCompilerFlags();
  440. if (! targetFlags.isEmpty())
  441. {
  442. out << "target_compile_options (" << targetVarName << " PRIVATE" << newLine;
  443. for (auto& flag : targetFlags)
  444. out << " " << flag << newLine;
  445. out << ")" << newLine << newLine;
  446. }
  447. out << "target_link_libraries (" << targetVarName << " PRIVATE" << newLine;
  448. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle
  449. || target->type == build_tools::ProjectType::Target::Type::StandalonePlugIn)
  450. out << " SHARED_CODE" << newLine;
  451. out << " " << exporter.getArchFlags (config) << newLine;
  452. for (auto& flag : target->getLinkerFlags())
  453. out << " " << flag << newLine;
  454. for (auto& flag : exporter.getLinkerFlags (config))
  455. out << " " << flag << newLine;
  456. for (auto& lib : cmakeFoundLibraries)
  457. out << " " << lib << newLine;
  458. for (auto& package : exporter.getLinkPackages())
  459. out << " ${" << package.toUpperCase() << "_LIBRARIES}" << newLine;
  460. out << ")" << newLine << newLine;
  461. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle
  462. || target->type == build_tools::ProjectType::Target::Type::StandalonePlugIn)
  463. out << "add_dependencies (" << targetVarName << " " << "SHARED_CODE)" << newLine << newLine;
  464. }
  465. StringArray cFlags;
  466. cFlags.add (exporter.getArchFlags (config));
  467. cFlags.addArray (exporter.getCPreprocessorFlags (config));
  468. cFlags.addArray (exporter.getCFlags (config));
  469. out << addToCMakeVariable ("CMAKE_C_FLAGS", cFlags.joinIntoString (" ")) << newLine;
  470. String cxxFlags;
  471. for (auto& flag : exporter.getCXXFlags (config))
  472. if (! flag.startsWith ("-std="))
  473. cxxFlags += " " + flag;
  474. out << addToCMakeVariable ("CMAKE_CXX_FLAGS", "${CMAKE_C_FLAGS} " + cxxFlags) << newLine
  475. << newLine;
  476. out << "endif (" << buildTypeCondition << ")" << newLine
  477. << newLine;
  478. }
  479. }
  480. //==============================================================================
  481. void writeCMakeListsCodeBlocksSection (OutputStream& out, CodeBlocksProjectExporter& exporter) const
  482. {
  483. out << "project (" << getProject().getProjectNameString().quoted() << " C CXX)" << newLine
  484. << newLine;
  485. writeCMakeTargets (out, exporter);
  486. for (auto* target : exporter.targets)
  487. {
  488. if (target->type == build_tools::ProjectType::Target::Type::AggregateTarget)
  489. continue;
  490. out << "set_target_properties (" << getTargetVarName (*target) << " PROPERTIES PREFIX \"\")" << newLine
  491. << "set_target_properties (" << getTargetVarName (*target) << " PROPERTIES SUFFIX " << target->getTargetSuffix().quoted() << ")" << newLine
  492. << newLine;
  493. }
  494. for (ProjectExporter::ConstConfigIterator c (exporter); c.next();)
  495. {
  496. auto& config = dynamic_cast<const CodeBlocksProjectExporter::CodeBlocksBuildConfiguration&> (*c);
  497. out << "#------------------------------------------------------------------------------" << newLine
  498. << "# Config: " << config.getName() << newLine
  499. << "#------------------------------------------------------------------------------" << newLine
  500. << newLine;
  501. auto buildTypeCondition = String ("CMAKE_BUILD_TYPE STREQUAL " + config.getName());
  502. out << "if (" << buildTypeCondition << ")" << newLine
  503. << newLine;
  504. out << "include_directories (" << newLine;
  505. for (auto& path : exporter.getIncludePaths (config))
  506. out << " " << path.replace ("\\", "/").quoted() << newLine;
  507. out << ")" << newLine << newLine;
  508. for (auto* target : exporter.targets)
  509. {
  510. if (target->type == build_tools::ProjectType::Target::Type::AggregateTarget)
  511. continue;
  512. auto targetVarName = getTargetVarName (*target);
  513. out << "set_target_properties (" << targetVarName << " PROPERTIES" << newLine
  514. << " OUTPUT_NAME " << config.getTargetBinaryNameString().quoted() << newLine;
  515. auto cxxStandard = project.getCppStandardString();
  516. if (cxxStandard == "latest")
  517. cxxStandard = project.getLatestNumberedCppStandardString();
  518. out << " CXX_STANDARD " << cxxStandard << newLine;
  519. if (! shouldUseGNUExtensions())
  520. out << " CXX_EXTENSIONS OFF" << newLine;
  521. out << ")" << newLine << newLine;
  522. out << "target_compile_definitions (" << targetVarName << " PRIVATE" << newLine;
  523. for (auto& def : exporter.getDefines (config, *target))
  524. out << " " << def << newLine;
  525. out << ")" << newLine << newLine;
  526. out << "target_compile_options (" << targetVarName << " PRIVATE" << newLine;
  527. for (auto& option : exporter.getCompilerFlags (config, *target))
  528. if (! option.startsWith ("-std="))
  529. out << " " << option.quoted() << newLine;
  530. out << ")" << newLine << newLine;
  531. out << "target_link_libraries (" << targetVarName << " PRIVATE" << newLine;
  532. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle
  533. || target->type == build_tools::ProjectType::Target::Type::StandalonePlugIn)
  534. out << " SHARED_CODE" << newLine
  535. << " -L." << newLine;
  536. for (auto& path : exporter.getLinkerSearchPaths (config, *target))
  537. {
  538. out << " \"-L\\\"";
  539. if (! isWindowsAbsolutePath (path))
  540. out << "${CMAKE_CURRENT_SOURCE_DIR}/";
  541. out << path.replace ("\\", "/").unquoted() << "\\\"\"" << newLine;
  542. }
  543. for (auto& flag : exporter.getLinkerFlags (config, *target))
  544. out << " " << flag << newLine;
  545. for (auto& flag : exporter.getProjectLinkerLibs())
  546. out << " -l" << flag << newLine;
  547. for (auto& lib : exporter.mingwLibs)
  548. out << " -l" << lib << newLine;
  549. out << ")" << newLine << newLine;
  550. }
  551. out << addToCMakeVariable ("CMAKE_CXX_FLAGS", exporter.getProjectCompilerOptions().joinIntoString (" ")) << newLine
  552. << addToCMakeVariable ("CMAKE_C_FLAGS", "${CMAKE_CXX_FLAGS}") << newLine
  553. << newLine;
  554. out << "endif (" << buildTypeCondition << ")" << newLine
  555. << newLine;
  556. }
  557. }
  558. //==============================================================================
  559. void writeCMakeListsXcodeSection (OutputStream& out, XcodeProjectExporter& exporter) const
  560. {
  561. // We need to find out the SDK root before defining the project. Unfortunately this is
  562. // set per-target in the Xcode project, but we want it per-configuration.
  563. for (ProjectExporter::ConstConfigIterator c (exporter); c.next();)
  564. {
  565. auto& config = dynamic_cast<const XcodeProjectExporter::XcodeBuildConfiguration&> (*c);
  566. for (auto* target : exporter.targets)
  567. {
  568. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::macOSAppex
  569. || target->type == build_tools::ProjectType::Target::Type::AggregateTarget
  570. || target->type == build_tools::ProjectType::Target::Type::AudioUnitv3PlugIn)
  571. continue;
  572. auto targetAttributes = target->getTargetSettings (config);
  573. auto targetAttributeKeys = targetAttributes.getAllKeys();
  574. if (targetAttributes.getAllKeys().contains ("SDKROOT"))
  575. {
  576. out << "if (CMAKE_BUILD_TYPE STREQUAL " + config.getName() << ")" << newLine
  577. << " set (CMAKE_OSX_SYSROOT " << targetAttributes["SDKROOT"] << ")" << newLine
  578. << "endif()" << newLine << newLine;
  579. break;
  580. }
  581. }
  582. }
  583. out << "project (" << getProject().getProjectNameString().quoted() << " C CXX)" << newLine << newLine;
  584. writeCMakeTargets (out, exporter);
  585. for (auto* target : exporter.targets)
  586. {
  587. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::macOSAppex
  588. || target->type == build_tools::ProjectType::Target::Type::AggregateTarget
  589. || target->type == build_tools::ProjectType::Target::Type::AudioUnitv3PlugIn)
  590. continue;
  591. if (target->type == build_tools::ProjectType::Target::Type::AudioUnitPlugIn)
  592. out << "find_program (RC_COMPILER Rez NO_DEFAULT_PATHS PATHS \"/Applications/Xcode.app/Contents/Developer/usr/bin\")" << newLine
  593. << "if (NOT RC_COMPILER)" << newLine
  594. << " message (WARNING \"failed to find Rez; older resource-based AU plug-ins may not work correctly\")" << newLine
  595. << "endif (NOT RC_COMPILER)" << newLine << newLine;
  596. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::staticLibrary
  597. || target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::sharedLibraryOrDLL)
  598. out << "set_target_properties (" << getTargetVarName (*target) << " PROPERTIES SUFFIX \"" << target->xcodeBundleExtension << "\")" << newLine
  599. << newLine;
  600. }
  601. for (ProjectExporter::ConstConfigIterator c (exporter); c.next();)
  602. {
  603. auto& config = dynamic_cast<const XcodeProjectExporter::XcodeBuildConfiguration&> (*c);
  604. out << "#------------------------------------------------------------------------------" << newLine
  605. << "# Config: " << config.getName() << newLine
  606. << "#------------------------------------------------------------------------------" << newLine
  607. << newLine;
  608. auto buildTypeCondition = String ("CMAKE_BUILD_TYPE STREQUAL " + config.getName());
  609. out << "if (" << buildTypeCondition << ")" << newLine
  610. << newLine;
  611. out << "execute_process (COMMAND uname -m OUTPUT_VARIABLE JUCE_ARCH_LABEL OUTPUT_STRIP_TRAILING_WHITESPACE)" << newLine
  612. << newLine;
  613. auto configSettings = exporter.getProjectSettings (config);
  614. auto configSettingsKeys = configSettings.getAllKeys();
  615. auto binaryName = config.getTargetBinaryNameString();
  616. if (configSettingsKeys.contains ("PRODUCT_NAME"))
  617. binaryName = configSettings["PRODUCT_NAME"].unquoted();
  618. for (auto* target : exporter.targets)
  619. {
  620. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::macOSAppex
  621. || target->type == build_tools::ProjectType::Target::Type::AggregateTarget
  622. || target->type == build_tools::ProjectType::Target::Type::AudioUnitv3PlugIn)
  623. continue;
  624. auto targetVarName = getTargetVarName (*target);
  625. auto targetAttributes = target->getTargetSettings (config);
  626. auto targetAttributeKeys = targetAttributes.getAllKeys();
  627. StringArray headerSearchPaths;
  628. if (targetAttributeKeys.contains ("HEADER_SEARCH_PATHS"))
  629. {
  630. auto paths = targetAttributes["HEADER_SEARCH_PATHS"].trim().substring (1).dropLastCharacters (1);
  631. paths = paths.replace ("\"$(inherited)\"", {})
  632. .replace ("$(HOME)", "$ENV{HOME}")
  633. .replace ("~", "$ENV{HOME}");
  634. headerSearchPaths.addTokens (paths, ",\"\t\\", {});
  635. headerSearchPaths.removeEmptyStrings();
  636. targetAttributeKeys.removeString ("HEADER_SEARCH_PATHS");
  637. }
  638. out << "target_include_directories (" << targetVarName << " PRIVATE" << newLine;
  639. for (auto& path : headerSearchPaths)
  640. out << " " << path.quoted() << newLine;
  641. out << ")" << newLine << newLine;
  642. StringArray defines;
  643. if (targetAttributeKeys.contains ("GCC_PREPROCESSOR_DEFINITIONS"))
  644. {
  645. defines.addTokens (targetAttributes["GCC_PREPROCESSOR_DEFINITIONS"], "(),\t", {});
  646. defines.removeEmptyStrings();
  647. targetAttributeKeys.removeString ("GCC_PREPROCESSOR_DEFINITIONS");
  648. }
  649. out << "target_compile_definitions (" << targetVarName << " PRIVATE" << newLine;
  650. for (auto& def : defines)
  651. out << " " << def.replace ("\\\\\\\"", "\\\"").replace ("\\\\ ", " ") << newLine;
  652. out << ")" << newLine << newLine;
  653. StringArray cppFlags;
  654. String archLabel ("${JUCE_ARCH_LABEL}");
  655. // Fat binaries are not supported.
  656. if (targetAttributeKeys.contains ("ARCHS"))
  657. {
  658. auto value = targetAttributes["ARCHS"].unquoted();
  659. if (value.contains ("NATIVE_ARCH_ACTUAL"))
  660. {
  661. cppFlags.add ("-march=native");
  662. }
  663. else if (value.contains ("ARCHS_STANDARD_32_BIT"))
  664. {
  665. archLabel = "i386";
  666. cppFlags.add ("-arch x86");
  667. }
  668. else if (value.contains ("ARCHS_STANDARD_32_64_BIT")
  669. || value.contains ("ARCHS_STANDARD_64_BIT"))
  670. {
  671. archLabel = "x86_64";
  672. cppFlags.add ("-arch x86_64");
  673. }
  674. targetAttributeKeys.removeString ("ARCHS");
  675. }
  676. if (targetAttributeKeys.contains ("MACOSX_DEPLOYMENT_TARGET"))
  677. {
  678. cppFlags.add ("-mmacosx-version-min=" + targetAttributes["MACOSX_DEPLOYMENT_TARGET"]);
  679. targetAttributeKeys.removeString ("MACOSX_DEPLOYMENT_TARGET");
  680. }
  681. if (targetAttributeKeys.contains ("OTHER_CPLUSPLUSFLAGS"))
  682. {
  683. cppFlags.add (targetAttributes["OTHER_CPLUSPLUSFLAGS"].unquoted());
  684. targetAttributeKeys.removeString ("OTHER_CPLUSPLUSFLAGS");
  685. }
  686. if (targetAttributeKeys.contains ("GCC_OPTIMIZATION_LEVEL"))
  687. {
  688. cppFlags.add ("-O" + targetAttributes["GCC_OPTIMIZATION_LEVEL"]);
  689. targetAttributeKeys.removeString ("GCC_OPTIMIZATION_LEVEL");
  690. }
  691. if (targetAttributeKeys.contains ("LLVM_LTO"))
  692. {
  693. cppFlags.add ("-flto");
  694. targetAttributeKeys.removeString ("LLVM_LTO");
  695. }
  696. if (targetAttributeKeys.contains ("GCC_FAST_MATH"))
  697. {
  698. cppFlags.add ("-ffast-math");
  699. targetAttributeKeys.removeString ("GCC_FAST_MATH");
  700. }
  701. // We'll take this setting from the project
  702. targetAttributeKeys.removeString ("CLANG_CXX_LANGUAGE_STANDARD");
  703. if (targetAttributeKeys.contains ("CLANG_CXX_LIBRARY"))
  704. {
  705. cppFlags.add ("-stdlib=" + targetAttributes["CLANG_CXX_LIBRARY"].unquoted());
  706. targetAttributeKeys.removeString ("CLANG_CXX_LIBRARY");
  707. }
  708. out << "target_compile_options (" << targetVarName << " PRIVATE" << newLine;
  709. for (auto& flag : cppFlags)
  710. out << " " << flag << newLine;
  711. out << ")" << newLine << newLine;
  712. StringArray libSearchPaths;
  713. if (targetAttributeKeys.contains ("LIBRARY_SEARCH_PATHS"))
  714. {
  715. auto paths = targetAttributes["LIBRARY_SEARCH_PATHS"].trim().substring (1).dropLastCharacters (1);
  716. paths = paths.replace ("\"$(inherited)\"", {});
  717. paths = paths.replace ("$(HOME)", "$ENV{HOME}");
  718. libSearchPaths.addTokens (paths, ",\"\t\\", {});
  719. libSearchPaths.removeEmptyStrings();
  720. for (auto& libPath : libSearchPaths)
  721. {
  722. libPath = libPath.replace ("${CURRENT_ARCH}", archLabel);
  723. if (! isUnixAbsolutePath (libPath))
  724. libPath = "${CMAKE_CURRENT_SOURCE_DIR}/" + libPath;
  725. }
  726. targetAttributeKeys.removeString ("LIBRARY_SEARCH_PATHS");
  727. }
  728. StringArray linkerFlags;
  729. if (targetAttributeKeys.contains ("OTHER_LDFLAGS"))
  730. {
  731. // CMake adds its own SHARED_CODE library linking flags
  732. auto flagsWithReplacedSpaces = targetAttributes["OTHER_LDFLAGS"].unquoted().replace ("\\\\ ", "^^%%^^");
  733. linkerFlags.addTokens (flagsWithReplacedSpaces, true);
  734. linkerFlags.removeString ("-bundle");
  735. linkerFlags.removeString ("-l" + binaryName.replace (" ", "^^%%^^"));
  736. for (auto& flag : linkerFlags)
  737. flag = flag.replace ("^^%%^^", " ");
  738. targetAttributeKeys.removeString ("OTHER_LDFLAGS");
  739. }
  740. if (target->type == build_tools::ProjectType::Target::Type::AudioUnitPlugIn)
  741. {
  742. String rezFlags;
  743. if (targetAttributeKeys.contains ("OTHER_REZFLAGS"))
  744. {
  745. rezFlags = targetAttributes["OTHER_REZFLAGS"];
  746. targetAttributeKeys.removeString ("OTHER_REZFLAGS");
  747. }
  748. for (auto& item : exporter.getAllGroups())
  749. {
  750. if (item.getName() == ProjectSaver::getJuceCodeGroupName())
  751. {
  752. auto resSourcesVar = targetVarName + "_REZ_SOURCES";
  753. auto resOutputVar = targetVarName + "_REZ_OUTPUT";
  754. auto sdkVersion = config.getMacOSBaseSDKString().upToFirstOccurrenceOf (" ", false, false);
  755. auto sysroot = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" + sdkVersion + ".sdk";
  756. build_tools::RelativePath rFile ("JuceLibraryCode/include_juce_audio_plugin_client_AU.r", build_tools::RelativePath::projectFolder);
  757. rFile = rebaseFromProjectFolderToBuildTarget (rFile);
  758. out << "if (RC_COMPILER)" << newLine
  759. << " set (" << resSourcesVar << newLine
  760. << " " << ("${CMAKE_CURRENT_SOURCE_DIR}/" + rFile.toUnixStyle()).quoted() << newLine
  761. << " )" << newLine
  762. << " set (" << resOutputVar << " " << ("${CMAKE_CURRENT_BINARY_DIR}/" + binaryName + ".rsrc").quoted() << ")" << newLine
  763. << " target_sources (" << targetVarName << " PRIVATE" << newLine
  764. << " ${" << resSourcesVar << "}" << newLine
  765. << " ${" << resOutputVar << "}" << newLine
  766. << " )" << newLine
  767. << " execute_process (COMMAND" << newLine
  768. << " ${RC_COMPILER}" << newLine
  769. << " " << rezFlags.unquoted().removeCharacters ("\\") << newLine
  770. << " -isysroot " << sysroot.quoted() << newLine;
  771. for (auto& path : headerSearchPaths)
  772. {
  773. out << " -I \"";
  774. if (! isUnixAbsolutePath (path))
  775. out << "${PROJECT_SOURCE_DIR}/";
  776. out << path << "\"" << newLine;
  777. }
  778. out << " ${" << resSourcesVar << "}" << newLine
  779. << " -o ${" << resOutputVar << "}" << newLine
  780. << " )" << newLine
  781. << " set_source_files_properties (${" << resOutputVar << "} PROPERTIES" << newLine
  782. << " GENERATED TRUE" << newLine
  783. << " MACOSX_PACKAGE_LOCATION Resources" << newLine
  784. << " )" << newLine
  785. << "endif (RC_COMPILER)" << newLine << newLine;
  786. break;
  787. }
  788. }
  789. }
  790. if (targetAttributeKeys.contains ("INFOPLIST_FILE"))
  791. {
  792. auto plistFile = exporter.getTargetFolder().getChildFile (targetAttributes["INFOPLIST_FILE"]);
  793. if (auto plist = parseXML (plistFile))
  794. {
  795. if (auto* dict = plist->getChildByName ("dict"))
  796. {
  797. if (auto* entry = dict->getChildByName ("key"))
  798. {
  799. while (entry != nullptr)
  800. {
  801. if (entry->getAllSubText() == "CFBundleExecutable")
  802. {
  803. if (auto* bundleName = entry->getNextElementWithTagName ("string"))
  804. {
  805. bundleName->deleteAllTextElements();
  806. bundleName->addTextElement (binaryName);
  807. }
  808. }
  809. entry = entry->getNextElementWithTagName ("key");
  810. }
  811. }
  812. }
  813. auto updatedPlist = getTargetFolder().getChildFile (config.getName() + "-" + plistFile.getFileName());
  814. XmlElement::TextFormat format;
  815. format.dtd = "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">";
  816. plist->writeTo (updatedPlist, format);
  817. targetAttributes.set ("INFOPLIST_FILE", ("${CMAKE_CURRENT_SOURCE_DIR}/" + updatedPlist.getFileName()).quoted());
  818. }
  819. else
  820. {
  821. targetAttributeKeys.removeString ("INFOPLIST_FILE");
  822. }
  823. }
  824. targetAttributeKeys.sort (false);
  825. out << "set_target_properties (" << targetVarName << " PROPERTIES" << newLine
  826. << " OUTPUT_NAME " << binaryName.quoted() << newLine;
  827. auto cxxStandard = project.getCppStandardString();
  828. if (cxxStandard == "latest")
  829. cxxStandard = project.getLatestNumberedCppStandardString();
  830. out << " CXX_STANDARD " << cxxStandard << newLine;
  831. if (! shouldUseGNUExtensions())
  832. out << " CXX_EXTENSIONS OFF" << newLine;
  833. if (targetAttributeKeys.contains ("MTL_HEADER_SEARCH_PATHS"))
  834. {
  835. auto pathsString = targetAttributes["MTL_HEADER_SEARCH_PATHS"].trim().substring (1).dropLastCharacters (1);
  836. pathsString = pathsString.replace ("\"$(inherited)\"", {})
  837. .replace ("$(HOME)", "$ENV{HOME}")
  838. .replace ("~", "$ENV{HOME}");
  839. auto paths = StringArray::fromTokens (pathsString, ",\"\t\\", {});
  840. paths.removeEmptyStrings();
  841. out << " XCODE_ATTRIBUTE_MTL_HEADER_SEARCH_PATHS" << " " << paths.joinIntoString (" ").quoted() << newLine;
  842. targetAttributeKeys.removeString ("MTL_HEADER_SEARCH_PATHS");
  843. }
  844. for (auto& key : targetAttributeKeys)
  845. out << " XCODE_ATTRIBUTE_" << key << " " << targetAttributes[key] << newLine;
  846. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::executable
  847. || target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle)
  848. {
  849. out << " MACOSX_BUNDLE_INFO_PLIST " << targetAttributes.getValue ("INFOPLIST_FILE", "\"\"") << newLine
  850. << " XCODE_ATTRIBUTE_PRODUCT_NAME " << binaryName.quoted() << newLine;
  851. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::executable)
  852. {
  853. out << " MACOSX_BUNDLE TRUE" << newLine;
  854. }
  855. else
  856. {
  857. out << " BUNDLE TRUE" << newLine
  858. << " BUNDLE_EXTENSION " << targetAttributes.getValue ("WRAPPER_EXTENSION", "\"\"") << newLine
  859. << " XCODE_ATTRIBUTE_MACH_O_TYPE \"mh_bundle\"" << newLine;
  860. }
  861. }
  862. out << ")" << newLine << newLine;
  863. out << "target_link_libraries (" << targetVarName << " PRIVATE" << newLine;
  864. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle
  865. || target->type == build_tools::ProjectType::Target::Type::StandalonePlugIn)
  866. out << " SHARED_CODE" << newLine;
  867. for (auto& path : libSearchPaths)
  868. out << " \"-L\\\"" << path << "\\\"\"" << newLine;
  869. for (auto& flag : linkerFlags)
  870. out << " " << flag.quoted() << newLine;
  871. for (auto& framework : target->frameworkNames)
  872. out << " \"-framework " << framework << "\"" << newLine;
  873. out << ")" << newLine << newLine;
  874. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle
  875. || target->type == build_tools::ProjectType::Target::Type::StandalonePlugIn)
  876. {
  877. if (target->getTargetFileType() == build_tools::ProjectType::Target::TargetFileType::pluginBundle
  878. && targetAttributeKeys.contains("INSTALL_PATH"))
  879. {
  880. auto installPath = targetAttributes["INSTALL_PATH"].unquoted().replace ("$(HOME)", "$ENV{HOME}");
  881. auto productFilename = binaryName + (targetAttributeKeys.contains ("WRAPPER_EXTENSION") ? "." + targetAttributes["WRAPPER_EXTENSION"] : String());
  882. auto productPath = (installPath + productFilename).quoted();
  883. out << "add_custom_command (TARGET " << targetVarName << " POST_BUILD" << newLine
  884. << " COMMAND ${CMAKE_COMMAND} -E remove_directory " << productPath << newLine
  885. << " COMMAND ${CMAKE_COMMAND} -E copy_directory \"${CMAKE_BINARY_DIR}/" << productFilename << "\" " << productPath << newLine
  886. << " COMMENT \"Copying \\\"" << productFilename << "\\\" to \\\"" << installPath.unquoted() << "\\\"\"" << newLine
  887. << ")" << newLine << newLine;
  888. }
  889. }
  890. }
  891. std::map<String, String> basicWarnings
  892. {
  893. { "CLANG_WARN_BOOL_CONVERSION", "bool-conversion" },
  894. { "CLANG_WARN_COMMA", "comma" },
  895. { "CLANG_WARN_CONSTANT_CONVERSION", "constant-conversion" },
  896. { "CLANG_WARN_EMPTY_BODY", "empty-body" },
  897. { "CLANG_WARN_ENUM_CONVERSION", "enum-conversion" },
  898. { "CLANG_WARN_INFINITE_RECURSION", "infinite-recursion" },
  899. { "CLANG_WARN_INT_CONVERSION", "int-conversion" },
  900. { "CLANG_WARN_RANGE_LOOP_ANALYSIS", "range-loop-analysis" },
  901. { "CLANG_WARN_STRICT_PROTOTYPES", "strict-prototypes" },
  902. { "GCC_WARN_CHECK_SWITCH_STATEMENTS", "switch" },
  903. { "GCC_WARN_UNUSED_VARIABLE", "unused-variable" },
  904. { "GCC_WARN_MISSING_PARENTHESES", "parentheses" },
  905. { "GCC_WARN_NON_VIRTUAL_DESTRUCTOR", "non-virtual-dtor" },
  906. { "GCC_WARN_64_TO_32_BIT_CONVERSION", "shorten-64-to-32" },
  907. { "GCC_WARN_UNDECLARED_SELECTOR", "undeclared-selector" },
  908. { "GCC_WARN_UNUSED_FUNCTION", "unused-function" }
  909. };
  910. StringArray compilerFlags;
  911. for (auto& key : configSettingsKeys)
  912. {
  913. auto basicWarning = basicWarnings.find (key);
  914. if (basicWarning != basicWarnings.end())
  915. {
  916. compilerFlags.add (configSettings[key] == "YES" ? "-W" + basicWarning->second : "-Wno-" + basicWarning->second);
  917. }
  918. else if (key == "CLANG_WARN_SUSPICIOUS_MOVE" && configSettings[key] == "YES") compilerFlags.add ("-Wmove");
  919. else if (key == "CLANG_WARN_UNREACHABLE_CODE" && configSettings[key] == "YES") compilerFlags.add ("-Wunreachable-code");
  920. else if (key == "CLANG_WARN__DUPLICATE_METHOD_MATCH" && configSettings[key] == "YES") compilerFlags.add ("-Wduplicate-method-match");
  921. else if (key == "GCC_INLINES_ARE_PRIVATE_EXTERN" && configSettings[key] == "YES") compilerFlags.add ("-fvisibility-inlines-hidden");
  922. else if (key == "GCC_NO_COMMON_BLOCKS" && configSettings[key] == "YES") compilerFlags.add ("-fno-common");
  923. else if (key == "GCC_WARN_ABOUT_RETURN_TYPE" && configSettings[key] != "YES") compilerFlags.add (configSettings[key] == "YES_ERROR" ? "-Werror=return-type" : "-Wno-return-type");
  924. else if (key == "GCC_WARN_TYPECHECK_CALLS_TO_PRINTF" && configSettings[key] != "YES") compilerFlags.add ("-Wno-format");
  925. else if (key == "GCC_WARN_UNINITIALIZED_AUTOS")
  926. {
  927. if (configSettings[key] == "YES") compilerFlags.add ("-Wuninitialized");
  928. else if (configSettings[key] == "YES_AGGRESSIVE") compilerFlags.add ("--Wconditional-uninitialized");
  929. else compilerFlags.add (")-Wno-uninitialized");
  930. }
  931. else if (key == "WARNING_CFLAGS") compilerFlags.add (configSettings[key].unquoted());
  932. }
  933. out << addToCMakeVariable ("CMAKE_CXX_FLAGS", compilerFlags.joinIntoString (" ")) << newLine
  934. << addToCMakeVariable ("CMAKE_C_FLAGS", "${CMAKE_CXX_FLAGS}") << newLine
  935. << newLine;
  936. out << "endif (" << buildTypeCondition << ")" << newLine
  937. << newLine;
  938. }
  939. }
  940. //==============================================================================
  941. JUCE_DECLARE_NON_COPYABLE (CLionProjectExporter)
  942. };