From 4db372900d0714840da35ac1dc06a79e8badc430 Mon Sep 17 00:00:00 2001 From: MoAlyousef Date: Wed, 9 Sep 2020 21:29:14 +0300 Subject: [PATCH] add defs --- .gitignore | 3 ++- README.md | 5 +++-- cmake.toml | 1 + src/gen.cpp | 11 +++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a0d3cab..9287d31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ bin compile_commands.json .clangd -temp.* \ No newline at end of file +temp.* +.vs \ No newline at end of file diff --git a/README.md b/README.md index a475820..f7709a6 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ type = "exe" # required (exe || shared || static) sources = ["src/main.cpp", "src/args.cpp", "src/gen.cpp"] # required include_directories = ["vendor"] # optional compile_features = ["cxx_std_17"] # optional +# definitions = [] # optional # link_libraries = [] # optional ``` @@ -59,13 +60,13 @@ Usage: cmkr [arguments] arguments: init [exe|shared|static] Starts a new project in the same directory. gen Generates CMakeLists.txt file. - build [cmake args...] Run cmake and build. + build [extra cmake args] Run cmake and build. help Show help. version Current cmkr version. ``` The build command invokes cmake and the default build-system on your platform, it also accepts extra cmake arguments: ``` -cmkr build -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain -DCMAKE_BUILD_TYPE=Release +cmkr build -GNinja -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain -DCMAKE_BUILD_TYPE=Release ``` ## Roadmap diff --git a/cmake.toml b/cmake.toml index c662dac..7c06070 100644 --- a/cmake.toml +++ b/cmake.toml @@ -18,5 +18,6 @@ type = "exe" # required (exe || shared || static) sources = ["src/main.cpp", "src/args.cpp", "src/gen.cpp"] # required include_directories = ["vendor"] # optional compile_features = ["cxx_std_17"] # optional +# definitions = [] # optional # link_libraries = [] # optional diff --git a/src/gen.cpp b/src/gen.cpp index 15aae78..3572acc 100644 --- a/src/gen.cpp +++ b/src/gen.cpp @@ -167,6 +167,7 @@ void generate_cmake() { } 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"; @@ -175,6 +176,7 @@ void generate_cmake() { } 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"; @@ -183,6 +185,15 @@ void generate_cmake() { } ss << ")\n\n"; } + + if (bin.contains("definitions")) { + const auto defs = toml::find(bin, "definitions").as_array(); + ss << "target_add_definitions(" << bin_name << " PUBLIC\n\t"; + for (const auto &def : defs) { + ss << def << "\n\t"; + } + ss << ")\n\n"; + } } }