-
Notifications
You must be signed in to change notification settings - Fork 993
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
CMakeDeps/CMakeToolchain: Several improvements for open issues #9455
Changes from 10 commits
f1f071b
735ad3f
682b7fe
bc0656e
a9c1147
9b64bf3
2a078fb
3f99570
1c81c2a
ab102df
d7e067a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,22 +7,23 @@ | |
|
||
class CMakeDepsFileTemplate(object): | ||
|
||
def __init__(self, cmakedeps, require, conanfile): | ||
def __init__(self, cmakedeps, require, conanfile, find_module_mode=False): | ||
self.cmakedeps = cmakedeps | ||
self.require = require | ||
self.conanfile = conanfile | ||
self.find_module_mode = find_module_mode | ||
|
||
@property | ||
def pkg_name(self): | ||
return self.conanfile.ref.name + self.suffix | ||
|
||
@property | ||
def target_namespace(self): | ||
return get_target_namespace(self.conanfile) + self.suffix | ||
return self.get_target_namespace(self.conanfile) + self.suffix | ||
|
||
@property | ||
def file_name(self): | ||
return get_file_name(self.conanfile) + self.suffix | ||
return get_file_name(self.conanfile, self.find_module_mode) + self.suffix | ||
|
||
@property | ||
def suffix(self): | ||
|
@@ -74,29 +75,34 @@ def arch(self): | |
def config_suffix(self): | ||
return "_{}".format(self.configuration.upper()) if self.configuration else "" | ||
|
||
def get_target_namespace(self): | ||
return get_target_namespace(self.conanfile) | ||
|
||
def get_file_name(self): | ||
return get_file_name(self.conanfile) | ||
|
||
|
||
def get_target_namespace(req): | ||
ret = req.new_cpp_info.get_property("cmake_target_name", "CMakeDeps") | ||
if not ret: | ||
ret = req.cpp_info.get_name("cmake_find_package_multi", default_name=False) | ||
return ret or req.ref.name | ||
|
||
|
||
def get_component_alias(req, comp_name): | ||
if comp_name not in req.new_cpp_info.components: | ||
# foo::foo might be referencing the root cppinfo | ||
if req.ref.name == comp_name: | ||
return get_target_namespace(req) | ||
raise ConanException("Component '{name}::{cname}' not found in '{name}' " | ||
"package requirement".format(name=req.ref.name, cname=comp_name)) | ||
ret = req.new_cpp_info.components[comp_name].get_property("cmake_target_name", "CMakeDeps") | ||
if not ret: | ||
ret = req.cpp_info.components[comp_name].get_name("cmake_find_package_multi", | ||
default_name=False) | ||
return ret or comp_name | ||
return get_file_name(self.conanfile, find_module_mode=self.find_module_mode) | ||
|
||
def get_target_namespace(self, req): | ||
if self.find_module_mode: | ||
ret = req.new_cpp_info.get_property("cmake_module_target_name", "CMakeDeps") | ||
if ret: | ||
return ret | ||
|
||
ret = req.new_cpp_info.get_property("cmake_target_name", "CMakeDeps") | ||
lasote marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not ret: | ||
ret = req.cpp_info.get_name("cmake_find_package_multi", default_name=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No fallback to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been greping
So the fallback looks enough. We introduce this fallback mostly for Conan center. |
||
return ret or req.ref.name | ||
|
||
def get_component_alias(self, req, comp_name): | ||
if comp_name not in req.new_cpp_info.components: | ||
# foo::foo might be referencing the root cppinfo | ||
if req.ref.name == comp_name: | ||
return self.get_target_namespace(req) | ||
raise ConanException("Component '{name}::{cname}' not found in '{name}' " | ||
"package requirement".format(name=req.ref.name, cname=comp_name)) | ||
if self.find_module_mode: | ||
ret = req.new_cpp_info.components[comp_name].get_property("cmake_module_target_name", | ||
"CMakeDeps") | ||
if ret: | ||
return ret | ||
ret = req.new_cpp_info.components[comp_name].get_property("cmake_target_name", "CMakeDeps") | ||
if not ret: | ||
ret = req.cpp_info.components[comp_name].get_name("cmake_find_package_multi", | ||
default_name=False) | ||
return ret or comp_name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious why a
"both"
option?AFAIK official CMake are modules (And there are a few projects the provide their own) and most project install targets + follow https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html which are your config packages
but I've not come across a project that does both 🤔 with the old generators it was the costume who decided what to install but now it's defined by the recipe... we'll need to be more careful to define it correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both
cover the case where the library has a module in cmake, typicalFindXXX.cmake
but also the author's provided config (irrespective if we package it or not). In that case, you don't know how the consumer will expect to consume the package, maybefind_package(XXX MODULE)
maybefind_package(xxx CONFIG)
but we want Conan to be as "ready" as possible to consume any conan center package. SoCMakeDeps
will generate both. Note that theconfig
namespace and target name should be declared typically following the author's one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, I understand the motivation but I am not aware of any examples.
There are a few project out there that provide their own module files even though the upstream project provides config files. I wonder if this bonus feature will help there 🤔