add missing fields

self-hosting
MoAlyousef 4 years ago
parent 9b44d37a78
commit c03c9a2d0d

@ -1,18 +1,24 @@
cmake_minimum_required(VERSION 3.0)
project(cmkr)
project(cmkr VERSION 0.1.0)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(cmkr_SOURCES
src/main.cpp
src/args.cpp
src/gen.cpp
)
add_executable(cmkr ${cmkr_SOURCES})
target_compile_features(cmkr PRIVATE cxx_std_17)
set(CMKR_SOURCES
"src/main.cpp"
"src/args.cpp"
"src/gen.cpp"
)
add_executable(cmkr ${CMKR_SOURCES})
target_include_directories(cmkr PUBLIC
"vendor"
)
target_compile_features(cmkr PUBLIC
"cxx_std_17"
)
target_include_directories(cmkr PRIVATE ${CMAKE_CURRENT_LIST_DIR}/vendor)

@ -2,26 +2,26 @@
minimum_required = "3.0" # required
cpp_flags = [""] # optional
c_flags = [""] # optional
link_flags = [""] # optional
linker_flags = [""] # optional
[project] # required
name = "cmkr" # required
version = "0.1.0" # required
[dependencies] # optional, runs find_package
# boost = "1.74.0"
# boost = "*"
[[app]] # optional
name = "cmkr" # required
sources = ["src/main.cpp", "src/args.cpp", "src/gen.cpp", "src/help.cpp"] # required
sources = ["src/main.cpp", "src/args.cpp", "src/gen.cpp"] # required
include_directories = ["vendor"] # optional
compile_features = ["cxx_std_17"] # optional
link_libraries = [""] # optional
# link_libraries = [""] # optional
# [[lib]] # optional
# name = "cmkr" # required
# sources = ["src/args.cpp", "src/gen.cpp", "src/help.cpp"] # required
# type = "shared" # required (shared, static)
# sources = ["src/args.cpp", "src/gen.cpp"] # required
# include_directories = ["vendor"] # optional
# compile_features = ["cxx_std_17"] # optional
# link_libraries = [""] # optional

@ -1,7 +1,6 @@
#include "gen.hpp"
#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <stdexcept>
@ -84,10 +83,37 @@ void generate_cmake() {
<< "project(" << proj_name << " VERSION " << proj_version << ")\n\n"
<< "set(CMAKE_EXPORT_COMPILE_COMMANDS ON)\n\n";
if (cmake.contains("cpp_flags")) {
ss << "set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}";
const auto flags = toml::find(cmake, "cpp_flags").as_array();
for (const auto &flag: flags) {
ss << " " << flag;
}
ss << ")\n\n";
}
if (cmake.contains("c_flags")) {
ss << "set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS}";
const auto flags = toml::find(cmake, "c_flags").as_array();
for (const auto &flag: flags) {
ss << " " << flag;
}
ss << ")\n\n";
}
if (cmake.contains("linker_flags")) {
ss << "set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}";
const auto flags = toml::find(cmake, "linker_flags").as_array();
for (const auto &flag: flags) {
ss << " " << flag;
}
ss << ")\n\n";
}
if (toml.contains("dependencies")) {
std::map<std::string, std::string> deps =
toml::find<std::map<std::string, std::string>>(toml, "dependencies");
for (const auto& dep : deps) {
for (const auto &dep : deps) {
ss << "find_package(" << dep.first;
if (dep.second != "*") {
ss << " " << dep.second << " CONFIG REQUIRED)\n";
@ -100,96 +126,89 @@ void generate_cmake() {
ss << "\n";
if (toml.contains("app")) {
const auto &bins = toml::find(toml, "app");
const auto &bins = toml::find(toml, "app").as_array();
for (auto i = 0; i < bins.size(); ++i) {
const auto bin = toml::find(bins, i);
for (const auto &bin: bins) {
const std::string bin_name = toml::find(bin, "name").as_string();
const auto srcs = toml::find(bin, "sources");
const auto srcs = toml::find(bin, "sources").as_array();
ss << "set(" << detail::to_upper(bin_name) << "_SOURCES\n";
for (auto j = 0; j < srcs.size(); ++j) {
const std::string source = toml::find(srcs, i).as_string();
ss << "\t" << source << "\n";
for (const auto &src: srcs) {
ss << "\t" << src << "\n";
}
ss << "\t)\n\n"
<< "add_executable(" << bin_name << " ${" << detail::to_upper(bin_name)
<< "_SOURCES})\n\n";
if (bin.contains("include_directories")) {
const auto includes = toml::find(bin, "include_directories").as_array();
ss << "target_include_directories(" << bin_name << " PUBLIC\n\t";
const auto includes = toml::find(bin, "link_libraries");
for (auto k = 0; k < includes.size(); ++k) {
const std::string inc = toml::find(includes, i).as_string();
for (const auto &inc: includes) {
ss << inc << "\n\t";
}
ss << ")";
ss << ")\n\n";
}
if (bin.contains("link_libraries")) {
const auto libraries = toml::find(bin, "link_libraries").as_array();
ss << "target_link_libraries(" << bin_name << " PUBLIC\n\t";
const auto includes = toml::find(bin, "link_libraries");
for (auto k = 0; k < includes.size(); ++k) {
const std::string inc = toml::find(includes, i).as_string();
ss << inc << "\n\t";
for (const auto &l: libraries) {
ss << l << "\n\t";
}
ss << ")";
ss << ")\n\n";
}
if (bin.contains("compile_features")) {
const auto feats = toml::find(bin, "compile_features").as_array();
ss << "target_compile_features(" << bin_name << " PUBLIC\n\t";
const auto includes = toml::find(bin, "compile_features");
for (auto k = 0; k < includes.size(); ++k) {
const std::string inc = toml::find(includes, i).as_string();
ss << inc << "\n\t";
for (const auto &feat: feats) {
ss << feat << "\n\t";
}
ss << ")";
ss << ")\n\n";
}
}
}
if (toml.contains("lib")) {
const auto &libs = toml::find(toml, "lib");
const auto &libs = toml::find(toml, "lib").as_array();
for (auto i = 0; i < libs.size(); ++i) {
const auto lib = toml::find(libs, i);
for (const auto &lib: libs) {
const std::string lib_name = toml::find(lib, "name").as_string();
const std::string type = toml::find(lib, "type").as_string();
const auto srcs = toml::find(lib, "sources");
const auto srcs = toml::find(lib, "sources").as_array();
ss << "set(" << detail::to_upper(lib_name) << "_SOURCES\n";
for (auto j = 0; j < srcs.size(); ++j) {
const std::string source = toml::find(srcs, i).as_string();
ss << "\t" << source << "\n";
for (const auto &src: srcs) {
ss << "\t" << src << "\n";
}
ss << "\t)\n\n"
<< "add_library(" << lib_name << " " << detail::to_upper(type) << " ${"
<< detail::to_upper(lib_name) << "_SOURCES})\n\n";
if (lib.contains("include_directories")) {
const auto includes = toml::find(lib, "include_directories").as_array();
ss << "target_include_directories(" << lib_name << " PUBLIC\n\t";
const auto includes = toml::find(lib, "include_directories");
for (auto k = 0; k < includes.size(); ++k) {
const std::string inc = toml::find(includes, i).as_string();
for (const auto &inc: includes) {
ss << inc << "\n\t";
}
ss << ")";
ss << ")\n\n";
}
if (lib.contains("link_libraries")) {
const auto ls = toml::find(lib, "link_libraries").as_array();
ss << "target_link_libraries(" << lib_name << " PUBLIC\n\t";
const auto includes = toml::find(lib, "link_libraries");
for (auto k = 0; k < includes.size(); ++k) {
const std::string inc = toml::find(includes, i).as_string();
ss << inc << "\n\t";
for (const auto& l: ls) {
ss << l << "\n\t";
}
ss << ")";
ss << ")\n\n";
}
if (lib.contains("compile_features")) {
const auto feats = toml::find(lib, "compile_features").as_array();
ss << "target_compile_features(" << lib_name << " PUBLIC\n\t";
const auto includes = toml::find(lib, "compile_features");
for (auto k = 0; k < includes.size(); ++k) {
const std::string inc = toml::find(includes, i).as_string();
ss << inc << "\n\t";
for (const auto &feat: feats) {
ss << feat << "\n\t";
}
ss << ")\n\n";
}
ss << ")";
}
}
@ -199,6 +218,5 @@ void generate_cmake() {
}
ofs.flush();
ofs.close();
}
}
} // namespace cmkr::gen

@ -5,7 +5,7 @@ namespace cmkr::help {
const char *version = "cmkr version 0.1.0";
const char *help_msg = R"lit(
Usage: cmk [argument]
Usage: cmkr [arguments]
arguments:
init [app|shared|static] Starts a new project in the same directory.
gen Generates CMakeLists.txt file.

Loading…
Cancel
Save