[Liblas-devel] Patches to cmake configuration for libLAS 1.7.0
Charles Karney
charles.karney at sri.com
Fri Oct 5 07:20:39 PDT 2012
I have made some patches to the cmake configuration for libLAS 1.7.0
(roughly in order of importance):
(1) Add support for find_package(libLAS). Installation adds a file
liblas-config.cmake to the installation tree and find_package will use
this to determine the include directories and library paths.
(2) Fix FindGeoTIFF.cmake so that it works for Linux (PATH_PREFIXES
should be PATH_SUFFIXES and libgeotiff needs to be searched as well as
geotiff).
(3) Remove -pedantic compilation option for Unix because it causes
compilation to fail with boost 1.15.0 under Linux (because of a comma at
the end of an enum list).
(4) Add runtime library path to libLAS utilities for Unix.
(5) Remove -Wcast-qual, -Wfloat-equal, and -Wredundant-decls compilation
options for Unix to reduce the number of compilation warnings.
I posted this as an "issue" on github a month ago; but there is no
provision for attaching the patch. So I'm including the patch in this
E-mail. (Be warned that the patch may not apply cleanly because the
release is inconsistent in its use of DOS vs Unix line endings.)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21461a5..954619d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -139,8 +139,12 @@ else()
# Recommended C++ compilation flags
# -Weffc++
+ #
+ # Remove -pedandic which causes errors from boost (comma at end of
+ # enum) 2012-09-05. Remove -Wcast-qual -Wfloat-equal
+ # -Wredundant-decls to suppress the multitude of warning messages.
set(LIBLAS_COMMON_CXX_FLAGS
- "-pedantic -ansi -Wall -Wpointer-arith -Wcast-align -Wcast-qual
-Wfloat-equal -Wredundant-decls -Wno-long-long")
+ "-ansi -Wall -Wpointer-arith -Wcast-align -Wno-long-long")
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
@@ -354,7 +358,8 @@ else()
endif()
endif()
-
+# Add find_package(libLAS) support
+add_subdirectory(cmake)
# Version information
SET(CPACK_PACKAGE_VERSION_MAJOR ${LIBLAS_VERSION_MAJOR})
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
index 7dc71c3..1b30cdd 100644
--- a/apps/CMakeLists.txt
+++ b/apps/CMakeLists.txt
@@ -180,6 +180,22 @@ install(TARGETS ${LIBLAS_UTILITIES}
if(UNIX)
+ set(LIBLAS_UTILS_RPATH ${CMAKE_INSTALL_PREFIX}/lib ${Boost_LIBRARY_DIRS})
+ if(LASZIP_FOUND)
+ get_filename_component(LASZIP_LIBRARY_DIRS ${LASZIP_LIBRARY} PATH)
+ set (LIBLAS_UTILS_RPATH ${LIBLAS_UTILS_RPATH} ${LASZIP_LIBRARY_DIRS})
+ endif()
+ if(GEOTIFF_FOUND)
+ get_filename_component(GEOTIFF_LIBRARY_DIRS ${GEOTIFF_LIBRARY} PATH)
+ set (LIBLAS_UTILS_RPATH ${LIBLAS_UTILS_RPATH} ${GEOTIFF_LIBRARY_DIRS})
+ endif()
+ if(GDAL_FOUND)
+ get_filename_component(GDAL_LIBRARY_DIRS ${GDAL_LIBRARY} PATH)
+ set (LIBLAS_UTILS_RPATH ${LIBLAS_UTILS_RPATH} ${GDAL_LIBRARY_DIRS})
+ endif()
+ set_target_properties(${LIBLAS_UTILITIES} PROPERTIES
+ INSTALL_RPATH "${LIBLAS_UTILS_RPATH}")
+
if(WITH_PKGCONFIG)
set(PKGCFG_PREFIX "${CMAKE_INSTALL_PREFIX}")
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
new file mode 100644
index 0000000..18c876a
--- /dev/null
+++ b/cmake/CMakeLists.txt
@@ -0,0 +1,33 @@
+#############################################################################
+# Config file generation and installation
+#############################################################################
+
+# Set where cmake will install liblas-config.cmake. It's installed in
+# ${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR} and ${PROJECT_ROOT_DIR}
+# is the relative path to the root from there.
+if (NOT WIN32)
+ set(INSTALL_CMAKE_DIR "share/cmake/${PROJECT_NAME}-${VERSION}")
+ set (PROJECT_ROOT_DIR "../../..")
+else ()
+ set(INSTALL_CMAKE_DIR "cmake")
+ set (PROJECT_ROOT_DIR "..")
+endif ()
+
+# Now create the liblas-config files using the .in templates
+configure_file (liblas-config.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/liblas-config.cmake @ONLY)
+configure_file (liblas-config-version.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/liblas-config-version.cmake @ONLY)
+
+# Install the liblas-config files so that other modules can find this
+# project using 'find_package(libLAS)'
+install (FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/liblas-config.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/liblas-config-version.cmake"
+ DESTINATION "${INSTALL_CMAKE_DIR}")
+
+# Make information about libLAS available. The depends target is
+# defined in ../src/CMakeLists.txt
+install (EXPORT depends
+ FILE "liblas-depends.cmake"
+ DESTINATION "${INSTALL_CMAKE_DIR}")
diff --git a/cmake/liblas-config-version.cmake.in
b/cmake/liblas-config-version.cmake.in
new file mode 100644
index 0000000..7ad76d6
--- /dev/null
+++ b/cmake/liblas-config-version.cmake.in
@@ -0,0 +1,18 @@
+# Version checking for libLAS
+
+set(PACKAGE_VERSION "@VERSION@")
+set(PACKAGE_VERSION_MAJOR "@LIBLAS_VERSION_MAJOR@")
+set(PACKAGE_VERSION_MINOR "@LIBLAS_VERSION_MINOR@")
+set(PACKAGE_VERSION_PATCH "@LIBLAS_VERSION_PATCH@")
+
+if (WIN32 AND NOT "${CMAKE_GENERATOR}" STREQUAL "@CMAKE_GENERATOR@")
+ # Reject if there's a mismatch on compiler versions (Windows only)
+ set (PACKAGE_VERSION_UNSUITABLE TRUE)
+elseif (PACKAGE_FIND_VERSION)
+ if (${PACKAGE_FIND_VERSION} VERSION_EQUAL ${PACKAGE_VERSION})
+ set (PACKAGE_VERSION_EXACT TRUE)
+ elseif (${PACKAGE_FIND_VERSION} VERSION_LESS ${PACKAGE_VERSION}
+ AND ${PACKAGE_FIND_VERSION_MAJOR} EQUAL ${PACKAGE_VERSION_MAJOR})
+ set (PACKAGE_VERSION_COMPATIBLE TRUE)
+ endif ()
+endif ()
diff --git a/cmake/liblas-config.cmake.in b/cmake/liblas-config.cmake.in
new file mode 100644
index 0000000..51e1163
--- /dev/null
+++ b/cmake/liblas-config.cmake.in
@@ -0,0 +1,29 @@
+# Configure libLAS package
+#
+# It defines the following variables
+# libLAS_FOUND = LIBLAS_FOUND - TRUE
+# libLAS_INCLUDE_DIRS - include directories for libLAS
+# libLAS_LIBRARY_DIRS - library directory
+# libLAS_LIBRARIES - all the libraries of the components requested
+# if no components specified then all found
+# libLAS_VERSION - libLAS library version
+
+message (STATUS "Reading ${CMAKE_CURRENT_LIST_FILE}")
+set (libLAS_VERSION "@PACKAGE_VERSION@")
+message (STATUS "libLAS configuration, version "
+ ${libLAS_VERSION})
+
+# Tell the user project where to find our headers and libraries
+get_filename_component (_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
+get_filename_component (PROJECT_ROOT_DIR "${_DIR}/@PROJECT_ROOT_DIR@"
ABSOLUTE)
+set (libLAS_INCLUDE_DIRS "${PROJECT_ROOT_DIR}/include")
+set (libLAS_LIBRARY_DIRS "${PROJECT_ROOT_DIR}/lib")
+
+include ("${_DIR}/liblas-depends.cmake")
+if(WIN32)
+ set (libLAS_LIBRARIES liblas liblas_c)
+else()
+ set (libLAS_LIBRARIES las las_c)
+endif()
+
+set (LIBLAS_FOUND TRUE)
diff --git a/cmake/modules/FindGeoTIFF.cmake
b/cmake/modules/FindGeoTIFF.cmake
index e0bcd45..28d498f 100644
--- a/cmake/modules/FindGeoTIFF.cmake
+++ b/cmake/modules/FindGeoTIFF.cmake
@@ -38,7 +38,7 @@ ENDIF()
FIND_PATH(GEOTIFF_INCLUDE_DIR
geotiff.h
- PATH_PREFIXES geotiff
+ PATH_SUFFIXES geotiff libgeotiff
PATHS
${OSGEO4W_ROOT_DIR}/include)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d378358..212e1a4 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -254,9 +254,12 @@ if (APPLE)
endif()
###############################################################################
-# Targets installation
+# Targets installation. The EXPORT clause specifies a depends target
+# which packages up information about the libraries for
+# liblas-config.cmake.
install(TARGETS ${LIBLAS_LIB_NAME} ${LIBLAS_C_LIB_NAME}
+ EXPORT depends
RUNTIME DESTINATION ${LIBLAS_BIN_DIR}
LIBRARY DESTINATION ${LIBLAS_LIB_DIR}
ARCHIVE DESTINATION ${LIBLAS_LIB_DIR})
--
Charles Karney <charles.karney at sri.com>
SRI International, Princeton, NJ 08543-5300
Tel: +1 609 734 2312
Fax: +1 609 734 2662
More information about the Liblas-devel
mailing list