diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4d25124..de67108 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: - name: Test run: | cd build/tests - ctest -C ${{ env.BUILD_TYPE }} + ctest -C ${{ env.BUILD_TYPE }} --verbose - name: Upload artifacts uses: actions/upload-artifact@v2 diff --git a/CMakeLists.txt b/CMakeLists.txt index ff35240..bc72a73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,6 @@ list(APPEND cmkr_SOURCES "include/arguments.hpp" "include/build.hpp" "include/cmake_generator.hpp" - "include/enum_helper.hpp" "include/error.hpp" "include/fs.hpp" "include/help.hpp" diff --git a/docs/examples/interface.md b/docs/examples/interface.md index 3e27f87..976ed86 100644 --- a/docs/examples/interface.md +++ b/docs/examples/interface.md @@ -19,6 +19,7 @@ description = "Header-only library" [target.mylib] type = "interface" include-directories = ["include"] +compile-features = ["cxx_std_11"] [target.example] type = "executable" diff --git a/docs/examples/templates.md b/docs/examples/templates.md new file mode 100644 index 0000000..398f061 --- /dev/null +++ b/docs/examples/templates.md @@ -0,0 +1,40 @@ +--- +# Automatically generated from tests/templates/cmake.toml - DO NOT EDIT +layout: default +title: Target templates +permalink: /examples/templates +parent: Examples +nav_order: 7 +--- + +# Target templates + +To avoid repeating yourself in targets you can create your own target type (template). All properties of the template are inherited when used as a target type. + +```toml +[project] +name = "templates" +description = "Target templates" + +[template.app] +type = "executable" +sources = ["src/templates.cpp"] +compile-definitions = ["IS_APP"] + +# Unlike interface targets you can also inherit properties +[template.app.properties] +CXX_STANDARD = "11" +CXX_STANDARD_REQUIRED = true + +[target.app-a] +type = "app" +compile-definitions = ["APP_A"] + +[target.app-b] +type = "app" +compile-definitions = ["APP_B"] +``` + +**Note**: In most cases you probably want to use an [interface](/examples/interface) target instead. + +This page was automatically generated from [tests/templates/cmake.toml](https://github.com/build-cpp/cmkr/tree/main/tests/templates/cmake.toml). diff --git a/include/enum_helper.hpp b/include/enum_helper.hpp deleted file mode 100644 index 7aafd78..0000000 --- a/include/enum_helper.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// https://codereview.stackexchange.com/a/14315 - -#include -#include -#include -#include - -// This is the type that will hold all the strings. -// Each enumeration type will declare its own specialization. -// Any enum that does not have a specialization will generate a compiler error -// indicating that there is no definition of this variable (as there should be -// be no definition of a generic version). -template -struct enumStrings { - static char const *data[]; -}; - -// This is a utility type. -// Created automatically. Should not be used directly. -template -struct enumRefHolder { - T &enumVal; - enumRefHolder(T &enumVal) : enumVal(enumVal) {} -}; -template -struct enumConstRefHolder { - T const &enumVal; - enumConstRefHolder(T const &enumVal) : enumVal(enumVal) {} -}; - -// The next two functions do the actual work of reading/writing an -// enum as a string. -template -std::ostream &operator<<(std::ostream &str, enumConstRefHolder const &data) { - return str << enumStrings::data[data.enumVal]; -} - -template -std::istream &operator>>(std::istream &str, enumRefHolder const &data) { - std::string value; - str >> value; - - // These two can be made easier to read in C++11 - // using std::begin() and std::end() - // - static auto begin = std::begin(enumStrings::data); - static auto end = std::end(enumStrings::data); - - auto find = std::find(begin, end, value); - if (find != end) { - data.enumVal = static_cast(std::distance(begin, find)); - } else { - throw std::invalid_argument(""); - } - return str; -} - -// This is the public interface: -// use the ability of function to deduce their template type without -// being explicitly told to create the correct type of enumRefHolder -template -enumConstRefHolder enumToString(T const &e) { - return enumConstRefHolder(e); -} - -template -enumRefHolder enumFromString(T &e) { - return enumRefHolder(e); -} \ No newline at end of file diff --git a/include/project_parser.hpp b/include/project_parser.hpp index bebab1a..7c5ea11 100644 --- a/include/project_parser.hpp +++ b/include/project_parser.hpp @@ -56,11 +56,16 @@ enum TargetType { target_interface, target_custom, target_object, + target_template, + target_last, }; +extern const char *targetTypeNames[target_last]; + struct Target { std::string name; - TargetType type = {}; + TargetType type = target_last; + std::string type_name; ConditionVector headers; ConditionVector sources; @@ -100,6 +105,12 @@ struct Target { ConditionVector include_after; }; +struct Template { + Target outline; + std::string add_function; + bool pass_sources_to_add_function = false; +}; + struct Test { std::string name; std::string condition; @@ -160,6 +171,7 @@ struct Project { std::vector packages; Vcpkg vcpkg; std::vector contents; + std::vector