-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[docs] Enforce usage of targets #7153
Conversation
This comment has been minimized.
This comment has been minimized.
Co-authored-by: SSE4 <[email protected]>
This comment has been minimized.
This comment has been minimized.
The C++ developer in my loves the freedom to do anything, so there's a little resistance for me, but after using Golang and Node ecosystems and the position of
I have no issue with enforcing this rule. However I think it would be a very nice hook 😉 |
docs/reviewing.md
Outdated
When using CMake to test a package, the information should be consumed using the **targets provided by `cmake_find_package_multi` generator**. We | ||
enforce this generator to align with the upcoming | ||
[Conan's new `CMakeDeps` generator](https://docs.conan.io/en/latest/reference/conanfile/tools/cmake/cmakedeps.html?highlight=cmakedeps) | ||
and it should help in the migration (and compatibility) with Conan v2. | ||
|
||
* use `cmake_find_package` if library has an [official](cmake.org/cmake/help/latest/manual/cmake-modules.7.html#find-modules) CMake module emulated in the recipe. | ||
* use `cmake_find_package_multi` if library provides an official cmake config file emulated in the recipe. If there are more than one target, try to use all of them, or add another executable linking to the global (usually unofficial) target. There may additionally be variables that are emulated by the recipe which should be used as well. There are some ways to identify when to use it: | ||
* Usually, project installs its cmake files into `package_folder/lib/cmake`. The folder is removed from package folder by calling `tools.rmdir(os.path.join(self.package_folder), "lib", "cmake")` | ||
* Also, the library's CMake scripts can use [install(EXPORT ..)](https://cmake.org/cmake/help/latest/command/install.html#export) and/or may install [package configuration helpers](https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html) | ||
to indicate an exported CMake config file. | ||
* When `self.cpp_info.filenames["cmake_find_package_multi"]`, `self.cpp_info.names["cmake_find_package_multi"]` are declared | ||
* otherwise, use [cmake generator](https://docs.conan.io/en/latest/reference/generators/cmake.html) to not suggest an unofficial cmake target in test package. | ||
In ConanCenter we try to mimic the names of the targets and the information provided by CMake's modules and config files that some libraries | ||
provide. If CMake or the library itself don't enforce any target name, the ones provided by Conan should be recommended. The minimal project | ||
in the `test_package` folder should serve as an example of the best way to consume the package, and targets are preferred over raw variables. | ||
|
||
This rule applies for the _global_ target and for components ones. The following snippet should serve as example: |
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 would suggest:
- cmake_find_package_multi if there is an official config file
- cmake_find_package if there is an official Find module file and no official config file
- pkg_config if there is an official .pc file and no official cmake Find/config files.
- cmake_find_package_multi otherwise
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 would also warn against relying on unofficial CMake Find/config and pkg_config files in recipes themselves, it can break at anytime (upstream suddenly decides to provide a CMake config file, and it's different than default CMake config file generated by conan, so we update this recipe accordingly, and it breaks all downstream recipes) while CONAN_PKG targets are robust.
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'ld also prefer using CONAN_PKG::
targets or similar. Something in a conan namespace.
I would consider it unfriendly if some package manager would start dictating cmake targets to my project.
At least, there should be some comment added that a target is conan specific and prone to breakage.
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.
To give a heads-up of what is happening in Conan 2.0:
- The only CMake generator that remains is
CMakeDeps
andCMakeToolchain
. They generatepkg::pkg
andpkg::component
targets, not any CONAN_LIB or CONAN_PKG targets. - The idea is to provide a fully transparent integration with CMake, the push for that has been massive over the years.
- Also, to provide 1 integration for CMake, supporting many ones is is big overhead in support in maintenance, we need to converge to 1 solution
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.
Will CMakeDeps be able to generate both module and configs?
If not, that will break a lot of recipes at cci
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.
Yes, it is already able in Conan 1.40
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.
They tagged us in a PR with the feature asking for feedback :)
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.
Leaving the links here, it may be useful:
Here we are trying to maximize compatibility with the following Conan versions. At some point in time, we will need to introduce Conan v2.x in CCI and we should try to make the recipes as compatible as possible with both versions, trying to keep The
It doesn't really matter if we use When there is nothing official: New Conan versions won't provide
Can you figure out a mark we can add to recipes/cpp_info? Something that the generator can inform the consumer about? |
It depends whether you use And for CCI, we package many recipes with legacy CMakeLists (sometimes it doesn't even deserve the name legacy, just that official Find file has introduced targets in very recent CMake versions, e.g CURL::libcurl in FindCURL.cmake introduced in CMake 3.12), relying on CMake variables which can't be emulated in config files due to its "multi" nature, so there is still a strong advantage of |
I searched through the repo and found that some recipes generate different file names for Projects might do
I think conan already knows when to inform the consumer about this. First, conan should be able to detect whether an option is explicitly set or has a default value. default_values = []
for dep in conanfile.deps:
if conanfile.deps_cpp_info[dep].names["CMakeDeps"].default_value: # Assume every item in the names list to be a wrapper object with extra functionality
default_values.append(dep)
cmakedeps_generate(dep, conanfile.deps_cpp_info[dep])
if default_values and tools.get_env("CONAN_WARNING_CMAKEDEPS", False): # Only warn about default targets when the user cares about it. Perhaps conan needs functionality comparable to `-Wall -Weverything`?
conanfile.output.warning("The following CMakeDeps modules are not explicitly defined and are prone to breakage: {}".format(default_values) |
I think we can summarize the concern for
Might not cover enough cases? We are trying to tame the lawless C++ landscape so there are more combinations that exist.
➡️ Are we okay not supporting all projects? |
Co-authored-by: Chris Mc <[email protected]>
Updating docs! |
Conan v2 is approaching fast with radical improvements around build helpers. Most of the new functionality is being backported to Conan v1.x in an effort to provide a baseline of compatible features and syntax that will work with both versions and make the migration path as smooth as possible.
You can read about these new features in the tribe repository and in the Conan documentation. The changelog is also a good place to keep updated, there you can find an exhaustive list of new features together with a link to the documentation that was changed related to it.
Regarding
conan-center-index
, one of the main changes will be the deprecation of (the functionality provided by) thecmake
generator. This functionality will be superseded by a much more convenient approach: CMake toolchains (the new CMake build-helper will take care to inject it and it would be the same if using CMake from CLI). It means that some variables will no longer be accessible, among them it's important to notice thatCONAN_LIBS
will no longer be available.We are already doing a huge effort (thanks to everyone) trying to mimic in our
package_info()
the information provided by the modules offered by CMake and the config files that some libraries provide. We are mimic target names, and thanks to the build-modules we can create aliases and provide extra variables.We believe that targets are more convenient for consumers and there is no reason to keep using only the
cmake
generator and raw variables instead of the targets that Conan is already providing. We think that ConanCenter itself can suggest and enforce targets when they are not already enforced.Following this lead, the mini-project in
test_package
can become an example of the best practices to consume the library, and not just a test for the Conan package itself. It will also align with the following releases of Conan and will make it easier to use new Conan versions and, eventually, make it possible to use the same recipes with Conan v1 and v2.Of course, we will keep trying to mimic existing targets when they are already available and spread in the C++ ecosystem, and we will change Conan ones and modify the
cpp_info
information if some library starts to recommend different names and/or targets.