diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2018-10-31 18:48:15 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-11-01 17:16:37 (GMT) |
commit | 22ba9b6a328a0eea77559b2d607fe8d525445812 (patch) | |
tree | 962e8435dcf4486b28ab383e5d6f17d7550cc01d | |
parent | 525ff0c3bc1f625756337c2ae724a58ec93ba4d1 (diff) | |
download | CMake-22ba9b6a328a0eea77559b2d607fe8d525445812.zip CMake-22ba9b6a328a0eea77559b2d607fe8d525445812.tar.gz CMake-22ba9b6a328a0eea77559b2d607fe8d525445812.tar.bz2 |
FindGDAL: set the GDAL_VERSION
-rw-r--r-- | Modules/FindGDAL.cmake | 15 | ||||
-rw-r--r-- | Tests/FindGDAL/Test/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Tests/FindGDAL/Test/main.c | 5 |
3 files changed, 17 insertions, 7 deletions
diff --git a/Modules/FindGDAL.cmake b/Modules/FindGDAL.cmake index 5dd9335..8522f9b 100644 --- a/Modules/FindGDAL.cmake +++ b/Modules/FindGDAL.cmake @@ -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) diff --git a/Tests/FindGDAL/Test/CMakeLists.txt b/Tests/FindGDAL/Test/CMakeLists.txt index 20f4b84..8bdc57c 100644 --- a/Tests/FindGDAL/Test/CMakeLists.txt +++ b/Tests/FindGDAL/Test/CMakeLists.txt @@ -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) diff --git a/Tests/FindGDAL/Test/main.c b/Tests/FindGDAL/Test/main.c index 046eb99..7b31a13 100644 --- a/Tests/FindGDAL/Test/main.c +++ b/Tests/FindGDAL/Test/main.c @@ -1,12 +1,11 @@ #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); } |