[Liblas-commits] hg: add GeoTIFF-style LASzip finding cmake module

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Dec 23 22:29:11 EST 2010


details:   http://hg.liblas.orghg/rev/8f170797c7c5
changeset: 2640:8f170797c7c5
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Dec 23 21:29:05 2010 -0600
description:
add GeoTIFF-style LASzip finding cmake module

diffstat:

 CMakeLists.txt                 |  14 ++++-
 cmake/modules/FindLASzip.cmake |  96 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+), 4 deletions(-)

diffs (124 lines):

diff -r dfcba7cf296a -r 8f170797c7c5 CMakeLists.txt
--- a/CMakeLists.txt	Thu Dec 23 21:01:50 2010 -0600
+++ b/CMakeLists.txt	Thu Dec 23 21:29:05 2010 -0600
@@ -284,10 +284,16 @@
 # LASZIP support - optional, default=OFF
 set(WITH_LASZIP FALSE CACHE BOOL "Choose if LASZIP support should be built")
 if(WITH_LASZIP)
-  include_directories(${LASZIP_INCLUDE_DIR})
-  add_definitions(-DHAVE_LASZIP=1)
-  mark_as_advanced(CLEAR LASZIP_INCLUDE_DIR) 
-  mark_as_advanced(CLEAR LASZIP_LIBRARY) 
+  find_package(LASzip 1.0.0)
+
+  if(LASZIP_FOUND)    
+    set(CMAKE_REQUIRED_LIBRARIES ${LASZIP_LIBRARY})
+    include_directories(${LASZIP_INCLUDE_DIR})
+    add_definitions(-DHAVE_LASZIP=1)
+    mark_as_advanced(CLEAR LASZIP_INCLUDE_DIR) 
+    mark_as_advanced(CLEAR LASZIP_LIBRARY) 
+    mark_as_advanced(CLEAR LASZIP_VERSION) 
+  endif()
 endif()
 
 ###############################################################################
diff -r dfcba7cf296a -r 8f170797c7c5 cmake/modules/FindLASzip.cmake
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake/modules/FindLASzip.cmake	Thu Dec 23 21:29:05 2010 -0600
@@ -0,0 +1,96 @@
+###############################################################################
+#
+# CMake module to search for LASzip library
+#
+# On success, the macro sets the following variables:
+# LASZIP_FOUND       = if the library found
+# LASZIP_LIBRARIES   = full path to the library
+# LASZIP_INCLUDE_DIR = where to find the library headers also defined,
+#                       but not for general use are
+# LASZIP_LIBRARY     = where to find the PROJ.4 library.
+# LASZIP_VERSION     = version of library which was found, e.g. "1.2.5"
+#
+# Copyright (c) 2009 Mateusz Loskot <mateusz at loskot.net>
+#
+# Module source: http://github.com/mloskot/workshop/tree/master/cmake/
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+###############################################################################
+MESSAGE(STATUS "Searching for LASzip ${LASzip_FIND_VERSION}+ library")
+
+IF(LASZIP_INCLUDE_DIR)
+  # Already in cache, be silent
+  SET(LASZIP_FIND_QUIETLY TRUE)
+ENDIF()
+
+IF(WIN32)
+  SET(OSGEO4W_IMPORT_LIBRARY laszip_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(LASZIP_INCLUDE_DIR
+  laszip.hpp
+  PATH_PREFIXES laszip
+  PATHS
+  ${OSGEO4W_ROOT_DIR}/include)
+
+SET(LASZIP_NAMES ${OSGEO4W_IMPORT_LIBRARY} laszip)
+
+FIND_LIBRARY(LASZIP_LIBRARY
+  NAMES ${LASZIP_NAMES}
+  PATHS
+  ${OSGEO4W_ROOT_DIR}/lib)
+
+IF(LASZIP_FOUND)
+  SET(LASZIP_LIBRARIES ${LASZIP_LIBRARY})
+ENDIF()
+
+IF(LASZIP_INCLUDE_DIR)
+  SET(LASZIP_VERSION 0)
+
+  SET(LASZIP_VERSION_H "${LASZIP_INCLUDE_DIR}/laszip/laszip.hpp")
+  FILE(READ ${LASZIP_VERSION_H} LASZIP_VERSION_H_CONTENTS)
+
+  IF (DEFINED LASZIP_VERSION_H_CONTENTS)
+    string(REGEX REPLACE ".*#define[ \t]LASZIP_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" LASZIP_VERSION_MAJOR "${LASZIP_VERSION_H_CONTENTS}")
+    string(REGEX REPLACE ".*#define[ \t]LASZIP_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" LASZIP_VERSION_MINOR "${LASZIP_VERSION_H_CONTENTS}")
+    string(REGEX REPLACE ".*#define[ \t]LASZIP_VERSION_REVISION[ \t]+([0-9]+).*"   "\\1" LASZIP_VERSION_REVISION   "${LASZIP_VERSION_H_CONTENTS}")
+
+    if(NOT ${LASZIP_VERSION_MAJOR} MATCHES "[0-9]+")
+      message(FATAL_ERROR "LASzip version parsing failed for LASZIP_VERSION_MAJOR!")
+    endif()
+    if(NOT ${LASZIP_VERSION_MINOR} MATCHES "[0-9]+")
+      message(FATAL_ERROR "LASzip version parsing failed for LASZIP_VERSION_MINOR!")
+    endif()
+    if(NOT ${LASZIP_VERSION_REVISION} MATCHES "[0-9]+")
+      message(FATAL_ERROR "LASzip version parsing failed for LASZIP_VERSION_REVISION!")
+    endif()
+
+
+    SET(LASZIP_VERSION "${LASZIP_VERSION_MAJOR}.${LASZIP_VERSION_MINOR}.${LASZIP_VERSION_REVISION}"
+      CACHE INTERNAL "The version string for LASzip library")
+
+    IF (LASZIP_VERSION VERSION_EQUAL LASzip_FIND_VERSION OR
+        LASZIP_VERSION VERSION_GREATER LASzip_FIND_VERSION)
+      MESSAGE(STATUS "Found LASzip version: ${LASZIP_VERSION}")
+    ELSE()
+      MESSAGE(FATAL_ERROR "LASzip version check failed. Version ${LASZIP_VERSION} was found, at least version ${LASzip_FIND_VERSION} is required")
+    ENDIF()
+  ELSE()
+    MESSAGE(FATAL_ERROR "Failed to open ${LASZIP_VERSION_H} file")
+  ENDIF()
+
+ENDIF()
+
+# Handle the QUIETLY and REQUIRED arguments and set LASZIP_FOUND to TRUE
+# if all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LASzip DEFAULT_MSG LASZIP_LIBRARY LASZIP_INCLUDE_DIR)


More information about the Liblas-commits mailing list