Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vcpkg] Add CMake heuristics for header-only libraries #12386

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Changes from 1 commit
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
34 changes: 34 additions & 0 deletions toolsrc/src/vcpkg/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ namespace vcpkg::Install
{
std::map<std::string, std::string> config_files;
std::map<std::string, std::vector<std::string>> library_targets;
bool is_header_only = true;
std::string header_path;

for (auto&& suffix : *p_lines)
{
Expand Down Expand Up @@ -617,10 +619,42 @@ namespace vcpkg::Install
config_files[find_package_name] = root;
}
}
if (Strings::case_insensitive_ascii_contains(suffix, "/lib/") ||
Strings::case_insensitive_ascii_contains(suffix, "/bin/"))
{
if (!Strings::ends_with(suffix, ".pc")) is_header_only = false;
ras0219-msft marked this conversation as resolved.
Show resolved Hide resolved
}

if (is_header_only && header_path.empty())
{
auto it = suffix.find("/include/");
if (it != std::string::npos && !Strings::ends_with(suffix, "/"))
{
header_path = suffix.substr(it + 9);
}
}
}

if (library_targets.empty())
{
if (is_header_only && !header_path.empty())
{
static auto cmakeify = [](std::string name) {
auto n = Strings::ascii_to_uppercase(Strings::replace_all(std::move(name), "-", "_"));
if (n.empty() || Parse::ParserBase::is_ascii_digit(n[0]))
{
n.insert(n.begin(), '_');
}
return n;
};

const auto name = cmakeify(bpgh.spec.name());
auto msg = Strings::concat(
"The package ", bpgh.spec, " is header only and can be used from CMake via:\n\n");
Strings::append(msg, " find_path(", name, "_INCLUDE_DIRS \"", header_path, "\")\n");
Strings::append(msg, " target_include_directories(main PRIVATE ${", name, "_INCLUDE_DIRS})\n\n");
System::print2(msg);
}
}
else
{
Expand Down