Add note about BufferOp robustness improvement
[geos.git] / CMakeLists.txt
blob8871e3ea964002612c724663387d5306790c2223
1 #################################################################################
3 # Main GEOS build configuration file for CMake build system
5 # Copyright (C) 2009 Mateusz Loskot <mateusz@loskot.net>
7 # This is free software; you can redistribute and/or modify it under
8 # the terms of the GNU Lesser General Public Licence as published
9 # by the Free Software Foundation. 
10 # See the COPYING file for more information.
12 #################################################################################
13 project(geos)
14 cmake_minimum_required(VERSION 2.6)
16 if(NOT CMAKE_VERSION)
17     set(CMAKE_VERSION
18       "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
19 endif()
21 # Location of custom CMake modules with macros used by GEOS
22 set(CMAKE_MODULE_PATH "${geos_SOURCE_DIR}/cmake/modules")
24 #################################################################################
25 # Setup GEOS version
26 #################################################################################
28 # GEOS release version
29 # GEOS C++ library SONAME will use these encoding ABI break at every release
30 set(VERSION_MAJOR 3)
31 set(VERSION_MINOR 4)
32 set(VERSION_PATCH 0dev)
33 set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
35 # JTS_PORT is the version of JTS this release is bound to
36 set(JTS_PORT 1.12.0)
37 message(STATUS "Setting GEOS version ${VERSION} as port of JTS ${JTS_PORT}")
39 # GEOS C API version
40 set(CAPI_INTERFACE_CURRENT 9)
41 set(CAPI_INTERFACE_REVISION 0)
42 set(CAPI_INTERFACE_AGE 8)
44 math(EXPR CAPI_VERSION_MAJOR "${CAPI_INTERFACE_CURRENT} - ${CAPI_INTERFACE_AGE}")
45 set(CAPI_VERSION_MINOR ${CAPI_INTERFACE_AGE})
46 set(CAPI_VERSION_PATCH ${CAPI_INTERFACE_REVISION})
47 set(CAPI_VERSION "${CAPI_VERSION_MAJOR}.${CAPI_VERSION_MINOR}.${CAPI_VERSION_PATCH}")
48 message(STATUS "Setting GEOS C API version ${CAPI_VERSION}")
49 if (NOT WIN32)
50   set(CAPI_SOVERSION ${CAPI_VERSION_MAJOR})
51   message(STATUS "Setting GEOS C API soversion ${CAPI_SOVERSION}")
52 endif()
54 #################################################################################
55 # Check custom global options
56 #################################################################################
58 option(GEOS_ENABLE_TESTS
59   "Set to OFF|ON (default) to control build of GEOS tests package" ON)
61 option(GEOS_ENABLE_INLINE
62   "Set to OFF|ON (default) to control GEOS compilation with small functions inlining" ON)
64 if(NOT MSVC)
65   option(GEOS_ENABLE_ASSERT
66     "Set to ON|OFF (default) to build GEOS with assert() macro enabled" OFF) 
67 endif()
69 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
70   option(GEOS_ENABLE_FLOATSTORE
71     "Set to OFF|ON (default) to control IEEE754 conformance and remove extra precision" ON)
72 endif()
74 if(APPLE)
75   option(GEOS_ENABLE_MACOSX_FRAMEWORK
76     "Set to ON|OFF (default) to build GEOS as a Mac OS X framework" OFF)
77   option(GEOS_ENABLE_MACOSX_FRAMEWORK_UNIXCOMPAT
78     "Set to ON|OFF (default) to add Unix compatibility to the Mac OS X framework" OFF)
79 endif()
81 #################################################################################
82 # Setup C/C++ compiler options
83 #################################################################################
85 if(NOT MSVC_IDE)
86   if(NOT CMAKE_BUILD_TYPE)
87     set(CMAKE_BUILD_TYPE Debug CACHE STRING
88       "Choose the type of build, options are: None Debug Release" FORCE)
89   endif()
90   message(STATUS "Setting GEOS build type - ${CMAKE_BUILD_TYPE}")
91 endif()
93 if(CMAKE_BUILD_TYPE STREQUAL Debug)
94   add_definitions(-D_DEBUG)
95 endif()
97 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
99   # General options
100   set(CMAKE_CXX_FLAGS "-pedantic -ansi ${CMAKE_CXX_FLAGS}")
102   # Numerical stability
103   if(GEOS_ENABLE_FLOATSTORE)
104     # Remove extra precision by forcing conformance to IEEE 754 rather than IEEE 854
105     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffloat-store")
106   endif()
107   message(STATUS
108     "Forcing IEEE 754 using flag -ffloat-store - ${GEOS_ENABLE_FLOATSTORE}")
110   # Warnings specification
111   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long")
113   # Turn on Position Independent Code generation for GEOS C shared library
114   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
116   # Enable glibc ISO C99 features (macros isfinite, isnan)
117   set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_ISOC99_SOURCE=1")
119 elseif(MSVC)
120     
121   # Set pedantic mode by default
122   #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
123   string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
125   if(MSVC80 OR MSVC90 OR MSVC10)
127     # Option is to enable the /MP switch for Visual Studio 2005 or later
128     option(GEOS_MSVC_ENABLE_MP
129       "Set to ON to build GEOS with the /MP option (Visual Studio 2005 and above)." ON)
130     mark_as_advanced(GEOS_MSVC_ENABLE_MP)
131     if(GEOS_MSVC_ENABLE_MP)
132       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
133     endif()
134     message(STATUS "Setting Visual Studio 2005+ option /MP to ${GEOS_MSVC_ENABLE_MP}")
135     
136     add_definitions(-D_SCL_SECURE_NO_WARNINGS)
137     add_definitions(-D_CRT_SECURE_NO_WARNINGS)
138     add_definitions(-DNOMINMAX)
139   endif()
141 endif()
143 if(GEOS_ENABLE_INLINE)
144   add_definitions(-DGEOS_INLINE)
145 endif()
146 message(STATUS
147   "Setting GEOS compilation with small functions inlining - ${GEOS_ENABLE_INLINE}")
149 if(NOT MSVC)
150   if(GEOS_ENABLE_ASSERT)
151     string(REGEX REPLACE "[-/]D.*NDEBUG" "-U NDEBUG"
152       CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
153   endif()
154   message(STATUS
155     "Setting GEOS compilation with assert() macro enabled - ${GEOS_ENABLE_ASSERT}")
156 endif()
158 #################################################################################
159 # Setup C/C++ library features
160 #################################################################################
162 # check header files
163 include(CheckIncludeFiles)
165 check_include_files(stdint.h HAVE_STDINT_H)
166 check_include_files(inttypes.h HAVE_INTTYPES_H)
167 check_include_files(ieeefp.h HAVE_IEEEFP_H)
169 # check types and sizes
170 include(CheckTypeSize)
172 if(MSVC)
173   check_type_size("__int64" HAVE_INT64_T_64)
174 else()
175   if(HAVE_STDINT_H OR HAVE_INTTYPES_H)
176     check_type_size("int64_t" HAVE_INT64_T_64)
177   else()
178     check_type_size("long long int" HAVE_LONG_LONG_INT_64)
179   endif()
180 endif()
182 # check functions and macros
183 include(CheckPrototypeExists)
184 include(CheckSymbolExists)
186 check_prototype_exists(isnan cmath HAVE_STD_ISNAN)
187 if(NOT HAVE_STD_ISNAN)
188   if(MSVC)
189     check_prototype_exists(_isnan float.h HAVE_ISNAN)
190   elseif(APPLE)
191     check_prototype_exists(__isnand math.h HAVE_ISNAND_XCODE)
192     if(NOT HAVE_ISNAND_XCODE)
193       check_prototype_exists(__inline_isnand math.h HAVE_INLINE_ISNAND_XCODE)
194     endif()
195   else()
196     check_symbol_exists(isnan math.h HAVE_ISNAN)
197   endif()
198 endif()
200 check_prototype_exists(isfinite cmath HAVE_STD_ISFINITE)
202 if(NOT HAVE_STD_ISFINITE)
203   if(MSVC)
204     check_prototype_exists(_finite float.h HAVE_FINITE)
205   else()
206     #CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
207     check_symbol_exists(isfinite math.h HAVE_ISFINITE)
208   endif()
209 endif()
211 ################################################################################
212 # Setup build directories
213 #################################################################################
215 # Put the libaries and binaries that get built into directories at the
216 # top of the build tree rather than in hard-to-find leaf
217 # directories. This simplifies manual testing and the use of the build
218 # tree rather than installed Boost libraries.
219 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
220 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
221 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
223 ################################################################################
224 # Setup include directories
225 #################################################################################
227 # for including GEOS C++ API headers
228 include_directories(${geos_SOURCE_DIR}/include)
230 # for including build-specific GEOS C API headers
231 include_directories(${geos_BINARY_DIR}/capi)
233 # for including build-specific version.h, platform.h and geos_c.h
234 include_directories(${geos_BINARY_DIR}/include)
236 #################################################################################
237 # Setup checks and generate config headers
238 #################################################################################
240 # TODO: output to CMAKE_CURRENT_BINARY_DIR instead of CMAKE_SOURCE_DIR
242 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
243   message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h")
245   if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
246     file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
247     set(PH_RESULT "removed")
248   else()
249     file(RENAME
250       ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h
251       ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.disabled)
252       set(PH_RESULT "renamed")
253   endif()
255   message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h - ${PH_RESULT}")
256 endif()
258 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.cmake 
259   ${CMAKE_CURRENT_BINARY_DIR}/include/geos/platform.h)
261 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/version.h.in
262   ${CMAKE_CURRENT_BINARY_DIR}/include/geos/version.h @ONLY)
264 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/capi/geos_c.h.in
265   ${CMAKE_CURRENT_BINARY_DIR}/capi/geos_c.h @ONLY)
267 #################################################################################
268 # Configure tests
269 #################################################################################
271 if(GEOS_ENABLE_TESTS)
273  # Include CTest support
274  include(CTest)
275  enable_testing()
277   # Define "make check" as alias for "make test"
278   add_custom_target(check COMMAND ctest)
280 endif()
282 #################################################################################
283 # Configure subdirectories
284 #################################################################################
286 add_subdirectory(include)
287 add_subdirectory(src)
288 add_subdirectory(capi)
289 add_subdirectory(tests)
290 add_subdirectory(tools)
292 #################################################################################
293 # Install/Uninstall
294 #################################################################################
296 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
297   "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
298   IMMEDIATE @ONLY)
300 add_custom_target(uninstall
301   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake") 
303 #################################################################################
304 # DEBUG settings - TODO: make a summary
306 message(STATUS "CMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator")
308 #message(STATUS "XXX: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
309 #message(STATUS "XXX: CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}")
310 #message(STATUS "XXX: CMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}")