FindGDAL module populates GDAL_LIBRARY with the first dependent library, not libgdal.a
- RHEL 7.4
- CMake 3.9.0
- GDAL 2.1.1
My project has a dependency on GDAL
and I'm attempting to use find_package(GDAL ...)
to obtain the path to its library. The call succeeds, but GDAL_LIBRARY
is populated with the first dependent library, /path/to/proj4/lib/libproj.a
in my case, instead of /path/to/gdal/lib/libdal.a
.
I looked at FindGDAL.cmake to determine how GDAL_LIBRARY
is being populated and it's trying to use gdal-config
to get the library and its path. The output from this command would look something like this:
/path/to/gdal/lib/libgdal.a -L/path/to/proj4/lib -lproj -L/path/to/geos/lib -l:libgeos_c.a -l:libgeos.a -ljpeg -L/path/to/geotiff/lib -l:libgeotiff.a -lm -L/path/to/tiff/lib -ltiff -lpng -lz -lpthread -lm -lrt -ldl
Unfortunately, the logic on lines 70-73 appears to use the dependent libraries and their paths as hints to locate GDAL's library and populate GDAL_LIBRARY
. In my case, this results in GDAL_LIBRARY
being set to /path/to/proj4/lib/libproj.a
instead of /path/to/gdal/lib/libgdal.a
, the first entry in the output from gdal-config
.