File: cmPkgConfigResolver.h

package info (click to toggle)
cmake 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 147,412 kB
  • sloc: ansic: 403,924; cpp: 290,826; sh: 4,091; python: 3,357; yacc: 3,106; lex: 1,189; f90: 532; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 230; perl: 217; objc: 215; xml: 198; makefile: 98; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (175 lines) | stat: -rw-r--r-- 4,823 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file LICENSE.rst or https://cmake.org/licensing for details.  */

#pragma once

#include "cmConfigure.h" // IWYU pragma: keep

#include <string>
#include <unordered_map>
#include <vector>

#include <cm/optional>
#include <cm/string_view>

// From cmPkgConfigParser.h, IWYU doesn't like including the header
struct cmPkgConfigEntry;

struct cmPkgConfigCflagsResult
{
  std::string Flagline;
  std::vector<std::string> Includes;
  std::vector<std::string> CompileOptions;
};

struct cmPkgConfigLibsResult
{
  std::string Flagline;
  std::vector<std::string> LibDirs;
  std::vector<std::string> LibNames;
  std::vector<std::string> LinkOptions;
};

struct cmPkgConfigVersionReq
{
  enum
  {
    ANY = 0,
    LT,
    LT_EQ,
    EQ,
    NEQ,
    GT_EQ,
    GT,
  } Operation = ANY;
  std::string Version;

  std::string string() const;
};

struct cmPkgConfigDependency
{
  std::string Name;
  cmPkgConfigVersionReq VerReq;
};

struct cmPkgConfigEnv
{
  cm::optional<std::vector<std::string>> Path;
  cm::optional<std::vector<std::string>> LibDirs;
  cm::optional<std::vector<std::string>> SysCflags;
  cm::optional<std::vector<std::string>> SysLibs;

  cm::optional<std::string> SysrootDir;
  cm::optional<std::string> TopBuildDir;
  std::vector<std::string> search;

  cm::optional<bool> DisableUninstalled;

  bool AllowSysCflags = true;
  bool AllowSysLibs = true;
};

class cmPkgConfigResult
{
public:
  std::unordered_map<std::string, std::string> Keywords;
  std::unordered_map<std::string, std::string> Variables;

  std::string Name();
  std::string Description();
  std::string Version();

  std::vector<cmPkgConfigDependency> Conflicts();
  std::vector<cmPkgConfigDependency> Provides();
  std::vector<cmPkgConfigDependency> Requires(bool priv = false);

  cmPkgConfigCflagsResult Cflags(bool priv = false);
  cmPkgConfigLibsResult Libs(bool priv = false);

  cmPkgConfigEnv* env;

private:
  std::string StrOrDefault(std::string const& key, cm::string_view def = "");
};

class cmPkgConfigResolver
{
  friend class cmPkgConfigResult;

public:
  static cm::optional<cmPkgConfigResult> ResolveStrict(
    std::vector<cmPkgConfigEntry> const& entries, cmPkgConfigEnv env);

  static cm::optional<cmPkgConfigResult> ResolvePermissive(
    std::vector<cmPkgConfigEntry> const& entries, cmPkgConfigEnv env);

  static cmPkgConfigResult ResolveBestEffort(
    std::vector<cmPkgConfigEntry> const& entries, cmPkgConfigEnv env);

  static cmPkgConfigVersionReq ParseVersion(std::string const& version);

  static bool CheckVersion(cmPkgConfigVersionReq const& desired,
                           std::string const& provided);

  static void ReplaceSep(std::string& list);

#ifdef _WIN32
  static char const Sep = ';';
#else
  static char const Sep = ':';
#endif

private:
  static std::string HandleVariablePermissive(
    cmPkgConfigEntry const& entry,
    std::unordered_map<std::string, std::string> const& variables);

  static cm::optional<std::string> HandleVariableStrict(
    cmPkgConfigEntry const& entry,
    std::unordered_map<std::string, std::string> const& variables);

  static std::string HandleKeyword(
    cmPkgConfigEntry const& entry,
    std::unordered_map<std::string, std::string> const& variables);

  static std::vector<cm::string_view> TokenizeFlags(
    std::string const& flagline);

  static cmPkgConfigCflagsResult MangleCflags(
    std::vector<cm::string_view> const& flags);

  static cmPkgConfigCflagsResult MangleCflags(
    std::vector<cm::string_view> const& flags, std::string const& sysroot);

  static cmPkgConfigCflagsResult MangleCflags(
    std::vector<cm::string_view> const& flags,
    std::vector<std::string> const& syspaths);

  static cmPkgConfigCflagsResult MangleCflags(
    std::vector<cm::string_view> const& flags, std::string const& sysroot,
    std::vector<std::string> const& syspaths);

  static cmPkgConfigLibsResult MangleLibs(
    std::vector<cm::string_view> const& flags);

  static cmPkgConfigLibsResult MangleLibs(
    std::vector<cm::string_view> const& flags, std::string const& sysroot);

  static cmPkgConfigLibsResult MangleLibs(
    std::vector<cm::string_view> const& flags,
    std::vector<std::string> const& syspaths);

  static cmPkgConfigLibsResult MangleLibs(
    std::vector<cm::string_view> const& flags, std::string const& sysroot,
    std::vector<std::string> const& syspaths);

  static std::string Reroot(cm::string_view flag, cm::string_view prefix,
                            std::string const& sysroot);

  static cmPkgConfigVersionReq ParseVersion(std::string::const_iterator& cur,
                                            std::string::const_iterator end);

  static std::vector<cmPkgConfigDependency> ParseDependencies(
    std::string const& deps);
};