resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmCxxModuleMapper.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 <functional>
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 #include <cm/optional>
14 #include <cmext/string_view>
15
16 #include "cmScanDepFormat.h"
17
18 enum class CxxModuleMapFormat
19 {
20   Gcc,
21   Msvc,
22 };
23
24 struct CxxModuleLocations
25 {
26   // The path from which all relative paths should be computed. If
27   // this is relative, it is relative to the compiler's working
28   // directory.
29   std::string RootDirectory;
30
31   // A function to convert a full path to a path for the generator.
32   std::function<std::string(std::string const&)> PathForGenerator;
33
34   // Lookup the BMI location of a logical module name.
35   std::function<cm::optional<std::string>(std::string const&)>
36     BmiLocationForModule;
37
38   // Returns the generator path (if known) for the BMI given a
39   // logical module name.
40   cm::optional<std::string> BmiGeneratorPathForModule(
41     std::string const& logical_name) const;
42 };
43
44 struct CxxModuleReference
45 {
46   // The path to the module file used.
47   std::string Path;
48   // How the module was looked up.
49   LookupMethod Method;
50 };
51
52 struct CxxModuleUsage
53 {
54   // The usage requirements for this object.
55   std::map<std::string, std::set<std::string>> Usage;
56
57   // The references for this object.
58   std::map<std::string, CxxModuleReference> Reference;
59
60   // Add a reference to a module.
61   //
62   // Returns `true` if it matches how it was found previously, `false` if it
63   // conflicts.
64   bool AddReference(std::string const& logical, std::string const& loc,
65                     LookupMethod method);
66 };
67
68 // Return the extension to use for a given modulemap format.
69 cm::static_string_view CxxModuleMapExtension(
70   cm::optional<CxxModuleMapFormat> format);
71
72 // Fill in module usage information for internal usages.
73 //
74 // Returns the set of unresolved module usage requirements (these form an
75 // import cycle).
76 std::set<std::string> CxxModuleUsageSeed(
77   CxxModuleLocations const& loc, std::vector<cmScanDepInfo> const& objects,
78   CxxModuleUsage& usages);
79
80 // Return the contents of the module map in the given format for the
81 // object file.
82 std::string CxxModuleMapContent(CxxModuleMapFormat format,
83                                 CxxModuleLocations const& loc,
84                                 cmScanDepInfo const& obj,
85                                 CxxModuleUsage const& usages);