|
|
@ -1,7 +1,7 @@
|
|
|
|
#include "cmake_generator.hpp"
|
|
|
|
#include "cmake_generator.hpp"
|
|
|
|
#include "project_parser.hpp"
|
|
|
|
|
|
|
|
#include "error.hpp"
|
|
|
|
#include "error.hpp"
|
|
|
|
#include "literals.hpp"
|
|
|
|
#include "literals.hpp"
|
|
|
|
|
|
|
|
#include "project_parser.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include "fs.hpp"
|
|
|
|
#include "fs.hpp"
|
|
|
|
#include <cassert>
|
|
|
|
#include <cassert>
|
|
|
@ -639,10 +639,7 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
endl();
|
|
|
|
endl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// generate_cmake is called on the subdirectories recursively later
|
|
|
|
auto add_subdir = [&](const std::string &dir) {
|
|
|
|
if (!project.subdirs.empty()) {
|
|
|
|
|
|
|
|
gen.handle_condition(project.subdirs, [&](const std::string &, const std::vector<std::string> &subdirs) {
|
|
|
|
|
|
|
|
for (const auto &dir : subdirs) {
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
// clang-format off
|
|
|
|
comment(dir);
|
|
|
|
comment(dir);
|
|
|
|
cmd("set")("CMKR_CMAKE_FOLDER", "${CMAKE_FOLDER}");
|
|
|
|
cmd("set")("CMKR_CMAKE_FOLDER", "${CMAKE_FOLDER}");
|
|
|
@ -655,10 +652,39 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
|
|
|
|
|
|
|
|
cmd("add_subdirectory")(dir);
|
|
|
|
cmd("add_subdirectory")(dir);
|
|
|
|
cmd("set")("CMAKE_FOLDER", "${CMKR_CMAKE_FOLDER}").endl();
|
|
|
|
cmd("set")("CMAKE_FOLDER", "${CMKR_CMAKE_FOLDER}").endl();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// generate_cmake is called on the subdirectories recursively later
|
|
|
|
|
|
|
|
if (!project.project_subdirs.empty()) {
|
|
|
|
|
|
|
|
gen.handle_condition(project.project_subdirs, [&](const std::string &, const std::vector<std::string> &subdirs) {
|
|
|
|
|
|
|
|
for (const auto &dir : subdirs) {
|
|
|
|
|
|
|
|
add_subdir(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
endl();
|
|
|
|
endl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &subdir : project.subdirs) {
|
|
|
|
|
|
|
|
if (!subdir.condition.empty()) {
|
|
|
|
|
|
|
|
const auto &condition = subdir.condition;
|
|
|
|
|
|
|
|
if (project.conditions.count(condition) == 0) {
|
|
|
|
|
|
|
|
throw std::runtime_error("Unknown condition '" + condition + "' for [subdir." + subdir.name + "]");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
gen.cmd("if", condition)(RawArg(project.conditions[condition]));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gen.handle_condition(subdir.include_before,
|
|
|
|
|
|
|
|
[&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
|
|
|
|
|
|
|
gen.handle_condition(subdir.cmake_before, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add_subdir(subdir.name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gen.handle_condition(subdir.include_after, [&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
|
|
|
|
|
|
|
gen.handle_condition(subdir.cmake_after, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!subdir.condition.empty()) {
|
|
|
|
|
|
|
|
cmd("endif")();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!project.targets.empty()) {
|
|
|
|
if (!project.targets.empty()) {
|
|
|
|
for (const auto &target : project.targets) {
|
|
|
|
for (const auto &target : project.targets) {
|
|
|
@ -875,12 +901,28 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto &itr : project.subdirs) {
|
|
|
|
auto generate_subdir = [path](const fs::path &sub) {
|
|
|
|
for (const auto &sub : itr.second) {
|
|
|
|
// Skip generating for subdirectories that have a cmake.toml with a [project] in it
|
|
|
|
auto subpath = fs::path(path) / fs::path(sub);
|
|
|
|
fs::path subpath;
|
|
|
|
if (fs::exists(subpath / "cmake.toml"))
|
|
|
|
for (const auto &p : sub) {
|
|
|
|
|
|
|
|
subpath /= p;
|
|
|
|
|
|
|
|
if (parser::is_root_path(subpath.string())) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subpath = path / sub;
|
|
|
|
|
|
|
|
if (fs::exists(subpath / "cmake.toml")) {
|
|
|
|
generate_cmake(subpath.string().c_str(), false);
|
|
|
|
generate_cmake(subpath.string().c_str(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto &itr : project.project_subdirs) {
|
|
|
|
|
|
|
|
for (const auto &sub : itr.second) {
|
|
|
|
|
|
|
|
generate_subdir(sub);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &subdir : project.subdirs) {
|
|
|
|
|
|
|
|
generate_subdir(subdir.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|