|
|
@ -390,7 +390,9 @@ struct Generator {
|
|
|
|
cmd("if")(RawArg(cmake.conditions[condition]));
|
|
|
|
cmd("if")(RawArg(cmake.conditions[condition]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!itr.second.empty()) {
|
|
|
|
fn(condition, itr.second);
|
|
|
|
fn(condition, itr.second);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!condition.empty()) {
|
|
|
|
if (!condition.empty()) {
|
|
|
|
cmd("endif")();
|
|
|
|
cmd("endif")();
|
|
|
@ -573,7 +575,8 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
|
|
|
|
|
|
|
|
// generate_cmake is called on the subdirectories recursively later
|
|
|
|
// generate_cmake is called on the subdirectories recursively later
|
|
|
|
if (!cmake.subdirs.empty()) {
|
|
|
|
if (!cmake.subdirs.empty()) {
|
|
|
|
for (const auto &dir : cmake.subdirs) {
|
|
|
|
gen.handle_condition(cmake.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}");
|
|
|
@ -583,15 +586,19 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
cmd("set")("CMAKE_FOLDER", dir);
|
|
|
|
cmd("set")("CMAKE_FOLDER", dir);
|
|
|
|
cmd("endif")();
|
|
|
|
cmd("endif")();
|
|
|
|
// clang-format on
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
|
|
|
cmd("add_subdirectory")(dir);
|
|
|
|
cmd("add_subdirectory")(dir);
|
|
|
|
cmd("set")("CMAKE_FOLDER", "${CMKR_CMAKE_FOLDER}").endl();
|
|
|
|
cmd("set")("CMAKE_FOLDER", "${CMKR_CMAKE_FOLDER}").endl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
endl();
|
|
|
|
endl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!cmake.targets.empty()) {
|
|
|
|
if (!cmake.targets.empty()) {
|
|
|
|
for (const auto &target : cmake.targets) {
|
|
|
|
for (const auto &target : cmake.targets) {
|
|
|
|
comment("Target " + target.name);
|
|
|
|
comment("Target " + target.name);
|
|
|
|
|
|
|
|
cmd("set")("CMKR_TARGET", target.name);
|
|
|
|
|
|
|
|
|
|
|
|
gen.handle_condition(target.include_before,
|
|
|
|
gen.handle_condition(target.include_before,
|
|
|
|
[&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
|
|
|
[&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
|
|
|
gen.handle_condition(target.cmake_before, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
|
|
|
|
gen.handle_condition(target.cmake_before, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
|
|
|
@ -599,7 +606,7 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
auto sources_var = target.name + "_SOURCES";
|
|
|
|
auto sources_var = target.name + "_SOURCES";
|
|
|
|
|
|
|
|
|
|
|
|
bool added_toml = false;
|
|
|
|
bool added_toml = false;
|
|
|
|
cmd("unset")(sources_var).endl();
|
|
|
|
cmd("set")(sources_var, RawArg("\"\"")).endl();
|
|
|
|
gen.handle_condition(target.sources, [&](const std::string &condition, const std::vector<std::string> &condition_sources) {
|
|
|
|
gen.handle_condition(target.sources, [&](const std::string &condition, const std::vector<std::string> &condition_sources) {
|
|
|
|
auto sources = expand_cmake_paths(condition_sources, path);
|
|
|
|
auto sources = expand_cmake_paths(condition_sources, path);
|
|
|
|
if (sources.empty()) {
|
|
|
|
if (sources.empty()) {
|
|
|
@ -616,6 +623,7 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
if (!added_toml && target.type != cmake::target_interface) {
|
|
|
|
if (!added_toml && target.type != cmake::target_interface) {
|
|
|
|
cmd("list")("APPEND", sources_var, std::vector<std::string>{"cmake.toml"}).endl();
|
|
|
|
cmd("list")("APPEND", sources_var, std::vector<std::string>{"cmake.toml"}).endl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd("set")("CMKR_SOURCES", "${" + sources_var + "}");
|
|
|
|
|
|
|
|
|
|
|
|
std::string add_command;
|
|
|
|
std::string add_command;
|
|
|
|
std::string target_type;
|
|
|
|
std::string target_type;
|
|
|
@ -656,7 +664,13 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
assert("Unimplemented enum value" && false);
|
|
|
|
assert("Unimplemented enum value" && false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmd(add_command)(target.name, target_type, "${" + target.name + "_SOURCES}").endl();
|
|
|
|
cmd(add_command)(target.name, target_type).endl();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
|
|
|
|
cmd("if")(sources_var);
|
|
|
|
|
|
|
|
cmd("target_sources")(target.name, target.type == cmake::target_interface ? "INTERFACE" : "PRIVATE", "${" + sources_var + "}");
|
|
|
|
|
|
|
|
cmd("endif")().endl();
|
|
|
|
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
|
|
|
// The first executable target will become the Visual Studio startup project
|
|
|
|
// The first executable target will become the Visual Studio startup project
|
|
|
|
if (target.type == cmake::target_executable) {
|
|
|
|
if (target.type == cmake::target_executable) {
|
|
|
@ -696,6 +710,9 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
gen.handle_condition(target.include_after,
|
|
|
|
gen.handle_condition(target.include_after,
|
|
|
|
[&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
|
|
|
[&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
|
|
|
gen.handle_condition(target.cmake_after, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
|
|
|
|
gen.handle_condition(target.cmake_after, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd("unset")("CMKR_TARGET");
|
|
|
|
|
|
|
|
cmd("unset")("CMKR_SOURCES");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -755,11 +772,13 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto &sub : cmake.subdirs) {
|
|
|
|
for (const auto &itr : cmake.subdirs) {
|
|
|
|
|
|
|
|
for (const auto &sub : itr.second) {
|
|
|
|
auto subpath = fs::path(path) / fs::path(sub);
|
|
|
|
auto subpath = fs::path(path) / fs::path(sub);
|
|
|
|
if (fs::exists(subpath / "cmake.toml"))
|
|
|
|
if (fs::exists(subpath / "cmake.toml"))
|
|
|
|
generate_cmake(subpath.string().c_str(), false);
|
|
|
|
generate_cmake(subpath.string().c_str(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|