Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ namespace cppwinrt
{
w.write(R"(// C++/WinRT v%

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

)", CPPWINRT_VERSION_STRING);
%
)", CPPWINRT_VERSION_STRING, settings.license_template);
}
else
{
Expand Down
36 changes: 35 additions & 1 deletion cppwinrt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace cppwinrt
{ "?", 0, option::no_max, {}, {} },
{ "library", 0, 1, "<prefix>", "Specify library prefix (defaults to winrt)" },
{ "filter" }, // One or more prefixes to include in input (same as -include)
{ "license", 0, 0 }, // Generate license comment
{ "license", 0, 1, "[<path>]", "Generate license comment from template file" },
{ "brackets", 0, 0 }, // Use angle brackets for #includes (defaults to quotes)
{ "fastabi", 0, 0 }, // Enable support for the Fast ABI
{ "ignore_velocity", 0, 0 }, // Ignore feature staging metadata and always include implementations
Expand Down Expand Up @@ -115,6 +115,40 @@ R"( local Local ^%WinDir^%\System32\WinMetadata folder
settings.exclude.insert(exclude);
}

if (settings.license)
{
std::string license_arg = args.value("license");
if (license_arg.empty())
{
settings.license_template = R"(// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
)";
}
else
{
std::filesystem::path template_path{ license_arg };
std::ifstream template_file(absolute(template_path));
if (template_file.fail())
{
throw_invalid("Cannot read license template file '", absolute(template_path).string() + "'");
}
std::string line_buf;
while (getline(template_file, line_buf))
{
if (line_buf.empty())
{
settings.license_template += "//\n";
}
else
{
settings.license_template += "// ";
settings.license_template += line_buf;
settings.license_template += "\n";
}
}
}
}

if (settings.component)
{
settings.component_overwrite = args.exists("overwrite");
Expand Down
1 change: 1 addition & 0 deletions cppwinrt/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace cppwinrt
std::string output_folder;
bool base{};
bool license{};
std::string license_template;
bool brackets{};
bool verbose{};
bool component{};
Expand Down