cmSourceFile.h 4.54 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3 4
#ifndef cmSourceFile_h
#define cmSourceFile_h
5

6
#include "cmConfigure.h" // IWYU pragma: keep
7

8
#include "cmPropertyMap.h"
9
#include "cmSourceFileLocation.h"
10
#include "cmSourceFileLocationKind.h"
11 12 13

#include <string>
#include <vector>
14

15 16
class cmCustomCommand;
class cmMakefile;
17

18
/** \class cmSourceFile
19 20
 * \brief Represent a class loaded from a makefile.
 *
21
 * cmSourceFile is represents a class loaded from
22 23
 * a makefile.
 */
24
class cmSourceFile
25
{
26 27
public:
  /**
28 29
   * Construct with the makefile storing the source and the initial
   * name referencing it.
30
   */
31 32 33
  cmSourceFile(
    cmMakefile* mf, const std::string& name,
    cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
34 35

  ~cmSourceFile();
36

37 38 39
  cmSourceFile(const cmSourceFile&) = delete;
  cmSourceFile& operator=(const cmSourceFile&) = delete;

40 41 42
  /**
   * Get the list of the custom commands for this source file
   */
43 44
  cmCustomCommand* GetCustomCommand();
  cmCustomCommand const* GetCustomCommand() const;
45
  void SetCustomCommand(cmCustomCommand* cc);
46

47
  ///! Set/Get a property of this source file
48 49 50
  void SetProperty(const std::string& prop, const char* value);
  void AppendProperty(const std::string& prop, const char* value,
                      bool asString = false);
51
  ///! Might return a nullptr if the property is not set or invalid
52
  const char* GetProperty(const std::string& prop) const;
53 54
  ///! Always returns a valid pointer
  const char* GetSafeProperty(const std::string& prop) const;
55
  bool GetPropertyAsBool(const std::string& prop) const;
56

57 58
  /** Implement getting a property when called from a CMake language
      command like get_property or get_source_file_property.  */
59
  const char* GetPropertyForUser(const std::string& prop);
60

61 62 63 64
  ///! Checks is the GENERATED property is set and true
  /// @return Equivalent to GetPropertyAsBool("GENERATED")
  bool GetIsGenerated() const { return this->IsGenerated; }

65
  /**
66 67 68 69 70 71
   * The full path to the file.  The non-const version of this method
   * may attempt to locate the file on disk and finalize its location.
   * The const version of this method may return an empty string if
   * the non-const version has not yet been called (yes this is a
   * horrible interface, but is necessary for backwards
   * compatibility).
72
   */
Daniel Pfeifer's avatar
Daniel Pfeifer committed
73
  std::string const& GetFullPath(std::string* error = nullptr);
74
  std::string const& GetFullPath() const;
75

76 77 78 79 80 81 82
  /**
   * Get the information currently known about the source file
   * location without attempting to locate the file as GetFullPath
   * would.  See cmSourceFileLocation documentation.
   */
  cmSourceFileLocation const& GetLocation() const;

83
  /**
84
   * Get the file extension of this source file.
85
   */
86
  std::string const& GetExtension() const;
87

88
  /**
89
   * Get the language of the compiler to use for this source file.
90
   */
91 92
  std::string GetLanguage();
  std::string GetLanguage() const;
93

94
  /**
95
   * Return the vector that holds the list of dependencies
96
   */
97
  const std::vector<std::string>& GetDepends() const { return this->Depends; }
98
  void AddDepend(const std::string& d) { this->Depends.push_back(d); }
99

100
  // Get the properties
101
  cmPropertyMap& GetProperties() { return this->Properties; }
102
  const cmPropertyMap& GetProperties() const { return this->Properties; }
103

104 105 106 107 108
  /**
   * Check whether the given source file location could refer to this
   * source.
   */
  bool Matches(cmSourceFileLocation const&);
109

110 111 112
  void SetObjectLibrary(std::string const& objlib);
  std::string GetObjectLibrary() const;

113
private:
114
  cmSourceFileLocation Location;
115
  cmPropertyMap Properties;
116
  cmCustomCommand* CustomCommand = nullptr;
117 118
  std::string Extension;
  std::string Language;
119
  std::string FullPath;
120
  std::string ObjectLibrary;
121
  std::vector<std::string> Depends;
122 123
  bool FindFullPathFailed = false;
  bool IsGenerated = false;
124

125
  bool FindFullPath(std::string* error);
126
  void CheckExtension();
127
  void CheckLanguage(std::string const& ext);
128

129
  static const std::string propLANGUAGE;
130 131
  static const std::string propLOCATION;
  static const std::string propGENERATED;
132 133
};

134 135 136
// TODO: Factor out into platform information modules.
#define CM_HEADER_REGEX "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$"

137
#define CM_SOURCE_REGEX                                                       \
138 139
  "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|cu|f|f90|for|fpp|ftn|m|mm|rc|def|r|odl|idl|"  \
  "hpj"                                                                       \
140 141 142 143
  "|bat)$"

#define CM_RESOURCE_REGEX "\\.(pdf|plist|png|jpeg|jpg|storyboard|xcassets)$"

144
#endif