1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef TOOLS_GN_XCODE_WRITER_H_ 6 #define TOOLS_GN_XCODE_WRITER_H_ 7 8 #include <iosfwd> 9 #include <map> 10 #include <memory> 11 #include <string> 12 #include <vector> 13 14 class Builder; 15 class BuildSettings; 16 class Err; 17 18 enum class XcodeBuildSystem { 19 kLegacy, 20 kNew, 21 }; 22 23 // Writes an Xcode workspace to build and debug code. 24 class XcodeWriter { 25 public: 26 // Controls some parameters and behaviour of the RunAndWriteFiles(). 27 struct Options { 28 // Name of the generated project file. Defaults to "all" is empty. 29 std::string project_name; 30 31 // Name of the ninja target to use for the "All" target in the generated 32 // project. If empty, no target will be passed to ninja which will thus 33 // try to build all defined targets. 34 std::string root_target_name; 35 36 // Name of the ninja executable. Defaults to "ninja" if empty. 37 std::string ninja_executable; 38 39 // If specified, should be a semicolon-separated list of label patterns. 40 // It will be used to filter the list of targets generated in the project 41 // (in the same way that the other filtering is done, source and header 42 // files for those target will still be listed in the generated project). 43 std::string dir_filters_string; 44 45 // Control which version of the build system should be used for the 46 // generated Xcode project. 47 XcodeBuildSystem build_system = XcodeBuildSystem::kLegacy; 48 }; 49 50 // Writes an Xcode workspace with a single project file. 51 // 52 // The project will lists all files referenced for the build (including the 53 // sources, headers and some supporting files). The project can be used to 54 // build, develop and debug from Xcode (though adding files, changing build 55 // settings, etc. still needs to be done via BUILD.gn files). 56 // 57 // The list of targets is filtered to only include relevant targets for 58 // debugging (mostly binaries and bundles) so it is not possible to build 59 // individuals targets (i.e. source_set) via Xcode. This filtering is done 60 // to improve the performances when loading the solution in Xcode (project 61 // like Chromium cannot be opened if all targets are generated). 62 // 63 // The source and header files are still listed in the generated generated 64 // Xcode project, even if the target they are defined in are filtered (not 65 // doing so would make it less pleasant to use Xcode to debug without any 66 // significant performance improvement). 67 // 68 // Extra behaviour is controlled by the |options| parameter. See comments 69 // of the Options type for more informations. 70 // 71 // Returns true on success, fails on failure. |err| is set in that case. 72 static bool RunAndWriteFiles(const BuildSettings* build_settings, 73 const Builder& builder, 74 Options options, 75 Err* err); 76 77 private: 78 XcodeWriter(const XcodeWriter&) = delete; 79 XcodeWriter& operator=(const XcodeWriter&) = delete; 80 }; 81 82 #endif // TOOLS_GN_XCODE_WRITER_H_ 83