|
|
@ -48,19 +48,24 @@ int generate_project(const char *str) {
|
|
|
|
const auto tomlbuf = detail::format(cmake_toml, dir_name.c_str(), dir_name.c_str(), str);
|
|
|
|
const auto tomlbuf = detail::format(cmake_toml, dir_name.c_str(), dir_name.c_str(), str);
|
|
|
|
if (!strcmp(str, "exe")) {
|
|
|
|
if (!strcmp(str, "exe")) {
|
|
|
|
mainbuf = detail::format(hello_world, "main");
|
|
|
|
mainbuf = detail::format(hello_world, "main");
|
|
|
|
} else if (!strcmp(str, "static") || !strcmp(str, "shared")) {
|
|
|
|
} else if (!strcmp(str, "static") || !strcmp(str, "shared") !strcmp(str, "lib")) {
|
|
|
|
fs::create_directory("include");
|
|
|
|
fs::create_directory("include");
|
|
|
|
mainbuf = detail::format(hello_world, "test");
|
|
|
|
mainbuf = detail::format(hello_world, "test");
|
|
|
|
|
|
|
|
} else if (!strcmp(str, "interface")) {
|
|
|
|
|
|
|
|
fs::create_directory("include");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error("Unknown project type. Types are exe, shared, static!");
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
|
|
|
"Unknown project type. Types are exe, lib, shared, static, interface!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(str, "interface")) {
|
|
|
|
std::ofstream ofs("src/main.cpp");
|
|
|
|
std::ofstream ofs("src/main.cpp");
|
|
|
|
if (ofs.is_open()) {
|
|
|
|
if (ofs.is_open()) {
|
|
|
|
ofs << mainbuf;
|
|
|
|
ofs << mainbuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ofs.flush();
|
|
|
|
ofs.flush();
|
|
|
|
ofs.close();
|
|
|
|
ofs.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::ofstream ofs2("cmake.toml");
|
|
|
|
std::ofstream ofs2("cmake.toml");
|
|
|
|
if (ofs2.is_open()) {
|
|
|
|
if (ofs2.is_open()) {
|
|
|
@ -152,7 +157,8 @@ int generate_cmake(const char *path) {
|
|
|
|
|
|
|
|
|
|
|
|
if (!cmake.options.empty()) {
|
|
|
|
if (!cmake.options.empty()) {
|
|
|
|
for (const auto &opt : cmake.options) {
|
|
|
|
for (const auto &opt : cmake.options) {
|
|
|
|
ss << "option(" << opt.name << " \"" << opt.comment << "\" " << (opt.val ? "ON" : "OFF") << ")\n";
|
|
|
|
ss << "option(" << opt.name << " \"" << opt.comment << "\" "
|
|
|
|
|
|
|
|
<< (opt.val ? "ON" : "OFF") << ")\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -165,14 +171,19 @@ int generate_cmake(const char *path) {
|
|
|
|
if (bin.type == "exe") {
|
|
|
|
if (bin.type == "exe") {
|
|
|
|
bin_type = "";
|
|
|
|
bin_type = "";
|
|
|
|
add_command = "add_executable";
|
|
|
|
add_command = "add_executable";
|
|
|
|
} else if (bin.type == "shared" || bin.type == "static") {
|
|
|
|
} else if (bin.type == "shared" || bin.type == "static" ||
|
|
|
|
|
|
|
|
bin.type == "interface") {
|
|
|
|
bin_type = detail::to_upper(bin.type);
|
|
|
|
bin_type = detail::to_upper(bin.type);
|
|
|
|
add_command = "add_library";
|
|
|
|
add_command = "add_library";
|
|
|
|
|
|
|
|
} else if (bin.type == "lib") {
|
|
|
|
|
|
|
|
bin_type = "";
|
|
|
|
|
|
|
|
add_command = "add_library";
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error(
|
|
|
|
throw std::runtime_error(
|
|
|
|
"Unknown binary type! Supported types are exe, shared and static");
|
|
|
|
"Unknown binary type! Supported types are exe, shared and static");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!bin.sources.empty()) {
|
|
|
|
ss << "set(" << detail::to_upper(bin.name) << "_SOURCES\n";
|
|
|
|
ss << "set(" << detail::to_upper(bin.name) << "_SOURCES\n";
|
|
|
|
for (const auto &src : bin.sources) {
|
|
|
|
for (const auto &src : bin.sources) {
|
|
|
|
auto path = fs::path(src);
|
|
|
|
auto path = fs::path(src);
|
|
|
@ -187,9 +198,20 @@ int generate_cmake(const char *path) {
|
|
|
|
ss << "\t" << path << "\n";
|
|
|
|
ss << "\t" << path << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ss << "\t)\n\n"
|
|
|
|
ss << "\t)\n\n";
|
|
|
|
<< add_command << "(" << bin.name << " " << bin_type << " ${"
|
|
|
|
}
|
|
|
|
<< detail::to_upper(bin.name) << "_SOURCES})\n\n";
|
|
|
|
|
|
|
|
|
|
|
|
ss << add_command << "(" << bin.name << " " << bin_type;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!bin.sources.empty()) {
|
|
|
|
|
|
|
|
ss << " ${" << detail::to_upper(bin.name) << "_SOURCES})\n\n";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ss << ")\n\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!bin.alias.empty()) {
|
|
|
|
|
|
|
|
ss << "add_library(" << bin.alias << " ALIAS " << bin.name << ")\n\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!bin.include_dirs.empty()) {
|
|
|
|
if (!bin.include_dirs.empty()) {
|
|
|
|
ss << "target_include_directories(" << bin.name << " PUBLIC\n\t";
|
|
|
|
ss << "target_include_directories(" << bin.name << " PUBLIC\n\t";
|
|
|
|