[Liblas-commits] hg: Implemented version check of GeoTIFF library
in FindGeoTIFF....
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Jan 7 17:36:24 EST 2010
changeset b2f6a8113ba4 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=b2f6a8113ba4
summary: Implemented version check of GeoTIFF library in FindGeoTIFF.cmake macro
diffstat:
build/cmake/FindGeoTIFF.cmake | 78 ++++++++++++++++++++++++++++++------------
1 files changed, 56 insertions(+), 22 deletions(-)
diffs (112 lines):
diff -r 5928c7842ce3 -r b2f6a8113ba4 build/cmake/FindGeoTIFF.cmake
--- a/build/cmake/FindGeoTIFF.cmake Thu Jan 07 22:35:24 2010 +0000
+++ b/build/cmake/FindGeoTIFF.cmake Thu Jan 07 22:36:11 2010 +0000
@@ -5,9 +5,10 @@
# On success, the macro sets the following variables:
# GEOTIFF_FOUND = if the library found
# GEOTIFF_LIBRARIES = full path to the library
-# GEOTIFF_INCLUDE_DIR = where to find the library headers
-# also defined, but not for general use are
-# GEOTIFF_LIBRARY, where to find the PROJ.4 library.
+# GEOTIFF_INCLUDE_DIR = where to find the library headers also defined,
+# but not for general use are
+# GEOTIFF_LIBRARY = where to find the PROJ.4 library.
+# GEOTIFF_VERSION = version of library which was found, e.g. "1.2.5"
#
# Copyright (c) 2009 Mateusz Loskot <mateusz at loskot.net>
#
@@ -18,42 +19,75 @@
#
###############################################################################
MESSAGE(STATUS "Searching for GeoTIFF ${GeoTIFF_FIND_VERSION}+ library")
-MESSAGE(STATUS " NOTE: Required version is not checked - to be implemented")
IF(GEOTIFF_INCLUDE_DIR)
- # Already in cache, be silent
- SET(GEOTIFF_FIND_QUIETLY TRUE)
+ # Already in cache, be silent
+ SET(GEOTIFF_FIND_QUIETLY TRUE)
ENDIF()
IF(WIN32)
- SET(OSGEO4W_IMPORT_LIBRARY geotiff_i)
- IF(DEFINED ENV{OSGEO4W_ROOT})
- SET(OSGEO4W_ROOT_DIR $ENV{OSGEO4W_ROOT})
- MESSAGE(STATUS "Trying OSGeo4W using environment variable OSGEO4W_ROOT=$ENV{OSGEO4W_ROOT}")
- ELSE()
- SET(OSGEO4W_ROOT_DIR c:/OSGeo4W)
- MESSAGE(STATUS "Trying OSGeo4W using default location OSGEO4W_ROOT=${OSGEO4W_ROOT_DIR}")
- ENDIF()
+ SET(OSGEO4W_IMPORT_LIBRARY geotiff_i)
+ IF(DEFINED ENV{OSGEO4W_ROOT})
+ SET(OSGEO4W_ROOT_DIR $ENV{OSGEO4W_ROOT})
+ MESSAGE(STATUS "Trying OSGeo4W using environment variable OSGEO4W_ROOT=$ENV{OSGEO4W_ROOT}")
+ ELSE()
+ SET(OSGEO4W_ROOT_DIR c:/OSGeo4W)
+ MESSAGE(STATUS "Trying OSGeo4W using default location OSGEO4W_ROOT=${OSGEO4W_ROOT_DIR}")
+ ENDIF()
ENDIF()
FIND_PATH(GEOTIFF_INCLUDE_DIR
- geotiff.h
- PATH_PREFIXES geotiff
- PATHS
- ${OSGEO4W_ROOT_DIR}/include)
+ geotiff.h
+ PATH_PREFIXES geotiff
+ PATHS
+ ${OSGEO4W_ROOT_DIR}/include)
SET(GEOTIFF_NAMES ${OSGEO4W_IMPORT_LIBRARY} geotiff)
FIND_LIBRARY(GEOTIFF_LIBRARY
- NAMES ${GEOTIFF_NAMES}
- PATHS
- ${OSGEO4W_ROOT_DIR}/lib)
+ NAMES ${GEOTIFF_NAMES}
+ PATHS
+ ${OSGEO4W_ROOT_DIR}/lib)
IF(GEOTIFF_FOUND)
SET(GEOTIFF_LIBRARIES ${GEOTIFF_LIBRARY})
ENDIF()
+IF(GEOTIFF_INCLUDE_DIR)
+ SET(GEOTIFF_VERSION 0)
+
+ SET(GEOTIFF_VERSION_H "${GEOTIFF_INCLUDE_DIR}/geotiff.h")
+ FILE(READ ${GEOTIFF_VERSION_H} GEOTIFF_VERSION_H_CONTENTS)
+
+ IF (DEFINED GEOTIFF_VERSION_H_CONTENTS)
+ STRING(REGEX REPLACE ".*#define[ \t]LIBGEOTIFF_VERSION[ \t]+([0-9]+).*" "\\1" GEOTIFF_VERSION_NUM "${GEOTIFF_VERSION_H_CONTENTS}")
+
+ IF(NOT ${GEOTIFF_VERSION_NULL} MATCHES "[0-9]+")
+ MESSAGE(FATAL_ERROR "GeoTIFF version parsing failed!")
+ ENDIF()
+
+ IF(GEOTIFF_VERSION_NUM AND NOT "${GEOTIFF_VERSION_NUM}" STREQUAL "0")
+ MATH(EXPR GTIFF_VERSION_MAJOR "${GEOTIFF_VERSION_NUM} / 1000")
+ MATH(EXPR GTIFF_VERSION_MINOR "${GEOTIFF_VERSION_NUM} % 1000 / 100")
+ MATH(EXPR GTIFF_VERSION_PATCH "${GEOTIFF_VERSION_NUM} % 100 / 10")
+ ENDIF()
+
+ SET(GEOTIFF_VERSION "${GTIFF_VERSION_MAJOR}.${GTIFF_VERSION_MINOR}.${GTIFF_VERSION_PATCH}"
+ CACHE INTERNAL "The version string for GeoTIFF library")
+
+ IF (GEOTIFF_VERSION VERSION_EQUAL GeoTIFF_FIND_VERSION OR
+ GEOTIFF_VERSION VERSION_GREATER GeoTIFF_FIND_VERSION)
+ MESSAGE(STATUS "Found GeoTIFF version: ${GEOTIFF_VERSION}")
+ ELSE()
+ MESSAGE(FATAL_ERROR "GeoTIFF version check failed. Version ${GEOTIFF_VERSION} was found, at least version ${GeoTIFF_FIND_VERSION} is required")
+ ENDIF()
+ ELSE()
+ MESSAGE(FATAL_ERROR "Failed to open ${GEOTIFF_VERSION_H} file")
+ ENDIF()
+
+ENDIF()
+
# Handle the QUIETLY and REQUIRED arguments and set GEOTIFF_FOUND to TRUE
# if all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(GEOTIFF DEFAULT_MSG GEOTIFF_LIBRARY GEOTIFF_INCLUDE_DIR)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GeoTIFF DEFAULT_MSG GEOTIFF_LIBRARY GEOTIFF_INCLUDE_DIR)
More information about the Liblas-commits
mailing list