-
Notifications
You must be signed in to change notification settings - Fork 186
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
WIP: Fix bug/behaivor in imported targets via PkgConfig:: #139
Conversation
Force to parse again .pc file via pkg_check_modules(). After "updating" to a new hunter, toolchain or config version, CMakeCache.txt should be reinitialise with the new path.
I think the behaviour 'dont search a library again if found unless the CMakeCache.txt is cleared' is the same as the default FindX.cmake files included with CMake? Would this make behaviour inconsistent with those? |
Yep, I've also thought about it. But I think we should avoid to use the MODULE mode/way to add third party libs and use only CONFIG mode in At least we should add a warning ! |
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.
Please have a look...
message(SEND_ERROR "CMakeCache entries for ${PKG_CONFIG_MODULE}_LIBRARY_DIRS points to ${${PKG_CONFIG_MODULE}_LIBRARY_DIRS} but the current hunter install root dir is ${HUNTER_INSTALL_ROOT_DIR}\nYou should verify and change/remove all wrong cache entries or delete your CMakeCache.txt in your build folder!") | ||
endif() | ||
endif() | ||
|
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.
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.
Honestly I'm not sure I understand the issue still. In my experience CMake basically requires you bin your build tree (at least you CMakeCache.txt) when you change any libraries, which would include libraries changed by Hunter after a Hunter upgrade. If that is the thing you are trying to fix then I imagine it happens with non-pkgconfig libraries too? Maybe @rbsheth will have more of a clear idea?
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.
Actually, I don't have a clear idea. 😄
Based on the error description, it seems like using pkgconfig targets screws up CMake somehow and does not "refresh" the target if the version has changed. Wouldn't it be better to force a refresh somehow? This message is basically telling the user to nuke their CMakeCache, right?
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.
Sometime an example say more than thousand words ;-)
Do following ...
Clone my example:
git clone https://github.com/Bjoe/hunter.git
Then checkout:
git checkout step-1
Build the project .... after all is fine execute the bte
binary:
Version: Botan 2.10.0 (unreleased, revision unknown, distribution unspecified)
So no surprise ... :-)
Keep eyes on following cmake output:
HUNTER_INSTALL_ROOT_DIR= ...
botan-2_LIBRARY_DIRS= ...
HUNTER_INSTALL_ROOT_DIR
is the current hunter path
botan-2_LIBRARY_DIRS
is the "cache entry" in CMakeCache.txt which pkg_check_modules
is set.
Now we update the botan version from 2.10.0 to 2.11.0-110af9494 .... checkout out ...
git checkout step-2
Now build the project again for example cmake --build <YOUR_BUILD_PATH>
...
Hunter will build botan version 2.11.0-110af9494 and you see also following cmake output like:
...
-- [hunter] BOTAN_ROOT: /home/developer/.hunter/_Base/36e7f44/f49d2cd/8d03466/Install (ver.: 2.11.0-110af9494)
...
So all looks fine, but when you execute bte
it will still print:
Version: Botan 2.10.0 (unreleased, revision unknown, distribution unspecified)
If you verify the output from HUNTER_INSTALL_ROOT_DIR
and botan-2_LIBRARY_DIRS
... then you will have some output like:
-- HUNTER_INSTALL_ROOT_DIR=/home/developer/.hunter/_Base/36e7f44/f49d2cd/8d03466/Install
-- botan-2_LIBRARY_DIRS=/home/developer/.hunter/_Base/36e7f44/f49d2cd/5f3f694/Install/lib
You see .... botan-2_LIBRARY_DIRS is still pointing to the "build" before ... this is really bad and nobody will see this!
This happen, because if botan-2_FOUND
is 1 then pkg_check_modules
reads only the environemnt from the CMakeCache.txt. This behaivor is like find_library
see https://cmake.org/cmake/help/v3.16/command/find_library.html?highlight=find_library
You can test my solution ... checkout
git checkout step-3
Now you will get the error message (again should be more "proper").
As @hjmallon comment all the FindX.cmake working somehow with find_library
, find_path
or find_program
... all they have the same behaivor.
Hunter also provides FindX.cmake
with for example cmake/find/FindAvahi.cmake
line 51 or cmake/find/FindBoost.cmake
line 326 ....
Btw. FindBoost.cmake is also used when you add the config module with find_package(Boost CONFIG REQUIRED)
! See cmake/templates/BoostConfig.cmake.in
line 51 find_package(Boost MODULE REQUIRED ${Boost_FIND_COMPONENTS})
... this will fixed in the use boost config branch ..
Anyway, I will verify if there are more "pitfalls" for example with find_package
...
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.
Wow, thanks for the detailed explanation. I see what is going on now. Is this PR still WIP?
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.
@rbsheth Yes, still WIP, since I will check whether the "find_package ()" is also affected. Then I want to try to check "this" in "hunter_finalize ()" ... that's my plan. I'm trying to get ready this week
list(FILTER _copy_of_${PKG_CONFIG_MODULE}_LIBRARY_DIRS EXCLUDE REGEX "${HUNTER_INSTALL_ROOT_DIR}") | ||
list(LENGTH _copy_of_${PKG_CONFIG_MODULE}_LIBRARY_DIRS _list_length) | ||
if(_list_length GREATER 0) | ||
message(SEND_ERROR "CMakeCache entries for ${PKG_CONFIG_MODULE}_LIBRARY_DIRS points to ${${PKG_CONFIG_MODULE}_LIBRARY_DIRS} but the current hunter install root dir is ${HUNTER_INSTALL_ROOT_DIR}\nYou should verify and change/remove all wrong cache entries or delete your CMakeCache.txt in your build folder!") |
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.
The error message should be "corrected" ... I only write "something" ...
I thinking about to add a "verification" in |
@Bjoe Still WIP? |
@rbsheth Yep, I did some test with |
Okay! |
I created a new proposal see PR #173 ... |
pkg_check_modules() is only reparse/scan .pc files if
XYZ_FOUND
is0
. IfXYZ_FOUND
is1
, nothing happens.This behaviour cause following problem:
If you change or update some setting, configuration or version numbers in hunter, all the hunter packages they generated the "find" config modul via pkgconfig-export-targets.cmake.in are still use the "old" libraries.
This change will force to reparse/scan the .pc files every cmake execution. Better approach is maybe to verify if the path in the CMakeCache is different then the "new one", but I think this is a bigger effort....