[3party] Optionally allow building with packaged googletest #3528
No reviewers
Labels
No labels
Accessibility
Accessibility
Address
Address
Android
Android
Android Auto
Android Auto
Android Automotive (AAOS)
Android Automotive (AAOS)
API
API
AppGallery
AppGallery
AppStore
AppStore
Battery and Performance
Battery and Performance
Blocker
Blocker
Bookmarks and Tracks
Bookmarks and Tracks
Borders
Borders
Bug
Bug
Build
Build
CarPlay
CarPlay
Classificator
Classificator
Community
Community
Core
Core
CrashReports
CrashReports
Cycling
Cycling
Desktop
Desktop
DevEx
DevEx
DevOps
DevOps
dev_sandbox
dev_sandbox
Directions
Directions
Documentation
Documentation
Downloader
Downloader
Drape
Drape
Driving
Driving
Duplicate
Duplicate
Editor
Editor
Elevation
Elevation
Enhancement
Enhancement
Epic
Epic
External Map Datasets
External Map Datasets
F-Droid
F-Droid
Fonts
Fonts
Frequently User Reported
Frequently User Reported
Fund
Fund
Generator
Generator
Good first issue
Good first issue
Google Play
Google Play
GPS
GPS
GSoC
GSoC
iCloud
iCloud
Icons
Icons
iOS
iOS
Legal
Legal
Linux Desktop
Linux Desktop
Linux packaging
Linux packaging
Linux Phone
Linux Phone
Mac OS
Mac OS
Map Data
Map Data
Metro
Metro
Navigation
Navigation
Need Feedback
Need Feedback
Night Mode
Night Mode
NLnet 2024-06-281
NLnet 2024-06-281
No Feature Parity
No Feature Parity
Opening Hours
Opening Hours
Outdoors
Outdoors
POI Info
POI Info
Privacy
Privacy
Public Transport
Public Transport
Raw Idea
Raw Idea
Refactoring
Refactoring
Regional
Regional
Regression
Regression
Releases
Releases
RoboTest
RoboTest
Route Planning
Route Planning
Routing
Routing
Ruler
Ruler
Search
Search
Security
Security
Styles
Styles
Tests
Tests
Track Recording
Track Recording
Translations
Translations
TTS
TTS
UI
UI
UX
UX
Walk Navigation
Walk Navigation
Watches
Watches
Web
Web
Wikipedia
Wikipedia
Windows
Windows
Won't fix
Won't fix
World Map
World Map
No milestone
No project
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set.
Reference: organicmaps/organicmaps-tmp#3528
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "googletest"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Signed-off-by: Ferenc Géczi ferenc.gm@gmail.com
Var is not needed if it's used only once.
It would be great to update gtest with the latest version first manually, in a separate commit.
All right, it will be here: organicmaps/organicmaps#3538
Removed.
I could remove the CI part for now, so the rest of the commit can progress. Would that be all right?
Would that merit a merge otherwise?
I don't mind
All right I have ditched the CI code. Please take a look.
@Ferenc- Interesting, why are you focusing on the google test now? Just for training purposes? It is used for unit tests only, e.g. usually should not be packaged with Linux distros.
Good start! I suggest you try to make a function (or macro?) that encapsulates this logic and can be reused for most of the other 3party libs.
Probably QUIET option is needed to avoid log pollution when the package is not found, and it is found. What is the output in these both cases?
The current output for the not found scenario is:
When found it is:
Changes are difficult in every organization and project. I am trying to "tread carefully", not to cause a lot of anger for established project members.
Plus changes to the tests only, can really not break the production code, on some walled platform that I have no access to.
There is also some training purpose. If this PR gets accepted, then there will be more to come, following the patterns demonstrated here.
Although the tests are not packaged by Linux distros, they are often executed to validate builds and build environments, so they shouldn't be neglected either.
Good strategy :)
Comparing outputs, it's better to add a message when gtest is not found in the system and an embedded one is used, to avoid confusion and make it clearer for developers.
Thanks! :)
Done!
@biodranik so what do you think about the current state of this PR?
Do we absolutely need a function/macro already, when there would only be one sinle use?
Or does it make sense to apply these changes to more libraries first, and then we would see how to generalize best?
Another question:
Are you OK with the fact that if GoogleTest's cmake compatibility check is broken , then even a lover than required version would be picked up by this code?
The way I see, it is probably broken, hence I was suggesting putting all this behind a
-DSYSTEM_....
switch, just to be sure.No, lower version should not be used.
Only that one which is already in the repo, or greater. Otherwise, a repo's version should be used.
Why do you think the macro implementation can be different?
I fully agree. At least not by accident, and we should try to avoid such accidents, so I would go with the
-DSYSTEM_.... switch
if that is OK with you.Well the way
find_package
is looking for.cmake
files, that might not be availabe for every dependency.And alsofor example how fast double parser is simply inserted into SRC, doesn't seem to fit this pattern immediately.
Why DSYSTEM... is needed? Because if a lower version is installed in the system, it will be found and used?
What about syntax "1.12...<" ? Did you try it?
Yes exactly.
1.12...<
or1.12.0...<
appear to be invalid systax as of the latest CMake realease.A full version range like
1.12.0...<2.0.0
is valid, but firstly that results in a warning aboutGTest
not supporting it:And secondly, empirical tests show, that it doesn't work.
Yes, I misinterpret the cmake documentation. Why can't you check the version found by find_program, and use the embedded one if it is lower than the requested one?
It is possible, it adds some extra complexity, either we need some 3party for that like this, or do some naive implementation for ourselves, that is not hundreads of lines:
Which direction do you prefer?
@biodranik What is your opinion about the proposal above?
@Ferenc- CMake has built-in IF for VERSION_GREATER_EQUAL, why can't we use it?
Something must have falsified my previous tests. now it appears to be a viable option.
I have pushed a new commit with
VERSION_LESS
.You see, it is almost perfect ) The next steps are:
Should I push the macro into this PR, or in a new one, when we can actually use it more than once?
What are the benefits of some intermediate commits? Can you try to write/test the macro on top of these changes? (We'll squash them at the end into one commit).
They can be reviewed and tested for correctness individually, and most importantly they can be reverted individually,
if all that failed.
Done. The macro is now part of this PR.
Thanks! Looks good )
Is this if necessary? What if ARGN is always passed to add_subdirectory?
Why is it better than
?
It would be useful to also print a path to found package, but it is not critical.
Does it make sense to include this macro once from
cmake/OmimHelpers.cmake
and avoid inserting include into each 3p wrapper?@ -31,7 +31,12 @@ target_compile_definitions(${PROJECT_NAME}
PRIVATE GTEST_DONT_DEFINE_TEST WITH_GL_MOCK
find_package_or_fallback_to_3party
@ -31,7 +31,12 @@ target_compile_definitions(${PROJECT_NAME}
PRIVATE GTEST_DONT_DEFINE_TEST WITH_GL_MOCK
Done
Removed.
Makes things simpler for sure. The original idea was to avoid silently including macros, as it unintentionally invoked macros are rather hard and unpleasant to debug. But now I see, that it is considered premature optimization here.
So I moved the macro to
cmake/OmimHelpers.cmake
The requested changes are done.
The path printing is tricky because for example the current gtest code doesn't even set the
GTEST_INCLUDE_DIRS
, the way I think it should. AndGTEST_INCLUDE_DIRS
or such are useless, empty, so we would have to look for what has been last added to theINCLUDE_DIRECTORIES
, and get it out of there somehow.Because the current logical expression, expresses the relevant case that we have to handle.
The suggested conditional expression, does not express a relevant case, that is a rather irrelevant case, the fact that we even do something like logging in that scenario is just out of curtesy. We could skip that branch and the code would still work.
Thanks for your efforts! It looks good.