CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmFilePathChecksum.h
bloba6f7bd31c99c39065845adb98f51410c17253516
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
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <array>
8 #include <cstddef>
9 #include <string>
10 #include <utility>
12 class cmMakefile;
14 /** \class cmFilePathChecksum
15 * @brief Generates a checksum for the parent directory of a file
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.
22 class cmFilePathChecksum
24 public:
25 /// Maximum number of characters to use from the path checksum
26 static const size_t partLengthDefault = 10;
28 /// @brief Parent directories are empty
29 cmFilePathChecksum();
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);
37 /// @brief Initializes the parent directories from a makefile
38 cmFilePathChecksum(cmMakefile* makefile);
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);
47 /* @brief Calculates the path checksum for the parent directory of a file
50 std::string get(std::string const& filePath) const;
52 /* @brief Same as get() but returns only the first length characters
55 std::string getPart(std::string const& filePath,
56 size_t length = partLengthDefault) const;
58 private:
59 /// List of (directory name, seed name) pairs
60 std::array<std::pair<std::string, std::string>, 4> parentDirs;