cmSourceFile.h 4.51 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
Brad King's avatar
Brad King committed
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
  /**
   * Get the list of the custom commands for this source file
   */
40
41
  cmCustomCommand* GetCustomCommand();
  cmCustomCommand const* GetCustomCommand() const;
42
  void SetCustomCommand(cmCustomCommand* cc);
43

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

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

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

62
  /**
63
64
65
66
67
68
   * 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).
69
   */
Daniel Pfeifer's avatar
Daniel Pfeifer committed
70
  std::string const& GetFullPath(std::string* error = nullptr);
71
  std::string const& GetFullPath() const;
72

73
74
75
76
77
78
79
  /**
   * 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;

80
  /**
81
   * Get the file extension of this source file.
82
   */
83
  std::string const& GetExtension() const;
84

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

91
  /**
92
   * Return the vector that holds the list of dependencies
93
   */
94
  const std::vector<std::string>& GetDepends() const { return this->Depends; }
Ben Boeckel's avatar
Ben Boeckel committed
95
  void AddDepend(const std::string& d) { this->Depends.push_back(d); }
96

97
  // Get the properties
98
  cmPropertyMap& GetProperties() { return this->Properties; }
99
  const cmPropertyMap& GetProperties() const { return this->Properties; }
100

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

107
108
109
  void SetObjectLibrary(std::string const& objlib);
  std::string GetObjectLibrary() const;

110
private:
111
  cmSourceFileLocation Location;
112
  cmPropertyMap Properties;
113
  cmCustomCommand* CustomCommand = nullptr;
114
115
  std::string Extension;
  std::string Language;
Ken Martin's avatar
Ken Martin committed
116
  std::string FullPath;
117
  std::string ObjectLibrary;
Stephen Kelly's avatar
Stephen Kelly committed
118
  std::vector<std::string> Depends;
119
120
  bool FindFullPathFailed = false;
  bool IsGenerated = false;
121

122
  bool FindFullPath(std::string* error);
123
  bool TryFullPath(const std::string& path, const std::string& ext);
124
  void CheckExtension();
125
  void CheckLanguage(std::string const& ext);
126

127
  static const std::string propLANGUAGE;
128
129
  static const std::string propLOCATION;
  static const std::string propGENERATED;
130
131
};

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

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

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

142
#endif