/src/CMake/Source/cmInstallDirs.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmInstallDirs.h" |
4 | | |
5 | | #include <cmext/string_view> |
6 | | |
7 | | #include "cmMakefile.h" |
8 | | #include "cmStringAlgorithms.h" |
9 | | #include "cmValue.h" |
10 | | |
11 | | namespace { |
12 | | std::string GetDirectory(cmMakefile const* makefile, |
13 | | std::string const& varName, std::string const& guess) |
14 | 0 | { |
15 | 0 | cmValue value = makefile->GetDefinition(varName); |
16 | 0 | if (!value.IsEmpty()) { |
17 | 0 | return value; |
18 | 0 | } |
19 | 0 | return guess; |
20 | 0 | } |
21 | | } // namespace |
22 | | |
23 | | namespace cm { |
24 | | namespace InstallDirs { |
25 | | std::string GetRuntimeDirectory(cmMakefile const* makefile) |
26 | 0 | { |
27 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_BINDIR", "bin"); |
28 | 0 | } |
29 | | |
30 | | std::string GetSbinDirectory(cmMakefile const* makefile) |
31 | 0 | { |
32 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_SBINDIR", "sbin"); |
33 | 0 | } |
34 | | |
35 | | std::string GetArchiveDirectory(cmMakefile const* makefile) |
36 | 0 | { |
37 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_LIBDIR", "lib"); |
38 | 0 | } |
39 | | |
40 | | std::string GetLibraryDirectory(cmMakefile const* makefile) |
41 | 0 | { |
42 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_LIBDIR", "lib"); |
43 | 0 | } |
44 | | |
45 | | std::string GetIncludeDirectory(cmMakefile const* makefile) |
46 | 0 | { |
47 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_INCLUDEDIR", "include"); |
48 | 0 | } |
49 | | |
50 | | std::string GetSysconfDirectory(cmMakefile const* makefile) |
51 | 0 | { |
52 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_SYSCONFDIR", "etc"); |
53 | 0 | } |
54 | | |
55 | | std::string GetSharedStateDirectory(cmMakefile const* makefile) |
56 | 0 | { |
57 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_SHAREDSTATEDIR", "com"); |
58 | 0 | } |
59 | | |
60 | | std::string GetLocalStateDirectory(cmMakefile const* makefile) |
61 | 0 | { |
62 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_LOCALSTATEDIR", "var"); |
63 | 0 | } |
64 | | |
65 | | std::string GetRunStateDirectory(cmMakefile const* makefile) |
66 | 0 | { |
67 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_RUNSTATEDIR", |
68 | 0 | cmStrCat(GetLocalStateDirectory(makefile), "/run")); |
69 | 0 | } |
70 | | |
71 | | std::string GetDataRootDirectory(cmMakefile const* makefile) |
72 | 0 | { |
73 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_DATAROOTDIR", "share"); |
74 | 0 | } |
75 | | |
76 | | std::string GetDataDirectory(cmMakefile const* makefile) |
77 | 0 | { |
78 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_DATADIR", |
79 | 0 | GetDataRootDirectory(makefile)); |
80 | 0 | } |
81 | | |
82 | | std::string GetInfoDirectory(cmMakefile const* makefile) |
83 | 0 | { |
84 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_INFODIR", |
85 | 0 | cmStrCat(GetDataRootDirectory(makefile), "/info")); |
86 | 0 | } |
87 | | |
88 | | std::string GetLocaleDirectory(cmMakefile const* makefile) |
89 | 0 | { |
90 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_LOCALEDIR", |
91 | 0 | cmStrCat(GetDataRootDirectory(makefile), "/locale")); |
92 | 0 | } |
93 | | |
94 | | std::string GetManDirectory(cmMakefile const* makefile) |
95 | 0 | { |
96 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_MANDIR", |
97 | 0 | cmStrCat(GetDataRootDirectory(makefile), "/man")); |
98 | 0 | } |
99 | | |
100 | | std::string GetDocDirectory(cmMakefile const* makefile) |
101 | 0 | { |
102 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_DOCDIR", |
103 | 0 | cmStrCat(GetDataRootDirectory(makefile), "/doc")); |
104 | 0 | } |
105 | | |
106 | | std::string GetLibExecDirectory(cmMakefile const* makefile) |
107 | 0 | { |
108 | 0 | return GetDirectory(makefile, "CMAKE_INSTALL_LIBEXECDIR", "libexec"); |
109 | 0 | } |
110 | | |
111 | | std::string GetDirectoryForType(cmMakefile const* makefile, |
112 | | cm::string_view type) |
113 | 0 | { |
114 | 0 | if (type == "BIN"_s) { |
115 | 0 | return GetRuntimeDirectory(makefile); |
116 | 0 | } |
117 | 0 | if (type == "SBIN"_s) { |
118 | 0 | return GetSbinDirectory(makefile); |
119 | 0 | } |
120 | 0 | if (type == "SYSCONF"_s) { |
121 | 0 | return GetSysconfDirectory(makefile); |
122 | 0 | } |
123 | 0 | if (type == "SHAREDSTATE"_s) { |
124 | 0 | return GetSharedStateDirectory(makefile); |
125 | 0 | } |
126 | 0 | if (type == "LOCALSTATE"_s) { |
127 | 0 | return GetLocalStateDirectory(makefile); |
128 | 0 | } |
129 | 0 | if (type == "RUNSTATE"_s) { |
130 | 0 | return GetRunStateDirectory(makefile); |
131 | 0 | } |
132 | 0 | if (type == "LIB"_s) { |
133 | 0 | return GetLibraryDirectory(makefile); |
134 | 0 | } |
135 | 0 | if (type == "INCLUDE"_s) { |
136 | 0 | return GetIncludeDirectory(makefile); |
137 | 0 | } |
138 | 0 | if (type == "DATA"_s) { |
139 | 0 | return GetDataDirectory(makefile); |
140 | 0 | } |
141 | 0 | if (type == "INFO"_s) { |
142 | 0 | return GetInfoDirectory(makefile); |
143 | 0 | } |
144 | 0 | if (type == "LOCALE"_s) { |
145 | 0 | return GetLocaleDirectory(makefile); |
146 | 0 | } |
147 | 0 | if (type == "MAN"_s) { |
148 | 0 | return GetManDirectory(makefile); |
149 | 0 | } |
150 | 0 | if (type == "DOC"_s) { |
151 | 0 | return GetDocDirectory(makefile); |
152 | 0 | } |
153 | 0 | if (type == "LIBEXEC"_s) { |
154 | 0 | return GetLibExecDirectory(makefile); |
155 | 0 | } |
156 | 0 | return std::string{}; |
157 | 0 | } |
158 | | |
159 | | } // namespace InstallDirs |
160 | | } // namespace cm |