Status Notice
The CMake build system is the only one supported in GEOS versions 3.10 and after. It is available in GEOS versions 3.5 and after.
The CMake configuration for GEOS was introduced shortly after the GEOS 3.2.0 release (ticket #317). GEOS versions prior to 3.5 used GNU Automake as the only supported build system.
Building on Unix with CMake
This article describes how to use the CMake build system to build and install GEOS on Unix-like systems (Linux, Mac OS X, Solaris, *BSD, etc.) using GCC or any other supported compiler.
There are two ways of running CMake:
- cmake - CLI program accepting options or running in interactive mode
- ccmake - program with curses-based GUI
Requirements
- CMake 3.1 or later
- Decent C++ compiler and C++ Standard Library, GNU GCC 4.x or later recommended
- GEOS source code.
Configure
It is recommended to build GEOS outside of the source code tree. To do this, use a build
directory beside the source directory geos
(from now on referred to as BUILDDIR):
$ git clone https://git.osgeo.org/gitea/geos/geos.git $ mkdir build $ ls build geos $ cd build $ cmake ../geos $ make help
CMake variables are used to control aspects of compilation and installation. They are specified on the cmake
cmdline as -DVAR=VALUE
.
NOTE: Running
cmake
with no variables does NOT clear current variable settings. They must be set explicitly on the cmdline or interactively usingccmake .
. To revert to defaults thebuild
directory can be cleared usingrm -rf *
Useful CMake variables
CMAKE_INSTALL_PREFIX
- by default is set to /usr/local directoryCMAKE_BUILD_TYPE
- Values areRelease
orDebug
(which is useful for debugging)
CMake variables specific to GEOS
GEOS_ENABLE_TESTS
- Set to OFF|ON (default) to control build of GEOS tests packageGEOS_ENABLE_INLINE
- Set to OFF|ON (default) to control GEOS compilation with small functions inliningGEOS_ENABLE_ASSERT
- Set to ON|OFF (default) to build GEOS with assert() macro enabled (not available for Visual C++ compiler)GEOS_ENABLE_MACOSX_FRAMEWORK
- Set to ON|OFF (default) to build a Mac OS X frameworkGEOS_ENABLE_MACOSX_FRAMEWORK_UNIXCOMPAT
- Set to ON|OFF (default) to add compatibility with *nix library linking to the Mac OS X framework-DDISABLE_OVERLAYNG=NO
- Set to NO|YES (default) to enable OverlayNG use in Geometry overlay methods. (Note: as of GEOS 3.9 OverlayNG is the default)
Examples:
$ cmake ../geos -DGEOS_ENABLE_TESTS=ON -DGEOS_ENABLE_INLINE=OFF $ cmake ../geos -DCMAKE_BUILD_TYPE=Debug $ cmake ../geos -DCMAKE_BUILD_TYPE=Release
Note: when building a Mac OS X framework, you must specify the CMAKE_INSTALL_PREFIX. The default is /usr/local, and frameworks don't go there.
-DCMAKE_INSTALL_PREFIX=/Library/Frameworks
View / Change Variables via GUI
Use ccmake .
to interactively confirm or change variables
Build
To build, run make
in BUILDDIR:
$ make
This creates:
- GEOS C++ and C libraries in
lib
- Testing executables in
bin
Test
Under CMake testing is performed by CTest.
After building, tests can be executed in BUILDDIR. Natively, CMake uses a target named test:
$ make test
For convenience an Autotools-like check
target is available:
$ make check
It is possible to run ctest
directly. This gives access to ctest command line options (see ctest --help for a listing).
$ ctest $ ctest --verbose
A list of GEOS test suites is obtained by running ctest --show-only
:
$ ctest --show-only # # Test project /home/dan/dev/libgeos/cmake-build-debug # Test #1: test_geos_unit # Test #2: test_xmltester # Test #3: test_bug234 # Test #4: test_sweep_line_speed
A subset of test suites can be run using a regular expression (and in this case, running 4 jobs in parallel):
$ ctest --tests-regex test_ --parallel 4
Individual test classes within the test_geos_unit suite can be run by running test_geos_unit
with the name of the test group.
The test group name is found in the cpp file in the group
declaration.
$ bin/test_geos_unit capi::GEOSNode
Individual tests within a test class can be run by specifying the test number:
$ bin/test_geos_unit capi::GEOSNode 1
There are additional tests (typically for performance) which are built, but not run as part of the standard test suite. These can be run from the command line:
$ bin/perf_iterated_buffer
Install
To install both C and C++ API libraries as well as headers, in BUILDDIR run:
$ make install
Uninstall
In BUILDDIR run:
$ make uninstall
Open Tickets
- #935
- incorrect cmake instruction