require cmake 3.14 or higher

self-hosting
MoAlyousef 4 years ago
parent c20781f970
commit 11b3061d47

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.14)
project(cmkr VERSION 0.1.0)

@ -3,7 +3,7 @@
A CMakeLists.txt generator from TOML. Still WIP.
## Building
cmkr requires a C++17 compiler, cmake and git. It depends on toml11 by ToruNiina, which is added as a git submodule.
cmkr requires a C++17 compiler, cmake >= 3.14 and git. It depends on toml11 by ToruNiina, which is added as a git submodule.
```
git clone https://github.com/moalyousef/cmkr
cd cmkr
@ -16,7 +16,7 @@ cmake --build bin
cmkr parses cmake.toml files (using toml11) at the project directory. A basic hello world format with the minimum required fields:
```toml
[cmake]
minimum_required = "3.0"
minimum = "3.14"
[project]
name = "app"
@ -31,7 +31,7 @@ sources = ["src/main.cpp"]
This project's cmake.toml:
```toml
[cmake]
minimum_required = "3.0"
minimum = "3.14"
[project]
name = "cmkr"
@ -41,40 +41,43 @@ version = "0.1.0"
name = "cmkrlib"
type = "static"
sources = ["src/args.cpp", "src/gen.cpp", "src/help.cpp"]
include_dirs = ["vendor"]
include-dirs = ["vendor"]
features = ["cxx_std_17"]
[[bin]]
name = "cmkr"
type = "exe"
sources = ["src/main.cpp"]
link_libs = ["cmkrlib"]
link-libs = ["cmkrlib"]
```
Currently supported fields:
```toml
[cmake] # required for top-level project
minimum_required = "3.0" # required
cpp_flags = [] # optional
c_flags = [] # optional
link_flags = [] # optional
minimum = "3.14" # required
cpp-flags = [] # optional
c-flags = [] # optional
link-flags = [] # optional
subdirs = [] # optional
[project] # required per project
name = "app" # required
version = "0.1.0" # required
[dependencies] # optional, runs find_package, use "*" to ignore version
[find] # optional, runs find_package, use "*" to ignore version
boost = "1.74.0" # optional
[fetch] # optional, runs fetchContent
toml11 = { git = "https://github.com/ToruNiina/toml11", git-tag = "v3.5.0" } # optional
[[bin]] # required, can define several binaries
name = "app" # required
type = "exe" # required (exe || shared || static)
sources = ["src/main.cpp"] # required
include_dirs = [] # optional
include-dirs = [] # optional
features = [] # optional
defines = [] # optional
link_libs = [] # optional
link-libs = [] # optional
```
The cmkr executable can be run from the command-line:

@ -1,5 +1,5 @@
[cmake]
minimum_required = "3.0"
minimum = "3.14"
[project]
name = "cmkr"
@ -9,12 +9,12 @@ version = "0.1.0"
name = "cmkrlib"
type = "static"
sources = ["src/args.cpp", "src/gen.cpp", "src/help.cpp"]
include_dirs = ["vendor"]
include-dirs = ["vendor"]
features = ["cxx_std_17"]
[[bin]]
name = "cmkr"
type = "exe"
sources = ["src/main.cpp"]
link_libs = ["cmkrlib"]
link-libs = ["cmkrlib"]

@ -39,7 +39,7 @@ void generate_project(const char *str) {
std::ofstream ofs2("cmake.toml");
if (ofs2.is_open()) {
ofs2 << "[cmake]\nminimum_required = \"3.0\"\n\n[project]\nname = \""
ofs2 << "[cmake]\nminimum = \"3.14\"\n\n[project]\nname = \""
<< dir_name.string()
<< "\"\nversion = "
"\"0.1.0\"\n\n[[bin]]\nname = \""
@ -58,7 +58,7 @@ void generate_project(const char *str) {
std::ofstream ofs2("cmake.toml");
if (ofs2.is_open()) {
ofs2 << "[cmake]\nminimum_required = \"3.0\"\n\n[project]\nname = \""
ofs2 << "[cmake]\nminimum = \"3.14\"\n\n[project]\nname = \""
<< dir_name.string()
<< "\"\nversion = "
"\"0.1.0\"\n\n[[bin]]\nname = \""
@ -79,30 +79,30 @@ void generate_cmake(const char *path) {
const auto toml = toml::parse((fs::path(path) / "cmake.toml").string());
if (toml.contains("cmake")) {
const auto &cmake = toml::find(toml, "cmake");
const std::string cmake_min = toml::find(cmake, "minimum_required").as_string();
const std::string cmake_min = toml::find(cmake, "minimum").as_string();
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}";
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) {
ss << " " << flag;
}
ss << ")\n\n";
}
if (cmake.contains("c_flags")) {
if (cmake.contains("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) {
ss << " " << flag;
}
ss << ")\n\n";
}
if (cmake.contains("link_flags")) {
if (cmake.contains("link-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) {
ss << " " << flag;
}
@ -127,9 +127,9 @@ void generate_cmake(const char *path) {
ss << "project(" << proj_name << " VERSION " << proj_version << ")\n\n";
}
if (toml.contains("dependencies")) {
if (toml.contains("find")) {
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, "find");
for (const auto &dep : deps) {
ss << "find_package(" << dep.first;
if (dep.second != "*") {
@ -140,6 +140,20 @@ void generate_cmake(const char *path) {
}
}
if (toml.contains("fetch")) {
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");
ss << "include(FetchContent)\n\n";
for (const auto &dep : deps) {
ss << "FetchContent_Declare(\n\t" << dep.first << "\n";
for (const auto &arg: dep.second) {
ss << "\t" << arg.first << " " << arg.second << "\n";
}
ss << "\t)\n\n"
<< "FetchContent_MakeAvailable("<< dep.first << ")\n\n";
}
}
ss << "\nset(CMAKE_EXPORT_COMPILE_COMMANDS ON)\n\n";
if (toml.contains("bin")) {
@ -170,8 +184,8 @@ void generate_cmake(const char *path) {
<< add_command << "(" << bin_name << " " << bin_type << " ${"
<< detail::to_upper(bin_name) << "_SOURCES})\n\n";
if (bin.contains("include_dirs")) {
const auto includes = toml::find(bin, "include_dirs").as_array();
if (bin.contains("include-dirs")) {
const auto includes = toml::find(bin, "include-dirs").as_array();
ss << "target_include_directories(" << bin_name << " PUBLIC\n\t";
for (const auto &inc : includes) {
ss << inc << "\n\t";
@ -179,8 +193,8 @@ void generate_cmake(const char *path) {
ss << ")\n\n";
}
if (bin.contains("link_libs")) {
const auto libraries = toml::find(bin, "link_libs").as_array();
if (bin.contains("link-libs")) {
const auto libraries = toml::find(bin, "link-libs").as_array();
ss << "target_link_libraries(" << bin_name << " PUBLIC\n\t";
for (const auto &l : libraries) {
ss << l << "\n\t";

Loading…
Cancel
Save