diff --git a/docs/cmake-toml.md b/docs/cmake-toml.md index f78c7ea..cdeb4dd 100644 --- a/docs/cmake-toml.md +++ b/docs/cmake-toml.md @@ -302,6 +302,7 @@ condition = "MYPROJECT_BUILD_EXAMPLES" type = "executable" link-libraries = ["myproject::mylib"] add-function = "" +add-arguments = ["myoption"] pass-sources = false # Properties from the template are merged with the ones here @@ -313,6 +314,7 @@ sources = ["src/myexample.cpp"] The properties declared on a `template` are the same as the ones you use for targets. The only exceptions are: - `add-function`: Specifies a custom add function. Projects like [pybind11](https://pybind11.readthedocs.io/en/stable/cmake/index.html#new-findpython-mode) have their own `add_xxx` function, which you can specify here. +- `add-arguments`: Arguments to pass to the `add-function` before the list of sources. See [cmake_parse_arguments](https://cmake.org/cmake/help/latest/command/cmake_parse_arguments.html) for more details. - `pass-sources`: Pass sources directly to the add function instead of using `target_sources`. ## Tests and installation (unfinished) diff --git a/include/project_parser.hpp b/include/project_parser.hpp index 5f37142..0396557 100644 --- a/include/project_parser.hpp +++ b/include/project_parser.hpp @@ -118,6 +118,7 @@ struct Target { struct Template { Target outline; std::string add_function; + std::vector add_arguments; bool pass_sources_to_add_function = false; }; diff --git a/src/cmake_generator.cpp b/src/cmake_generator.cpp index 6949a66..b78f15f 100644 --- a/src/cmake_generator.cpp +++ b/src/cmake_generator.cpp @@ -1372,12 +1372,11 @@ void generate_cmake(const char *path, const parser::Project *parent_project) { // Handle custom add commands from templates. if (tmplate != nullptr && !tmplate->add_function.empty()) { add_command = tmplate->add_function; - target_type_string = ""; // TODO: let templates supply options to the add_command here? if (tmplate->pass_sources_to_add_function) { - cmd(add_command)(target.name, target_type_string, "${" + sources_var + "}"); + cmd(add_command)(target.name, tmplate->add_arguments, "${" + sources_var + "}"); } else { - cmd(add_command)(target.name, target_type_string).endl(); + cmd(add_command)(target.name, tmplate->add_arguments).endl(); if (has_sources) { cmd("target_sources")(target.name, target_type == parser::target_interface ? "INTERFACE" : "PRIVATE", "${" + sources_var + "}"); diff --git a/src/project_parser.cpp b/src/project_parser.cpp index 4429dbc..806845f 100644 --- a/src/project_parser.cpp +++ b/src/project_parser.cpp @@ -785,6 +785,7 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p tmplate.outline = parse_target(name, t, true); t.optional("add-function", tmplate.add_function); + t.optional("add-arguments", tmplate.add_arguments); t.optional("pass-sources-to-add-function", tmplate.pass_sources_to_add_function); t.optional("pass-sources", tmplate.pass_sources_to_add_function);