cmSourceFile.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. ///! Might return a nullptr if the property is not set or invalid
  41. const char* GetProperty(const std::string& prop) const;
  42. ///! Always returns a valid pointer
  43. const char* GetSafeProperty(const std::string& prop) const;
  44. bool GetPropertyAsBool(const std::string& prop) const;
  45. /** Implement getting a property when called from a CMake language
  46. command like get_property or get_source_file_property. */
  47. const char* GetPropertyForUser(const std::string& prop);
  48. ///! Checks is the GENERATED property is set and true
  49. /// @return Equivalent to GetPropertyAsBool("GENERATED")
  50. bool GetIsGenerated() const { return this->IsGenerated; }
  51. /**
  52. * The full path to the file. The non-const version of this method
  53. * may attempt to locate the file on disk and finalize its location.
  54. * The const version of this method may return an empty string if
  55. * the non-const version has not yet been called (yes this is a
  56. * horrible interface, but is necessary for backwards
  57. * compatibility).
  58. */
  59. std::string const& GetFullPath(std::string* error = nullptr);
  60. std::string const& GetFullPath() const;
  61. /**
  62. * Get the information currently known about the source file
  63. * location without attempting to locate the file as GetFullPath
  64. * would. See cmSourceFileLocation documentation.
  65. */
  66. cmSourceFileLocation const& GetLocation() const;
  67. /**
  68. * Get the file extension of this source file.
  69. */
  70. std::string const& GetExtension() const;
  71. /**
  72. * Get the language of the compiler to use for this source file.
  73. */
  74. std::string GetLanguage();
  75. std::string GetLanguage() const;
  76. /**
  77. * Return the vector that holds the list of dependencies
  78. */
  79. const std::vector<std::string>& GetDepends() const { return this->Depends; }
  80. void AddDepend(const std::string& d) { this->Depends.push_back(d); }
  81. // Get the properties
  82. cmPropertyMap& GetProperties() { return this->Properties; }
  83. const cmPropertyMap& GetProperties() const { return this->Properties; }
  84. /**
  85. * Check whether the given source file location could refer to this
  86. * source.
  87. */
  88. bool Matches(cmSourceFileLocation const&);
  89. void SetObjectLibrary(std::string const& objlib);
  90. std::string GetObjectLibrary() const;
  91. private:
  92. cmSourceFileLocation Location;
  93. cmPropertyMap Properties;
  94. cmCustomCommand* CustomCommand = nullptr;
  95. std::string Extension;
  96. std::string Language;
  97. std::string FullPath;
  98. std::string ObjectLibrary;
  99. std::vector<std::string> Depends;
  100. bool FindFullPathFailed = false;
  101. bool IsGenerated = false;
  102. bool FindFullPath(std::string* error);
  103. bool TryFullPath(const std::string& path, const std::string& ext);
  104. void CheckExtension();
  105. void CheckLanguage(std::string const& ext);
  106. static const std::string propLANGUAGE;
  107. static const std::string propLOCATION;
  108. static const std::string propGENERATED;
  109. };
  110. // TODO: Factor out into platform information modules.
  111. #define CM_HEADER_REGEX "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$"
  112. #define CM_SOURCE_REGEX \
  113. "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|cu|f|f90|for|fpp|ftn|m|mm|rc|def|r|odl|idl|" \
  114. "hpj" \
  115. "|bat)$"
  116. #define CM_RESOURCE_REGEX "\\.(pdf|plist|png|jpeg|jpg|storyboard|xcassets)$"
  117. #endif