Commit 22ba9b6a authored by Ben Boeckel's avatar Ben Boeckel Committed by Brad King

FindGDAL: set the GDAL_VERSION

parent 525ff0c3
......@@ -24,6 +24,8 @@ This module will set the following variables in your project:
Include directories for GDAL headers.
``GDAL_LIBRARIES``
Libraries to link to GDAL.
``GDAL_VERSION``
The version of GDAL found.
Cache variables
^^^^^^^^^^^^^^^
......@@ -138,8 +140,19 @@ find_library(GDAL_LIBRARY
PATH_SUFFIXES lib
)
if (EXISTS "${GDAL_INCLUDE_DIR}/gdal_version.h")
file(STRINGS "${GDAL_INCLUDE_DIR}/gdal_version.h" _gdal_version
REGEX "GDAL_RELEASE_NAME")
string(REGEX REPLACE ".*\"\(.*\)\"" "\\1" GDAL_VERSION "${_gdal_version}")
unset(_gdal_version)
else ()
set(GDAL_VERSION GDAL_VERSION-NOTFOUND)
endif ()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GDAL DEFAULT_MSG GDAL_LIBRARY GDAL_INCLUDE_DIR)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GDAL
VERSION_VAR GDAL_VERSION
REQUIRED_VARS GDAL_LIBRARY GDAL_INCLUDE_DIR)
if (GDAL_FOUND AND NOT TARGET GDAL::GDAL)
add_library(GDAL::GDAL UNKNOWN IMPORTED)
......
......@@ -4,9 +4,7 @@ include(CTest)
find_package(GDAL REQUIRED)
# FindGDAL doesn't export a version number.
#add_definitions(-DCMAKE_EXPECTED_GDAL_VERSION="${GDAL_VERSION}")
add_definitions(-DCMAKE_EXPECTED_GDAL_VERSION="unknown")
add_definitions(-DCMAKE_EXPECTED_GDAL_VERSION="${GDAL_VERSION}")
add_executable(test_tgt main.c)
target_link_libraries(test_tgt GDAL::GDAL)
......
#include <gdal.h>
#include <stdio.h>
// #include <string.h>
#include <string.h>
int main()
{
printf("Found GDAL version %s, expected version %s\n", GDAL_RELEASE_NAME,
CMAKE_EXPECTED_GDAL_VERSION);
GDALAllRegister();
// return strcmp(GDAL_RELEASE_NAME, CMAKE_EXPECTED_GDAL_VERSION);
return 0;
return strcmp(GDAL_RELEASE_NAME, CMAKE_EXPECTED_GDAL_VERSION);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment