Compilation

Author:Mateusz Loskot
Contact:mateusz at loskot dot net
Author:Howard Butler
Contact:hobu.inc at gmail dot com

Warning

This document is only for the 1.6 libLAS release. Unfortunately, there is no documentation for building earlier libLAS releases at this time, though it is a straightforward Autoconf setup for unix and nmake files for windows.

As of libLAS 1.6, CMake 2.8.1+ is the prescribed tool for building libLAS from source as well as running unit tests. CMake is a cross-platform build system that provides a number of benefits, and its usage ensures a single, up-to-date build system for all libLAS-supported operating systems and compiler platforms.

Like a combination of autoconf/autotools, except that it actually works on Windows (and works without eye-stabbing pain in general), CMake is somewhat of a meta-building tool. It can be used to generate MSVC project files, GNU Makefiles, NMake files for MSVC, XCode projects on Mac OS X, and Eclipse projects (as well as many others). This functionality allows the libLAS project to avoid maintaining these build options by hand and target a single configuration and build platform.

This tutorial will describe how to build libLAS using CMake on both a Unix platform and a Windows platform.

Note

The only supported build environment libLAS moving forward from the 1.6 release is CMake. Autoconf configuration will be phased out and will no longer be updated after the 1.6 release.

Prerequisites

In addition to CMake 2.8.1+, you also need a C/C++ compiler. The following compilers are known to work:

  • MSVC 2003 (VC 7.1) (not all optional libraries work with 2003)
  • MSVC 2005 (VC 8.0)
  • MSVC 2008 (VC 9.0)
  • MSVC 2010
  • GCC 4.0
  • GCC 4.2
  • LLVM 4.8/Clang 2.8

Boost

Boost is required to build libLAS 1.6. Set Boost_INCLUDE_DIR if CMake cannot find it in a default location. Additionally, set Boost_LIBRARY_DIRS if it cannot find your libraries.

Warning

You need Boost version 1.38.0 or higher to build libLAS 1.6.

Note

If you are building on Windows, http://www.boostpro.com/download/ has an excellent installer. The boost installer defaults are not enough, however, and you will need to scroll down and select “Boost ProgramOptions”, “Boost Thread”, and “Boost Serialization” components, and select static + multithreaded as the types. If you want to link in a different way, you will have to change your CMake cache variables Boost_USE_STATIC_LIBS and Boost_USE_MULTITHREADED accordingly.

Selecting program_options with the Boostpro.com installer

Optional libraries

The base libLAS library can work without optional libraries to read and write LAS files, but linking in libraries like GDAL, and libgeotiff will provide a boost in functionality to libLAS. libLAS linkage of GDAL and libgeotiff enhances spatial coordinate system description and provides data reprojection support. By linking OCI with the Oracle Instant Client, libLAS can be used to load LAS data into Oracle Point Cloud -enabled Oracle tables.

Building these libraries is beyond the scope of this document, but all except OCI can be built from source and installed at your leisure.

GDAL

Obtain GDAL via whatever method is convenient. Linux platforms such as Debian have DebianGIS, Mac OS X has the KyngChaos software frameworks, and Windows has the OSGeo4W platform.

  • GDAL 1.7+ is required.

Note

If you are using OSGeo4W as your provider of GDAL, you must use the gdal-dev package, which is GDAL 1.8 as of 11/19/2010.

libgeotiff

Obtain libgeotiff from the same place you got GDAL.

  • libgeotiff 1.3.0+ is required

Note

GDAL surreptitiously embeds a copy of libgeotiff in its library build but there is no way for you to know this. In addition to embedding libgeotiff, it also strips away the library symbols that libLAS needs, meaning that libLAS can’t simply link against GDAL. If you are building both of these libraries yourself, make sure you build GDAL using the “External libgeotiff” option, which will prevent the insanity that can ensue on some platforms. OSGeo4W users, including those using that platform to link and build libLAS themselves, do not need to worry about this issue.

OCI

Obtain the Oracle Instant Client and install in a location on your system. Be sure to install both the “Basic” and the “SDK” modules. Set your ORACLE_HOME environment variable system- or user-wide to point to this location so the CMake configuration can find your install.

Warning

OCI‘s libraries are inconsistently named. You may need to create symbolic links for some library names in order for the CMake to find them:

cd $ORACLE_HOME
ln -s libocci.so.11.1 libocci.so
ln -s libclntsh.so.11.1 libclntsh.so
ln -s libociei.so.11.1 libociei.so

Note

MSVC should only require the oci.lib and oci.dll library and dlls.

  • Oracle 11g is recommended, but OCI for 10g will work.

Using “Unix Makefiles” on Linux

Get the source code

See libLAS Source Repository for how to obtain the latest development version or visit Download to get the latest released version.

Prepare a build directory

CMake allows you to generate different builders for a project, and in this example, we are going to generate a “Unix Makefiles” builder for libLAS on Mac OS X.

$ cd liblas
$ mkdir makefiles
$ cd makefiles

Configure base library

Configure the basic core library for the “Unix Makefiles” target:

$ cmake -G "Unix Makefiles" ../
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Enable libLAS utilities to build - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/hobu/hg/liblas-cmake/makefiles

Issue the make command

This will build a base build of the library, with no extra libraries being configured.

$ make
-- Enable libLAS utilities to build - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/hobu/hg/liblas-cmake/makefiles
Scanning dependencies of target las
[  3%] Building CXX object src/CMakeFiles/las.dir/lasclassification.cpp.o
...
[ 60%] Building CXX object src/CMakeFiles/las.dir/detail/writer/writer.cpp.o
Linking CXX static library ../bin/Debug/liblas.a
[ 60%] Built target las
Scanning dependencies of target las_c
[ 63%] Building CXX object src/CMakeFiles/las_c.dir/las_c_api.cpp.o
Linking CXX shared library ../bin/Debug/liblas_c.dylib
[ 63%] Built target las_c
Scanning dependencies of target las2las
...
[100%] Built target txt2las

Run make install and test your installation with a lasinfo command

make install will install the utilities in the location that was specified for ‘CMAKE_INSTALL_PREFIX’. Once installed, ensure that you can run lasinfo.

$ lasinfo ../test/data/TO_core_last_clip.las

---------------------------------------------------------
  Header Summary
---------------------------------------------------------
  File Name: ../test/data/TO_core_last_clip.las
  Version:                    1.0
  Source ID:                  0
  Reserved:                   0
  Project ID/GUID:           '00000000-0000-0000-0000-000000000000'
  System Identifier:         ''
  Generating Software:       'TerraScan'
  File Creation Day/Year:    0/0
  Header Size                227
  Offset to Point Data       229
  Number Var. Length Records 0
  Point Data Format          1
  Point Data Record Length   28
  Number of Point Records    213093
  Number of Points by Return 128621 84472 0 0 0
  Scale Factor X Y Z         0.01 0.01 0.01
  Offset X Y Z               -0.000000 -0.000000 -0.000000
  Min X Y Z                  630250.000000 4834500.000000 46.830000
  Max X Y Z                  630500.000000 4834750.000000 170.650000
 Spatial Reference
Geotiff_Information:
   Version: 1
   Key_Revision: 1.0
   Tagged_Information:
      End_Of_Tags.
   Keyed_Information:
      End_Of_Keys.
   End_Of_Geotiff.

---------------------------------------------------------
  Point Inspection Summary
---------------------------------------------------------
  Header Point Count: 213093
  Actual Point Count: 213093

  Minimum and Maximum Attributes (min,max)
---------------------------------------------------------
  Min X,Y,Z:        630250.000000,4834500.000000,46.830000
  Max X,Y,Z:        630500.000000,4834750.000000,170.650000
  Bounding Box:     630250.00,4834500.00,630500.00,4834750.00
  Time:         413162.560400,414095.322000
  Return Number:    1,2
  Return Count:     1,2
  Flightline Edge:  0,0
  Intensity:        10,50200
  Scan Direction Flag:  0,0
  Scan Angle Rank:  0,0
  Classification:   1,1
  Point Source Id:  0,0
  Minimum Color:     0 0 0
  Maximum Color:     0 0 0

  Number of Points by Return
---------------------------------------------------------
    (0) 128621  (1) 84472   (2) 0   (3) 0   (4) 0
 Total Points: 213093

  Number of Returns by Pulse
---------------------------------------------------------
    (1) 128621  (2) 84472   (3) 0   (4) 0   (5) 0   (6) 0   (7) 0
 Total Pulses: 213093

  Point Classifications
---------------------------------------------------------
      213093 Unclassified (1)

Configure your Optional Libraries.

By checking the “on” button for each, CMake may find your installations of these libraries, but in case it does not, set the following variables, substituting accordingly, to values that match your system layout.

GDAL GDAL_CONFIG /usr/local/bin/gdal-config
  GDAL_INCLUDE_DIR /usr/local/include
  GDAL_LIBRARY /usr/local/lib/libgdal.so
libgeotiff GEOTIFF_INCLUDE_DIR /usr/local/include
  GEOTIFF_LIBRARY /usr/local/lib/libgeotiff.so
OCI ORACLE_INCLUDE_DIR /home/oracle/sdk/include
  ORACLE_NNZ_LIBRARY /home/oracle/libnnz10.so
  ORACLE_OCCI_LIBRARY /home/oracle/libocci.so
  ORACLE_OCIEI_LIBRARY /home/oracle/libociei.so
  ORACLE_OCI_LIBRARY /home/oracle/libclntsh.so

CCMake and cmake-gui

While CMake can be run from the command-line, and this is the preferred way for many individuals, it can be much easier to run CMake from a GUI. Now that we have a basic library building, we will use CMake’s GUIs to help us configure the rest of the optional components of the library. Run ccmake ../ for the Curses interface or cmake-gui ../ for a GUI version.

Running CCMake in OS X

Running the Curses CMake interface. This interface is available to all unix-like operating systems.

Note

If your arrow keys are not working with in CCMake, use CTRL-N and CTRL-P to move back and forth between the options.

Running cmake-gui in OS X

Running the cmake-gui CMake interface. This interface is available on Linux, Windows, and Mac OS X.

Build and install

Once you have configured your additional libraries, you can install the software. The main pieces that will be installed are:

  • libLAS headers (typically in a location ./include/liblas/...)
  • libLAS C++ (liblas.a or liblas.so) library
  • libLAS C (liblas_c.a or liblas_c.so) library
  • Utility programs
make install

Using “XCode” on OS X

Get the source code

See libLAS Source Repository for how to obtain the latest development version or visit Download to get the latest released version.

Prepare a build directory

CMake allows you to generate different builders for a project, and in this example, we are going to generate an “Xcode” builder for libLAS on Mac OS X. Additionally, we’re going to use an alternative compiler – LLVM – which under certain situations can produce much faster code on Mac OS X.

$ export CC=/usr/bin/llvm-gcc
$ export CXX=/usr/bin/llvm-g++
$ cd liblas
$ mkdir xcode
$ cd xcode/

Configure base library

Configure the basic core library for the Xcode build:

$ cmake -G "Xcode" ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Check for working C compiler: /usr/bin/llvm-gcc
-- Check for working C compiler: /usr/bin/llvm-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Check for working CXX compiler: /usr/bin/llvm-g++
-- Check for working CXX compiler: /usr/bin/llvm-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Enable libLAS utilities to build - done
-- Enable libLAS unit tests to build - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/hobu/hg/liblas-cmake/xcode

Alternatively, if you have KyngChaos frameworks for GDAL and libgeotiff installed, you can provide locations for those as part of your cmake invocation:

$ cmake -G "Xcode" \
  -D GDAL_CONFIG=/Library/Frameworks/GDAL.framework/Programs/gdal-config \
  -D GEOTIFF_INCLUDE_DIR=/Library/Frameworks/UnixImageIO.framework/unix/include \
  -D GEOTIFF_LIBRARY=/Library/Frameworks/UnixImageIO.framework/unix/lib/libgeotiff.dylib \
  ..
$ open libLAS.xcodeproj/
Building libLAS using the XCode project

Set default command for XCode

Set the default executable for the project to be lasinfo by opening the “Executables” tree, choosing “lasinfo,” and clicking the bubble next to the “Executable name” in the right-hand panel.

Setting the default executable

Set arguments for lasinfo

Set the arguments for lasinfo so it can be run from within XCode. We use the ${PROJECT_DIR} environment variable to be able to tell lasinfo the location of our test file. This is similar to the same command above in the “Unix Makefiles” section.

Setting the arguments for lasinfo

Build and run the lasinfo command

Open the console by pressing CMD-SHIFT-R or by navigating to the Run-Console menu and press the Build and Run button.

lasinfo output in XCode

Configure Optional Libraries

As before, use ccmake ../ or cmake-gui ../ to configure your Optional libraries.

Configuring optional libraries with CMake GUI

Configuring Optional Libraries with CMake GUI

Using “Visual Studio 9 2008” on Windows

Get the source code

See libLAS Source Repository for how to obtain the latest development version or visit Download to get the latest released version.

Prerequisites

  • Ensure that you have CMake 2.8.0+ installed on your system.

  • Install OSGeo4W on your system to get Optional Libraries in pre-compiled form. You can build these from source yourself, but it is much more convenient to get them from OSGeo4W.

    • gdal-dev
    • libtiff
    • libgeotiff
    OSGeo4W installation

    Choose the “Advanced install” to be able to pick the libraries and their headers that you need.

    Choosing libraries

    Open up the “Libs” tree and choose the libraries you need

Run cmake-gui.exe

  • Run cmake-gui.exe from a “Visual Studio 2008 Command Prompt”
cd d:\\liblas
cmake-gui .
Starting CMake

Upon opening cmake-gui, nothing will be configured.

Note

The Visual Studio Prompt can be found by navigating through the start bar to “Start” – “Microsoft Visual Studio 2008” – “Visual Studio Tools ” – “Visual Studio 2008 Command Prompt”. This command prompt sets a number of environment variables necessary for Visual Studio to run, and CMake must have these variables set in order for it to work properly.

Visual Studio Command prompt
Generating a project
  • Click “Configure” and a window will pop up asking what type of build to generate. Choose “Visual Studio 9 2008.”
  • Click “Generate” and a “libLAS.sln” file will be in d:\\liblas
  • Open and build the project
_images/windows-msvc-build.png

Configure your Optional Libraries.

By checking the “on” button for each, CMake may find your installations of these libraries, but in case it does not, set the following variables, substituting accordingly, to values that match your system layout.

Note

If you are building using OSGeo4W libraries, you must use the “gdal-dev” version, not the base GDAL build. libLAS requires GDAL 1.7+ to operate, and this is provided by the “gdal-dev” OSGeo4W version.

Note

You will need to choose “Advanced View” and select the location of the libTIFF library explicitly.

GDAL GDAL_INCLUDE_DIR c:\osgeo4w\apps\gdal-dev\include
  GDAL_LIBRARY c:\osgeo4w\apps\gdal-dev\lib\gdal_i.lib
libgeotiff GEOTIFF_INCLUDE_DIR c:\osgeo4w\include
  GEOTIFF_LIBRARY c:\osgeo4w\lib\geotiff_i.lib
libtiff TIFF_INCLUDE_DIR c:\osgeo4w\include
  TIFF_LIBRARY c:\osgeo4w\lib\libtiff_i.lib