Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

Bjoe
Copy link

@Bjoe Bjoe commented Jan 16, 2020

  • I've checked this Git style guide. Yes
  • I've checked this CMake style guide. Yes
  • My change will work with CMake 3.2 (minimum requirement for Hunter). Yes
  • I will try to keep this pull request as small as possible and will try not to mix unrelated features. Yes

pkg_check_modules() is only reparse/scan .pc files if XYZ_FOUND is 0. If XYZ_FOUND is 1, 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....

Bjoe added 2 commits January 16, 2020 12:01
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.
@hjmallon
Copy link

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?

@Bjoe Bjoe changed the title Fix hunter pkgconfig export target Fix bug/behaivor in imported targets via PkgConfig:: Jan 23, 2020
@Bjoe
Copy link
Author

Bjoe commented Jan 23, 2020

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 find_package. I think in the CONFIG mode, there is no FindX.cmake at all ... at least what i know. The problem is that 90% of the third party libs that added via PkgConfig:: target is affected when you change for example your local "configuration" for hunter .... you never ever see that you still use a "wrong" lib.

At least we should add a warning !

@Bjoe
Copy link
Author

Bjoe commented Feb 3, 2020

@rbsheth I'm fully agree with @hjmallon. Let me try to add a warning/error if the path's in the CMakeCache.txt are not align with the current hunter config. So don't merge yet please.

Copy link
Author

@Bjoe Bjoe left a 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()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hjmallon and @rbsheth What do you thing about this solution?

Copy link

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?

Copy link
Member

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?

Copy link
Author

@Bjoe Bjoe Feb 5, 2020

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 ...

Copy link
Member

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?

Copy link
Author

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!")
Copy link
Author

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" ...

@Bjoe Bjoe requested a review from rbsheth February 4, 2020 16:54
@Bjoe Bjoe mentioned this pull request Feb 5, 2020
@Bjoe Bjoe requested a review from hjmallon February 5, 2020 15:20
@Bjoe Bjoe changed the title Fix bug/behaivor in imported targets via PkgConfig:: WIP: Fix bug/behaivor in imported targets via PkgConfig:: Feb 12, 2020
@Bjoe
Copy link
Author

Bjoe commented Feb 12, 2020

I thinking about to add a "verification" in hunter_finalize ... I will provide a PR for this that's why I changed this title to WIP (Work In Process) ...

@rbsheth
Copy link
Member

rbsheth commented Mar 6, 2020

I thinking about to add a "verification" in hunter_finalize ... I will provide a PR for this that's why I changed this title to WIP (Work In Process) ...

@Bjoe Still WIP?

@Bjoe
Copy link
Author

Bjoe commented Mar 10, 2020

@rbsheth Yep, I did some test with find_package(... CONFIG) ... It looks like it is not affected. But give me some more day. Currently testing an approach to verify this error in hunter_finalize()

@rbsheth
Copy link
Member

rbsheth commented Mar 13, 2020

@rbsheth Yep, I did some test with find_package(... CONFIG) ... It looks like it is not affected. But give me some more day. Currently testing an approach to verify this error in hunter_finalize()

Okay!

@Bjoe
Copy link
Author

Bjoe commented Mar 17, 2020

I created a new proposal see PR #173 ...

@rbsheth
Copy link
Member

rbsheth commented Apr 2, 2020

I created a new proposal see PR #173 ...

@Bjoe So is this PR obsolete?

@Bjoe
Copy link
Author

Bjoe commented Apr 9, 2020

@rbsheth Yep. I will close this PR because of #173

@Bjoe Bjoe closed this Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants