-
Notifications
You must be signed in to change notification settings - Fork 989
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
[feature] CMakeDeps generates incorrect CMake variables #14788
Comments
Hi @hekrdla - thank you for raising this issue. Unfortunately there isn't a uniform convention with regards to these variables - so no matter which solution we go for, some packages may end up with variables names that do not patch pre-existing conventions. Conan tries to follow the conventions specified in the CMake documentation here: https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#standard-variable-names which mentions the following:
This convention is not always followed by library maintainers, and I suspect it may not have been uniformly followed by CMake-provided find modules. CMake guidelines also overwhelmingly recommend the use of imported targets - so beyond the fact that the variables don't follow convention, it is also unfortunate that they are used at all.
I think this is a good idea and something for us to consider - I would probably opt for a different property name, such as
To achieve the desired result. I don't think more complexity is needed. For example:
Please also note that sometimes the same package is used differently by consumers (different variable names, internal find modules), and that that the generator can be tweaked on the consumer side (not just in the |
@jcar87 I agree with you that all of that should be deprecated since CMake 3.0.0 2014 in favor of targets. But here we are in 2023 and still deal with it :-( I know that this will not cover everything, but this should cover a lot. And if not, there is still possibility to use I don't check all CMake built-in finders, but what I see they respect these inconsistencies and deprecated thinks, because they should. Even edit: sad example how I agree that List of variables I propose are most common, as I know. And my premise is that defining variable that not exists in original Config.cmake is no issue, because nobody should expect it, so it will not used. But not defining variable that should exists may be problem, because it may mean different behavior instead of error. I hope something like that will be added in whatever way. |
I've submitted one month ago a fix for And FYI, regarding extra CMake variables, there was #7691, but it has been closed since it was referring to legacy |
What is your suggestion?
Hi, I found issue with opencv package using openjpeg (
opencv:with_jpeg2000=openjpeg
). After my investigation, I have suggestion to new feature into Conan. Here are both issue and my suggestion in details.Environment
Conan 1.61.0
Windows msvc builds
Issue
Official OpenJPEGConfig.cmake is using UPPERCASE naming (
OPENJPEG
) for odlschool CMake variables likeOPENJPEG_INCLUDE_DIRS
even when package name is in CamelCase (OpenJPEG
). This is pretty common style, even for CMake built-in findersSo packages like
opencv
(and a lot more) using these oldschool cmake variables, expect official naming.But Conan CMakeDeps use file_name aka CMake PackageName to generate these variables. So they not match with official Config.cmake
Conan recipes deal with this, by patching sources in consuming packages, like in opencv. This complicates these recipes, it probably cost a lot effort to do it, will cost a lot effort to maintain this within updates to new versions and mainly it's easy to miss something, like in example bellow.
Conan workaroud recipes/opencv/4.x/conanfile.py
for this opencv/CMakeLists.txt
But there is no patch for usage in opencv/modules/imgcodecs/CMakeLists.txt
like it is for jasper
So
OPENJPEG_INCLUDE_DIRS
andOPENJPEG_LIBRARIES
not existsI think that Conan needs to address root cause of this issue, not patching every package affected by this. So
CMakeDeps
should be enhanced to generate proper variables. There is my proposalWhat is your suggestion?
New CMake tools already support property for
<PackageName>Config.cmake
and/orFind<PackageName>.cmake
file name:So there should be also something like: - name reflect CMake Result Variables chapter in documentation
with usage like this:
This will work for most packages, but there are exceptions like FindPythonLibs, where is used
PYTHON_
vsPYTHONLIBS_
so property to define name for version related variables may be useful
with usage like this:
But because CMake find_package provides version related variables like
<PackageName>_VERSION_MAJOR
, packages like OpenJPEG also explicitely set uppercase versions like<PACKAGE_NAME>_VERSION_MAJOR
. So in case thatversion_variables_prefix
not match withPackageName
(file_name
) Conan should set these as well. And probably also<PACKAGE_NAME>_FOUND
variantI would also consider to add
<PackageName>_LIBRARY
. Some package set this one and if not, nobody will use it.Last issue with this enchancement is, that there are already patches in conan recipes to deal with this and they will be invalid with fixed Config.cmake. Also depricated cmake tools will not support this. And there are also packages like libwebp that supports both naming styles.
So current variables named based on
cmake_file_name
needs to be generated as well. I'm not sure, if this should be supported always or somehow configurable.All toghether
New optional properies:
With defaults like:
And usage in CMakeDeps
I not check how Conan generates
Find<PackageName>.cmake
files, but this should be considered for this case as well.Usage in conan recipes
PackeName == Resutl Variables == Version Variables: no change
PackeName != Resutl Variables == Version Variables: use
cmake_result_variables_name
PackeName != Resutl Variables != Version Variables: use
cmake_result_variables_name
andcmake_version_variables_name
PackeName != Resutl Variables == Version Variables + extra variables: use
cmake_result_variables_name
+conan-official-{name}-variables.cmake
Have you read the CONTRIBUTING guide?
The text was updated successfully, but these errors were encountered: