MCPcopy Create free account
hub / github.com/build-cpp/cmkr / Project

Method Project

src/project_parser.cpp:212–891  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

210};
211
212Project::Project(const Project *parent, const std::string &path, bool build) : parent(parent) {
213 const auto toml_path = fs::path(path) / "cmake.toml";
214 if (!fs::exists(toml_path)) {
215 throw std::runtime_error("File not found '" + toml_path.string() + "'");
216 }
217 const auto toml = toml::parse<toml::discard_comments, tsl::ordered_map, std::vector>(toml_path.string());
218 if (toml.size() == 0) {
219 throw std::runtime_error("Empty TOML '" + toml_path.string() + "'");
220 }
221
222 TomlCheckerRoot checker(toml);
223
224 if (checker.contains("cmake")) {
225 auto &cmake = checker.create(toml, "cmake");
226
227 cmake.required("version", cmake_version);
228
229 if (cmake.contains("bin-dir")) {
230 throw_key_error("bin-dir has been renamed to build-dir", "bin-dir", cmake.find("bin-dir"));
231 }
232
233 cmake.optional("build-dir", build_dir);
234 cmake.optional("generator", generator);
235 cmake.optional("config", config);
236 cmake.optional("arguments", gen_args);
237 cmake.optional("allow-in-tree", allow_in_tree);
238
239 if (cmake.contains("cmkr-include")) {
240 const auto &cmkr_include_kv = cmake.find("cmkr-include");
241 if (cmkr_include_kv.is_string()) {
242 cmkr_include = cmkr_include_kv.as_string();
243 } else {
244 // Allow disabling this feature with cmkr-include = false
245 cmkr_include = "";
246 }
247 }
248
249 cmake.optional("cpp-flags", cppflags);
250 cmake.optional("c-flags", cflags);
251 cmake.optional("link-flags", linkflags);
252 }
253
254 // Skip the rest of the parsing when building
255 if (build) {
256 checker.check(conditions, false);
257 return;
258 }
259
260 // Reasonable default conditions (you can override these if you desire)
261 if (parent == nullptr) {
262 conditions["windows"] = R"cmake(WIN32)cmake";
263 conditions["macos"] = R"cmake(CMAKE_SYSTEM_NAME MATCHES "Darwin")cmake";
264 conditions["unix"] = R"cmake(UNIX)cmake";
265 conditions["bsd"] = R"cmake(CMAKE_SYSTEM_NAME MATCHES "BSD")cmake";
266 conditions["linux"] = conditions["lunix"] = R"cmake(CMAKE_SYSTEM_NAME MATCHES "Linux")cmake";
267 conditions["gcc"] = R"cmake(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")cmake";
268 conditions["msvc"] = R"cmake(MSVC)cmake";
269 conditions["clang"] =

Callers

nothing calls this directly

Calls 12

cmake_minimum_versionMethod · 0.95
throw_key_errorFunction · 0.85
parse_msvcRuntimeTypeFunction · 0.85
print_key_warningFunction · 0.85
parse_targetTypeFunction · 0.85
requiredMethod · 0.80
optionalMethod · 0.80
emptyMethod · 0.80
visistedMethod · 0.80
visitMethod · 0.80
containsMethod · 0.45
checkMethod · 0.45

Tested by

no test coverage detected