resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmFilePathChecksum.h
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #pragma once
4
5 #include "cmConfigure.h" // IWYU pragma: keep
6
7 #include <array>
8 #include <cstddef>
9 #include <string>
10 #include <utility>
11
12 class cmMakefile;
13
14 /** \class cmFilePathChecksum
15  * @brief Generates a checksum for the parent directory of a file
16  *
17  * The checksum is calculated from the relative file path to the
18  * closest known project directory. This guarantees reproducibility
19  * when source and build directory differ e.g. for different project
20  * build directories.
21  */
22 class cmFilePathChecksum
23 {
24 public:
25   /// Maximum number of characters to use from the path checksum
26   static const size_t partLengthDefault = 10;
27
28   /// @brief Parent directories are empty
29   cmFilePathChecksum();
30
31   /// @brief Initializes the parent directories manually
32   cmFilePathChecksum(std::string const& currentSrcDir,
33                      std::string const& currentBinDir,
34                      std::string const& projectSrcDir,
35                      std::string const& projectBinDir);
36
37   /// @brief Initializes the parent directories from a makefile
38   cmFilePathChecksum(cmMakefile* makefile);
39
40   /// @brief Allows parent directories setup after construction
41   ///
42   void setupParentDirs(std::string const& currentSrcDir,
43                        std::string const& currentBinDir,
44                        std::string const& projectSrcDir,
45                        std::string const& projectBinDir);
46
47   /* @brief Calculates the path checksum for the parent directory of a file
48    *
49    */
50   std::string get(std::string const& filePath) const;
51
52   /* @brief Same as get() but returns only the first length characters
53    *
54    */
55   std::string getPart(std::string const& filePath,
56                       size_t length = partLengthDefault) const;
57
58 private:
59   /// List of (directory name, seed name) pairs
60   std::array<std::pair<std::string, std::string>, 4> parentDirs;
61 };