cmSourceFile.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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>
  6. #include "cmPropertyMap.h"
  7. #include "cmSourceFileLocation.h"
  8. #include <string>
  9. #include <vector>
  10. class cmCustomCommand;
  11. class cmMakefile;
  12. /** \class cmSourceFile
  13. * \brief Represent a class loaded from a makefile.
  14. *
  15. * cmSourceFile is represents a class loaded from
  16. * a makefile.
  17. */
  18. class cmSourceFile
  19. {
  20. public:
  21. /**
  22. * Construct with the makefile storing the source and the initial
  23. * name referencing it.
  24. */
  25. cmSourceFile(cmMakefile* mf, const std::string& name);
  26. ~cmSourceFile();
  27. /**
  28. * Get the list of the custom commands for this source file
  29. */
  30. cmCustomCommand* GetCustomCommand();
  31. cmCustomCommand const* GetCustomCommand() const;
  32. void SetCustomCommand(cmCustomCommand* cc);
  33. ///! Set/Get a property of this source file
  34. void SetProperty(const std::string& prop, const char* value);
  35. void AppendProperty(const std::string& prop, const char* value,
  36. bool asString = false);
  37. const char* GetProperty(const std::string& prop) const;
  38. bool GetPropertyAsBool(const std::string& prop) const;
  39. /** Implement getting a property when called from a CMake language
  40. command like get_property or get_source_file_property. */
  41. const char* GetPropertyForUser(const std::string& prop);
  42. /**
  43. * The full path to the file. The non-const version of this method
  44. * may attempt to locate the file on disk and finalize its location.
  45. * The const version of this method may return an empty string if
  46. * the non-const version has not yet been called (yes this is a
  47. * horrible interface, but is necessary for backwards
  48. * compatibility).
  49. */
  50. std::string const& GetFullPath(std::string* error = CM_NULLPTR);
  51. std::string const& GetFullPath() const;
  52. /**
  53. * Get the information currently known about the source file
  54. * location without attempting to locate the file as GetFullPath
  55. * would. See cmSourceFileLocation documentation.
  56. */
  57. cmSourceFileLocation const& GetLocation() const;
  58. /**
  59. * Get the file extension of this source file.
  60. */
  61. std::string const& GetExtension() const;
  62. /**
  63. * Get the language of the compiler to use for this source file.
  64. */
  65. std::string GetLanguage();
  66. std::string GetLanguage() const;
  67. /**
  68. * Return the vector that holds the list of dependencies
  69. */
  70. const std::vector<std::string>& GetDepends() const { return this->Depends; }
  71. void AddDepend(const std::string& d) { this->Depends.push_back(d); }
  72. // Get the properties
  73. cmPropertyMap& GetProperties() { return this->Properties; }
  74. /**
  75. * Check whether the given source file location could refer to this
  76. * source.
  77. */
  78. bool Matches(cmSourceFileLocation const&);
  79. void SetObjectLibrary(std::string const& objlib);
  80. std::string GetObjectLibrary() const;
  81. private:
  82. cmSourceFileLocation Location;
  83. cmPropertyMap Properties;
  84. cmCustomCommand* CustomCommand;
  85. std::string Extension;
  86. std::string Language;
  87. std::string FullPath;
  88. std::string ObjectLibrary;
  89. std::vector<std::string> Depends;
  90. bool FindFullPathFailed;
  91. bool IsUiFile;
  92. bool FindFullPath(std::string* error);
  93. bool TryFullPath(const std::string& path, const std::string& ext);
  94. void CheckExtension();
  95. void CheckLanguage(std::string const& ext);
  96. static const std::string propLANGUAGE;
  97. };
  98. // TODO: Factor out into platform information modules.
  99. #define CM_HEADER_REGEX "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$"
  100. #endif