#pragma once #include #include #include #include #include namespace cmkr { namespace parser { template using Condition = tsl::ordered_map; using ConditionVector = Condition>; struct Variable { std::string name; std::string help; mpark::variant value; bool cache = false; bool force = false; }; struct Option { std::string name; std::string help; mpark::variant value; }; struct Package { std::string name; std::string condition; std::string version; bool required = true; bool config = false; std::vector components; }; struct Vcpkg { std::string version; std::string url; struct Package { std::string name; std::vector features; bool default_features = true; }; std::vector packages; // https://github.com/Microsoft/vcpkg-docs/blob/main/vcpkg/users/buildsystems/cmake-integration.md std::vector overlay_ports; std::vector overlay_triplets; bool enabled() const { return !packages.empty(); } }; enum TargetType { target_executable, target_library, target_shared, target_static, target_interface, target_custom, target_object, target_template, target_last, }; extern const char *targetTypeNames[target_last]; struct Target { struct CustomTarget { bool has_all = false; bool all = false; bool has_command = false; bool has_commands = false; std::vector> commands; std::vector depends; std::vector byproducts; bool has_working_directory = false; std::string working_directory; bool has_comment = false; std::string comment; bool has_job_pool = false; std::string job_pool; bool has_job_server_aware = false; bool job_server_aware = false; bool has_verbatim = false; bool verbatim = false; bool has_uses_terminal = false; bool uses_terminal = false; bool has_command_expand_lists = false; bool command_expand_lists = false; bool empty() const { return !has_all && !has_command && !has_commands && commands.empty() && depends.empty() && byproducts.empty() && !has_working_directory && !has_comment && !has_job_pool && !has_job_server_aware && !has_verbatim && !has_uses_terminal && !has_command_expand_lists; } }; struct CustomCommand { struct ImplicitDependency { std::string language; std::string file; }; std::string condition; std::vector> commands; std::vector outputs; std::string build_event; bool has_append = false; bool append = false; bool has_main_dependency = false; std::string main_dependency; std::vector depends; std::vector byproducts; std::vector implicit_depends; bool has_working_directory = false; std::string working_directory; bool has_comment = false; std::string comment; bool has_depfile = false; std::string depfile; bool has_job_pool = false; std::string job_pool; bool has_job_server_aware = false; bool job_server_aware = false; bool has_verbatim = false; bool verbatim = false; bool has_uses_terminal = false; bool uses_terminal = false; bool has_codegen = false; bool codegen = false; bool has_command_expand_lists = false; bool command_expand_lists = false; bool has_depends_explicit_only = false; bool depends_explicit_only = false; bool is_output_form() const { return !outputs.empty(); } bool is_target_form() const { return !build_event.empty(); } }; std::string name; TargetType type = target_last; std::string type_name; ConditionVector sources; // https://cmake.org/cmake/help/latest/manual/cmake-commands.7.html#project-commands ConditionVector compile_definitions; ConditionVector private_compile_definitions; ConditionVector compile_features; ConditionVector private_compile_features; ConditionVector compile_options; ConditionVector private_compile_options; ConditionVector include_directories; ConditionVector private_include_directories; ConditionVector link_directories; ConditionVector private_link_directories; ConditionVector link_libraries; ConditionVector private_link_libraries; ConditionVector link_options; ConditionVector private_link_options; ConditionVector precompile_headers; ConditionVector private_precompile_headers; ConditionVector dependencies; CustomTarget custom_target; std::vector custom_commands; std::string condition; std::string alias; Condition> properties; Condition cmake_before; Condition cmake_after; ConditionVector include_before; ConditionVector include_after; }; struct Template { Target outline; std::string add_function; std::vector add_arguments; bool pass_sources_to_add_function = false; }; struct Test { std::string name; std::string condition; std::vector configurations; std::string working_directory; std::string command; std::vector arguments; }; struct Install { std::string condition; std::vector targets; std::vector files; std::vector dirs; std::vector configs; std::string destination; std::string component; bool optional = false; }; struct Subdir { std::string name; std::string condition; Condition cmake_before; Condition cmake_after; ConditionVector include_before; ConditionVector include_after; }; struct ContentOption { mpark::variant value; }; struct Content { std::string name; std::string condition; tsl::ordered_map arguments; tsl::ordered_map options; Condition cmake_before; Condition cmake_after; ConditionVector include_before; ConditionVector include_after; bool system = false; std::string subdir; }; enum MsvcRuntimeType { msvc_dynamic, msvc_static, msvc_last, }; extern const char *msvcRuntimeTypeNames[msvc_last]; struct Project { const Project *parent; // This is the CMake version required to use all cmkr versions. std::string cmake_version = "3.15"; std::string cmkr_include = "cmkr.cmake"; std::string build_dir = "build"; std::string generator; std::string config; bool allow_in_tree = false; Condition> project_subdirs; std::vector cppflags; std::vector cflags; std::vector linkflags; std::vector gen_args; std::vector build_args; std::string project_name; std::string project_version; std::string project_description; ConditionVector project_languages; bool project_allow_unknown_languages = false; MsvcRuntimeType project_msvc_runtime = msvc_last; Condition cmake_before; Condition cmake_after; ConditionVector include_before; ConditionVector include_after; std::vector variables; std::vector