1 // Copyright (c) 2013 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_TARGET_H_ 6 #define TOOLS_GN_TARGET_H_ 7 8 #include <set> 9 #include <string> 10 #include <vector> 11 12 #include "base/basictypes.h" 13 #include "base/compiler_specific.h" 14 #include "base/logging.h" 15 #include "base/strings/string_piece.h" 16 #include "base/synchronization/lock.h" 17 #include "tools/gn/config_values.h" 18 #include "tools/gn/item.h" 19 #include "tools/gn/source_file.h" 20 21 class InputFile; 22 class Settings; 23 class Token; 24 25 class Target : public Item { 26 public: 27 enum OutputType { 28 NONE, 29 EXECUTABLE, 30 SHARED_LIBRARY, 31 STATIC_LIBRARY, 32 LOADABLE_MODULE, 33 COPY_FILES, 34 CUSTOM, 35 }; 36 typedef std::vector<SourceFile> FileList; 37 typedef std::vector<std::string> StringVector; 38 39 Target(const Settings* settings, const Label& label); 40 virtual ~Target(); 41 42 // Item overrides. 43 virtual Target* AsTarget() OVERRIDE; 44 virtual const Target* AsTarget() const OVERRIDE; 45 virtual void OnResolved() OVERRIDE; 46 47 // This flag indicates if we've run the TargetGenerator for this target to 48 // fill out the rest of the values. Once we've done this, we save the 49 // location of the function that started the generating so that we can detect 50 // duplicate declarations. 51 bool HasBeenGenerated() const; 52 void SetGenerated(const Token* token); 53 54 const Settings* settings() const { return settings_; } 55 56 OutputType output_type() const { return output_type_; } 57 void set_output_type(OutputType t) { output_type_ = t; } 58 59 bool IsLinkable() const; 60 61 const FileList& sources() const { return sources_; } 62 void swap_in_sources(FileList* s) { sources_.swap(*s); } 63 64 const FileList& data() const { return data_; } 65 void swap_in_data(FileList* d) { data_.swap(*d); } 66 67 // Linked dependencies. 68 const std::vector<const Target*>& deps() const { return deps_; } 69 void swap_in_deps(std::vector<const Target*>* d) { deps_.swap(*d); } 70 71 // Non-linked dependencies. 72 const std::vector<const Target*>& datadeps() const { return datadeps_; } 73 void swap_in_datadeps(std::vector<const Target*>* d) { datadeps_.swap(*d); } 74 75 // List of configs that this class inherits settings from. 76 const std::vector<const Config*>& configs() const { return configs_; } 77 void swap_in_configs(std::vector<const Config*>* c) { configs_.swap(*c); } 78 79 // List of configs that all dependencies (direct and indirect) of this 80 // target get. These configs are not added to this target. 81 const std::vector<const Config*>& all_dependent_configs() const { 82 return all_dependent_configs_; 83 } 84 void swap_in_all_dependent_configs(std::vector<const Config*>* c) { 85 all_dependent_configs_.swap(*c); 86 } 87 88 // List of configs that targets depending directly on this one get. These 89 // configs are not added to this target. 90 const std::vector<const Config*>& direct_dependent_configs() const { 91 return direct_dependent_configs_; 92 } 93 void swap_in_direct_dependent_configs(std::vector<const Config*>* c) { 94 direct_dependent_configs_.swap(*c); 95 } 96 97 const std::set<const Target*>& inherited_libraries() const { 98 return inherited_libraries_; 99 } 100 101 // This config represents the configuration set directly on this target. 102 ConfigValues& config_values() { return config_values_; } 103 const ConfigValues& config_values() const { return config_values_; } 104 105 const SourceDir& destdir() const { return destdir_; } 106 void set_destdir(const SourceDir& d) { destdir_ = d; } 107 108 const SourceFile& script() const { return script_; } 109 void set_script(const SourceFile& s) { script_ = s; } 110 111 const std::vector<std::string>& script_args() const { return script_args_; } 112 void swap_in_script_args(std::vector<std::string>* sa) { 113 script_args_.swap(*sa); 114 } 115 116 const FileList& outputs() const { return outputs_; } 117 void swap_in_outputs(FileList* s) { outputs_.swap(*s); } 118 119 private: 120 const Settings* settings_; 121 OutputType output_type_; 122 123 FileList sources_; 124 FileList data_; 125 std::vector<const Target*> deps_; 126 std::vector<const Target*> datadeps_; 127 std::vector<const Config*> configs_; 128 std::vector<const Config*> all_dependent_configs_; 129 std::vector<const Config*> direct_dependent_configs_; 130 131 // Libraries from transitive deps. Libraries need to be linked only 132 // with the end target (executable, shared library). These do not get 133 // pushed beyond shared library boundaries. 134 std::set<const Target*> inherited_libraries_; 135 136 ConfigValues config_values_; 137 138 SourceDir destdir_; 139 140 // Script target stuff. 141 SourceFile script_; 142 std::vector<std::string> script_args_; 143 FileList outputs_; 144 145 bool generated_; 146 const Token* generator_function_; // Who generated this: for error messages. 147 148 DISALLOW_COPY_AND_ASSIGN(Target); 149 }; 150 151 #endif // TOOLS_GN_TARGET_H_ 152