add missing fields

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

@ -1,18 +1,24 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(cmkr)
project(cmkr VERSION 0.1.0) project(cmkr VERSION 0.1.0)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 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 minimum_required = "3.0" # required
cpp_flags = [""] # optional cpp_flags = [""] # optional
c_flags = [""] # optional c_flags = [""] # optional
link_flags = [""] # optional linker_flags = [""] # optional
[project] # required [project] # required
name = "cmkr" # required name = "cmkr" # required
version = "0.1.0" # required version = "0.1.0" # required
[dependencies] # optional, runs find_package [dependencies] # optional, runs find_package
# boost = "1.74.0" # boost = "*"
[[app]] # optional [[app]] # optional
name = "cmkr" # required 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 include_directories = ["vendor"] # optional
compile_features = ["cxx_std_17"] # optional compile_features = ["cxx_std_17"] # optional
link_libraries = [""] # optional # link_libraries = [""] # optional
# [[lib]] # optional # [[lib]] # optional
# name = "cmkr" # required # name = "cmkr" # required
# sources = ["src/args.cpp", "src/gen.cpp", "src/help.cpp"] # required
# type = "shared" # required (shared, static) # type = "shared" # required (shared, static)
# sources = ["src/args.cpp", "src/gen.cpp"] # required
# include_directories = ["vendor"] # optional # include_directories = ["vendor"] # optional
# compile_features = ["cxx_std_17"] # optional # compile_features = ["cxx_std_17"] # optional
# link_libraries = [""] # optional # link_libraries = [""] # optional

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

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

Loading…
Cancel
Save