cmSourceFile.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmSourceFile_h
  4. #define cmSourceFile_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include "cmPropertyMap.h"
  7. #include "cmSourceFileLocation.h"
  8. #include "cmSourceFileLocationKind.h"
  9. #include <string>
  10. #include <vector>
  11. class cmCustomCommand;
  12. class cmMakefile;
  13. /** \class cmSourceFile
  14. * \brief Represent a class loaded from a makefile.
  15. *
  16. * cmSourceFile is represents a class loaded from
  17. * a makefile.
  18. */
  19. class cmSourceFile
  20. {
  21. public:
  22. /**
  23. * Construct with the makefile storing the source and the initial
  24. * name referencing it.
  25. */
  26. cmSourceFile(
  27. cmMakefile* mf, const std::string& name,
  28. cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
  29. ~cmSourceFile();
  30. /**
  31. * Get the list of the custom commands for this source file
  32. */
  33. cmCustomCommand* GetCustomCommand();
  34. cmCustomCommand const* GetCustomCommand() const;
  35. void SetCustomCommand(cmCustomCommand* cc);
  36. ///! Set/Get a property of this source file
  37. void SetProperty(const std::string& prop, const char* value);
  38. void AppendProperty(const std::string& prop, const char* value,
  39. bool asString = false);
  40. const char* GetProperty(const std::string& prop) const;
  41. bool GetPropertyAsBool(const std::string& prop) const;
  42. /** Implement getting a property when called from a CMake language
  43. command like get_property or get_source_file_property. */
  44. const char* GetPropertyForUser(const std::string& prop);
  45. /**
  46. * The full path to the file. The non-const version of this method
  47. * may attempt to locate the file on disk and finalize its location.
  48. * The const version of this method may return an empty string if
  49. * the non-const version has not yet been called (yes this is a
  50. * horrible interface, but is necessary for backwards
  51. * compatibility).
  52. */
  53. std::string const& GetFullPath(std::string* error = nullptr);
  54. std::string const& GetFullPath() const;
  55. /**
  56. * Get the information currently known about the source file
  57. * location without attempting to locate the file as GetFullPath
  58. * would. See cmSourceFileLocation documentation.
  59. */
  60. cmSourceFileLocation const& GetLocation() const;
  61. /**
  62. * Get the file extension of this source file.
  63. */
  64. std::string const& GetExtension() const;
  65. /**
  66. * Get the language of the compiler to use for this source file.
  67. */
  68. std::string GetLanguage();
  69. std::string GetLanguage() const;
  70. /**
  71. * Return the vector that holds the list of dependencies
  72. */
  73. const std::vector<std::string>& GetDepends() const { return this->Depends; }
  74. void AddDepend(const std::string& d) { this->Depends.push_back(d); }
  75. // Get the properties
  76. cmPropertyMap& GetProperties() { return this->Properties; }
  77. const cmPropertyMap& GetProperties() const { return this->Properties; }
  78. /**
  79. * Check whether the given source file location could refer to this
  80. * source.
  81. */
  82. bool Matches(cmSourceFileLocation const&);
  83. void SetObjectLibrary(std::string const& objlib);
  84. std::string GetObjectLibrary() const;
  85. private:
  86. cmSourceFileLocation Location;
  87. cmPropertyMap Properties;
  88. cmCustomCommand* CustomCommand;
  89. std::string Extension;
  90. std::string Language;
  91. std::string FullPath;
  92. std::string ObjectLibrary;
  93. std::vector<std::string> Depends;
  94. bool FindFullPathFailed;
  95. bool FindFullPath(std::string* error);
  96. bool TryFullPath(const std::string& path, const std::string& ext);
  97. void CheckExtension();
  98. void CheckLanguage(std::string const& ext);
  99. static const std::string propLANGUAGE;
  100. };
  101. // TODO: Factor out into platform information modules.
  102. #define CM_HEADER_REGEX "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$"
  103. #define CM_SOURCE_REGEX \
  104. "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|cu|f|f90|for|fpp|ftn|m|mm|rc|def|r|odl|idl|" \
  105. "hpj" \
  106. "|bat)$"
  107. #define CM_RESOURCE_REGEX "\\.(pdf|plist|png|jpeg|jpg|storyboard|xcassets)$"
  108. #endif