Skip to content
Snippets Groups Projects
Commit 9b26e4ef authored by Ben Boeckel's avatar Ben Boeckel
Browse files

FindGDAL: remove usage of gdal-config

CMake builds don't contain this tool and a CMake build gets shadowed by
the availability of a non-CMake build with it. Instead, just generate
the possible library names.
parent 334b2c00
No related branches found
No related tags found
No related merge requests found
......@@ -60,68 +60,6 @@ GDAL installation prefix.
#
#include "gdal.h"
if(UNIX)
# Use gdal-config to obtain the library version (this should hopefully
# allow us to -lgdal1.x.y where x.y are correct version)
# For some reason, libgdal development packages do not contain
# libgdal.so...
find_program(GDAL_CONFIG gdal-config
HINTS
${GDAL_ROOT}
ENV GDAL_DIR
ENV GDAL_ROOT
PATH_SUFFIXES bin
)
if(GDAL_CONFIG)
exec_program(${GDAL_CONFIG} ARGS --libs OUTPUT_VARIABLE GDAL_CONFIG_LIBS)
if(GDAL_CONFIG_LIBS)
# treat the output as a command line and split it up
separate_arguments(args NATIVE_COMMAND "${GDAL_CONFIG_LIBS}")
# only consider libraries whose name matches this pattern
set(name_pattern "[gG][dD][aA][lL]")
# consider each entry as a possible library path, name, or parent directory
foreach(arg IN LISTS args)
# library name
if("${arg}" MATCHES "^-l(.*)$")
set(lib "${CMAKE_MATCH_1}")
# only consider libraries whose name matches the expected pattern
if("${lib}" MATCHES "${name_pattern}")
list(APPEND _gdal_lib "${lib}")
endif()
# library search path
elseif("${arg}" MATCHES "^-L(.*)$")
list(APPEND _gdal_libpath "${CMAKE_MATCH_1}")
# assume this is a full path to a library
elseif(IS_ABSOLUTE "${arg}" AND EXISTS "${arg}")
# extract the file name
get_filename_component(lib "${arg}" NAME)
# only consider libraries whose name matches the expected pattern
if(NOT "${lib}" MATCHES "${name_pattern}")
continue()
endif()
# extract the file directory
get_filename_component(dir "${arg}" DIRECTORY)
# remove library prefixes/suffixes
string(REGEX REPLACE "^(${CMAKE_SHARED_LIBRARY_PREFIX}|${CMAKE_STATIC_LIBRARY_PREFIX})" "" lib "${lib}")
string(REGEX REPLACE "(${CMAKE_SHARED_LIBRARY_SUFFIX}|${CMAKE_STATIC_LIBRARY_SUFFIX})$" "" lib "${lib}")
# use the file name and directory as hints
list(APPEND _gdal_libpath "${dir}")
list(APPEND _gdal_lib "${lib}")
endif()
endforeach()
endif()
endif()
endif()
find_path(GDAL_INCLUDE_DIR gdal.h
HINTS
${GDAL_ROOT}
......@@ -133,18 +71,22 @@ find_path(GDAL_INCLUDE_DIR gdal.h
include
)
# GDAL name its library when built with CMake as `gdal${major}${minor}`.
set(_gdal_versions
3.0 2.4 2.3 2.2 2.1 2.0 1.11 1.10 1.9 1.8 1.7 1.6 1.5 1.4 1.3 1.2)
set(_gdal_libnames)
foreach (_gdal_version IN LISTS _gdal_versions)
string(REPLACE "." "" _gdal_version "${_gdal_version}")
list(APPEND _gdal_libnames "gdal${_gdal_version}" "GDAL${_gdal_libnames}")
endforeach ()
find_library(GDAL_LIBRARY
NAMES ${_gdal_lib} gdal gdal_i gdal1.5.0 gdal1.4.0 gdal1.3.2 GDAL
NAMES ${_gdal_libnames} gdal gdal_i gdal1.5.0 gdal1.4.0 gdal1.3.2 GDAL
HINTS
${GDAL_ROOT}
ENV GDAL_DIR
ENV GDAL_ROOT
# This is last because `gdal-config` may not exist if it was built with
# CMake. Looking for it out-of-order with the include path may end up with
# a CMake-built include path and a autoconf-built libpath from the
# `gdal-config` tool.
${_gdal_libpath}
PATH_SUFFIXES lib
)
if (EXISTS "${GDAL_INCLUDE_DIR}/gdal_version.h")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment