aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src
diff options
context:
space:
mode:
authorras0219 <533828+ras0219@users.noreply.github.com>2020-07-13 12:07:52 -0700
committerGitHub <noreply@github.com>2020-07-13 12:07:52 -0700
commit7b3eea9481991425286feb7a53ab420e6e6c13a2 (patch)
tree6abb8b79f85df81f545e581093d21679cea61ddd /toolsrc/src
parent52a9d9a9e481f835e9c3b9ba028ff2f833cb3624 (diff)
downloadvcpkg-7b3eea9481991425286feb7a53ab420e6e6c13a2.tar.gz
vcpkg-7b3eea9481991425286feb7a53ab420e6e6c13a2.zip
[vcpkg] Add CMake heuristics for header-only libraries (#12386)
* [vcpkg] Add CMake heuristics for header-only libraries * [vcpkg] Update toolsrc/src/vcpkg/install.cpp Handles the case of: ``` triplet/lib/ triplet/lib/x.pc ``` Co-authored-by: nicole mazzuca <mazzucan@outlook.com> Co-authored-by: Robert Schumacher <roschuma@microsoft.com> Co-authored-by: nicole mazzuca <mazzucan@outlook.com>
Diffstat (limited to 'toolsrc/src')
-rw-r--r--toolsrc/src/vcpkg/install.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp
index 7c0107264..0767a1bc7 100644
--- a/toolsrc/src/vcpkg/install.cpp
+++ b/toolsrc/src/vcpkg/install.cpp
@@ -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)
{
@@ -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") && !Strings::ends_with(suffix, "/")) is_header_only = false;
+ }
+
+ 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
{