|
|
@ -1,4 +1,5 @@
|
|
|
|
#include "gen.h"
|
|
|
|
#include "gen.h"
|
|
|
|
|
|
|
|
#include "error.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <fstream>
|
|
|
|
#include <fstream>
|
|
|
@ -25,7 +26,7 @@ inline std::string to_upper(const std::string &str) {
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
|
|
|
|
void generate_project(const char *str) {
|
|
|
|
int generate_project(const char *str) {
|
|
|
|
fs::create_directory("src");
|
|
|
|
fs::create_directory("src");
|
|
|
|
auto dir_name = fs::current_path().stem();
|
|
|
|
auto dir_name = fs::current_path().stem();
|
|
|
|
if (!strcmp(str, "exe")) {
|
|
|
|
if (!strcmp(str, "exe")) {
|
|
|
@ -39,8 +40,7 @@ void generate_project(const char *str) {
|
|
|
|
|
|
|
|
|
|
|
|
std::ofstream ofs2("cmake.toml");
|
|
|
|
std::ofstream ofs2("cmake.toml");
|
|
|
|
if (ofs2.is_open()) {
|
|
|
|
if (ofs2.is_open()) {
|
|
|
|
ofs2 << "[cmake]\nminimum = \"3.14\"\n\n[project]\nname = \""
|
|
|
|
ofs2 << "[cmake]\nminimum = \"3.14\"\n\n[project]\nname = \"" << dir_name.string()
|
|
|
|
<< dir_name.string()
|
|
|
|
|
|
|
|
<< "\"\nversion = "
|
|
|
|
<< "\"\nversion = "
|
|
|
|
"\"0.1.0\"\n\n[[bin]]\nname = \""
|
|
|
|
"\"0.1.0\"\n\n[[bin]]\nname = \""
|
|
|
|
<< dir_name.string() << "\"\nsources = [\"src/main.cpp\"]\ntype = \"" << str
|
|
|
|
<< dir_name.string() << "\"\nsources = [\"src/main.cpp\"]\ntype = \"" << str
|
|
|
@ -58,8 +58,7 @@ void generate_project(const char *str) {
|
|
|
|
|
|
|
|
|
|
|
|
std::ofstream ofs2("cmake.toml");
|
|
|
|
std::ofstream ofs2("cmake.toml");
|
|
|
|
if (ofs2.is_open()) {
|
|
|
|
if (ofs2.is_open()) {
|
|
|
|
ofs2 << "[cmake]\nminimum = \"3.14\"\n\n[project]\nname = \""
|
|
|
|
ofs2 << "[cmake]\nminimum = \"3.14\"\n\n[project]\nname = \"" << dir_name.string()
|
|
|
|
<< dir_name.string()
|
|
|
|
|
|
|
|
<< "\"\nversion = "
|
|
|
|
<< "\"\nversion = "
|
|
|
|
"\"0.1.0\"\n\n[[bin]]\nname = \""
|
|
|
|
"\"0.1.0\"\n\n[[bin]]\nname = \""
|
|
|
|
<< dir_name.string() << "\"\nsources = [\"src/lib.cpp\"]\ntype = \"" << str
|
|
|
|
<< dir_name.string() << "\"\nsources = [\"src/lib.cpp\"]\ntype = \"" << str
|
|
|
@ -70,9 +69,10 @@ void generate_project(const char *str) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error("Unknown project type. Types are exe, shared, static!");
|
|
|
|
throw std::runtime_error("Unknown project type. Types are exe, shared, static!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void generate_cmake(const char *path) {
|
|
|
|
int generate_cmake(const char *path) {
|
|
|
|
std::stringstream ss;
|
|
|
|
std::stringstream ss;
|
|
|
|
std::vector<std::string> subdirs;
|
|
|
|
std::vector<std::string> subdirs;
|
|
|
|
|
|
|
|
|
|
|
@ -83,30 +83,30 @@ void generate_cmake(const char *path) {
|
|
|
|
ss << "cmake_minimum_required(VERSION " << cmake_min << ")\n\n";
|
|
|
|
ss << "cmake_minimum_required(VERSION " << cmake_min << ")\n\n";
|
|
|
|
|
|
|
|
|
|
|
|
if (cmake.contains("cpp-flags")) {
|
|
|
|
if (cmake.contains("cpp-flags")) {
|
|
|
|
ss << "set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}";
|
|
|
|
ss << "set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}\"";
|
|
|
|
const auto flags = toml::find(cmake, "cpp-flags").as_array();
|
|
|
|
const auto flags = toml::find(cmake, "cpp-flags").as_array();
|
|
|
|
for (const auto &flag : flags) {
|
|
|
|
for (const auto &flag : flags) {
|
|
|
|
ss << " " << flag;
|
|
|
|
ss << " " << std::string(flag.as_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ss << ")\n\n";
|
|
|
|
ss << "\")\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (cmake.contains("c-flags")) {
|
|
|
|
if (cmake.contains("c-flags")) {
|
|
|
|
ss << "set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS}";
|
|
|
|
ss << "set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS}\"";
|
|
|
|
const auto flags = toml::find(cmake, "c-flags").as_array();
|
|
|
|
const auto flags = toml::find(cmake, "c-flags").as_array();
|
|
|
|
for (const auto &flag : flags) {
|
|
|
|
for (const auto &flag : flags) {
|
|
|
|
ss << " " << flag;
|
|
|
|
ss << " " << std::string(flag.as_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ss << ")\n\n";
|
|
|
|
ss << "\")\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (cmake.contains("link-flags")) {
|
|
|
|
if (cmake.contains("link-flags")) {
|
|
|
|
ss << "set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}";
|
|
|
|
ss << "set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}\"";
|
|
|
|
const auto flags = toml::find(cmake, "link-flags").as_array();
|
|
|
|
const auto flags = toml::find(cmake, "link-flags").as_array();
|
|
|
|
for (const auto &flag : flags) {
|
|
|
|
for (const auto &flag : flags) {
|
|
|
|
ss << " " << flag;
|
|
|
|
ss << " " << std::string(flag.as_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ss << ")\n\n";
|
|
|
|
ss << "\")\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (cmake.contains("subdirs")) {
|
|
|
|
if (cmake.contains("subdirs")) {
|
|
|
@ -142,7 +142,8 @@ void generate_cmake(const char *path) {
|
|
|
|
|
|
|
|
|
|
|
|
if (toml.contains("fetch-content")) {
|
|
|
|
if (toml.contains("fetch-content")) {
|
|
|
|
std::map<std::string, std::map<std::string, std::string>> deps =
|
|
|
|
std::map<std::string, std::map<std::string, std::string>> deps =
|
|
|
|
toml::find<std::map<std::string, std::map<std::string, std::string>>>(toml, "fetch-content");
|
|
|
|
toml::find<std::map<std::string, std::map<std::string, std::string>>>(toml,
|
|
|
|
|
|
|
|
"fetch-content");
|
|
|
|
ss << "include(FetchContent)\n\n";
|
|
|
|
ss << "include(FetchContent)\n\n";
|
|
|
|
for (const auto &dep : deps) {
|
|
|
|
for (const auto &dep : deps) {
|
|
|
|
ss << "FetchContent_Declare(\n\t" << dep.first << "\n";
|
|
|
|
ss << "FetchContent_Declare(\n\t" << dep.first << "\n";
|
|
|
@ -154,7 +155,7 @@ void generate_cmake(const char *path) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ss << "\nset(CMAKE_EXPORT_COMPILE_COMMANDS ON)\n\n";
|
|
|
|
ss << "set(CMAKE_EXPORT_COMPILE_COMMANDS ON)\n\n";
|
|
|
|
|
|
|
|
|
|
|
|
if (toml.contains("bin")) {
|
|
|
|
if (toml.contains("bin")) {
|
|
|
|
const auto &bins = toml::find(toml, "bin").as_array();
|
|
|
|
const auto &bins = toml::find(toml, "bin").as_array();
|
|
|
@ -233,13 +234,22 @@ void generate_cmake(const char *path) {
|
|
|
|
for (const auto &sub : subdirs) {
|
|
|
|
for (const auto &sub : subdirs) {
|
|
|
|
generate_cmake(sub.c_str());
|
|
|
|
generate_cmake(sub.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace cmkr::gen
|
|
|
|
} // namespace cmkr::gen
|
|
|
|
|
|
|
|
|
|
|
|
void cmkr_gen_generate_project(const char *typ) {
|
|
|
|
int cmkr_gen_generate_project(const char *typ) {
|
|
|
|
cmkr::gen::generate_project(typ);
|
|
|
|
try {
|
|
|
|
|
|
|
|
return cmkr::gen::generate_project(typ);
|
|
|
|
|
|
|
|
} catch (...) {
|
|
|
|
|
|
|
|
return cmkr::error::Status(cmkr::error::Status::Code::InitError);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cmkr_gen_generate_cmake(const char *path) {
|
|
|
|
int cmkr_gen_generate_cmake(const char *path) {
|
|
|
|
cmkr::gen::generate_cmake(path);
|
|
|
|
try {
|
|
|
|
|
|
|
|
return cmkr::gen::generate_cmake(path);
|
|
|
|
|
|
|
|
} catch (...) {
|
|
|
|
|
|
|
|
return cmkr::error::Status(cmkr::error::Status::Code::GenerationError);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|