Support using non-hunter version of bzip2, zlib and libarchive if HUNTER_ENABLED is OFF
Introduction: among our modifications to support the HUNTER_ENABLED=OFF build (see also https://github.com/luxonis/depthai-core/pull/1048 and https://github.com/luxonis/depthai-core/pull/1049) this is probably the one that complicates the code the most, so I would understand if you prefer to not merge such modification. However, I think it was worth to isolate the change and made it available in the form of a PR.
When setting HUNTER_ENABLED=OFF, one can install all the dependencies via the usual CMake workflow in a directory that is added to CMAKE_PREFIX_PATH, and then build depthai-core . However, there are three packages that are installed in different ways depending of weather the hunter/luxonis fork is used, or if the upstream version is used.
The three packages are:
ZLIB: The hunter/luxonis ZLIB is found via find_package(ZLIB CONFIG) and it defines the ZLIB::zlib imported target, while the regular ZLIB does not install any CMake config file, but it can be found by CMake's upstream FindZLIB.cmake that defines the ZLIB::ZLIB imported target.
BZip2: The hunter/luxonis BZip2 is found via find_package(BZip2 CONFIG) and it defines the BZip2::bz2 imported target, while the regular BZip2 does not install any CMake config file, but it can be found by CMake's upstream FindBZip2.cmake that defines the BZip2::BZip2 imported target.
libarchive: The hunter/luxonis libarchive is found via find_package(archive_static CONFIG) and it defines the archive_static imported target, while the regular libarchivedoes not install any CMake config file, but it can be found by CMake's upstream FindLibArchive.cmake that defines the LibArchive::LibArchive imported target.
If you have a project that is already using the upstream version, in general you would like for depthai-core to also use the upstream version.
To achieve this, this PR modifies the logic if HUNTER_ENABLED is set to OFF. In that case, first the hunter/luxonis package names and target are tested, and if they can be found they are used, while if they do not exist the logic fallbacks to the upstream package names/target names.
If HUNTER_ENABLED is set to ON, the PR does not change the existing logic.
Thanks @traversaro !
Really excited to get these merged in.
The changes besides the implicit minimum cmake version look good to me.
As I see it this is what has to be done before the merge:
- Add Find**** files to avoid the minimum cmake version
- Add a test to CI to test with HUNTER_ENABLED=OFF.
- I think replicating however you build locally will work (just docker-zing it)