GEOSGeom_extractUniquePoints [RT-SIGTA]
[geos.git] / CMakeLists.txt
blob21a6c50fe9a383584cc9aec6854417d7e255c51d
1 #################################################################################
2 # $Id$
4 # Main GEOS build configuration file for CMake build system
6 # Copyright (C) 2009 Mateusz Loskot <mateusz@loskot.net>
8 # This is free software; you can redistribute and/or modify it under
9 # the terms of the GNU Lesser General Public Licence as published
10 # by the Free Software Foundation. 
11 # See the COPYING file for more information.
13 #################################################################################
14 project(geos)
15 cmake_minimum_required(VERSION 2.6)
17 if(NOT CMAKE_VERSION)
18     set(CMAKE_VERSION "${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 3)
32 set(VERSION_PATCH 0)
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.10.0)
37 message(STATUS "Setting GEOS version ${VERSION} as port of JTS ${JTS_PORT}")
39 # GEOS C API version
40 set(CAPI_INTERFACE_CURRENT 7)
41 set(CAPI_INTERFACE_REVISION 1)
42 set(CAPI_INTERFACE_AGE 6)
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}")
50 #################################################################################
51 # Check custom global options
52 #################################################################################
54 option(GEOS_ENABLE_TESTS
55   "Set to OFF|ON (default) to control build of GEOS tests package" ON)
57 option(GEOS_ENABLE_INLINE
58   "Set to OFF|ON (default) to control GEOS compilation with small functions inlining" ON)
60 if(NOT MSVC)
61   option(GEOS_ENABLE_ASSERT
62     "Set to ON|OFF (default) to build GEOS with assert() macro enabled" OFF) 
63 endif()
65 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
66   option(GEOS_ENABLE_FLOATSTORE
67     "Set to OFF|ON (default) to control IEEE754 conformance and remove extra precision" ON)
68 endif()
70 #################################################################################
71 # Setup C/C++ compiler options
72 #################################################################################
74 if(NOT CMAKE_BUILD_TYPE)
75   set(CMAKE_BUILD_TYPE Debug CACHE STRING
76       "Choose the type of build, options are: None Debug Release" FORCE)
77 endif()
78 message(STATUS "Setting GEOS build type - ${CMAKE_BUILD_TYPE}")
80 if(CMAKE_BUILD_TYPE STREQUAL Debug)
81   add_definitions(-D_DEBUG)
82 endif()
84 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
86   # General options
87   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -ansi")
89   # Numerical stability
90   if(GEOS_ENABLE_FLOATSTORE)
91     # Remove extra precision by forcing conformance to IEEE 754 rather than IEEE 854
92     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffloat-store")
93   endif()
94   message(STATUS
95     "Forcing IEEE 754 using flag -ffloat-store - ${GEOS_ENABLE_FLOATSTORE}")
97   # Warnings specification
98   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long")
100   # Turn on Position Independent Code generation for GEOS C shared library
101   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
103   # Enable glibc ISO C99 features (macros isfinite, isnan)
104   set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_ISOC99_SOURCE=1")
106 elseif(MSVC)
107     
108   # Set pedantic mode by default
109   #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
110   string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
111   message(STATUS "Z: ${CMAKE_CXX_FLAGS}")
113   if(MSVC80 OR MSVC90 OR MSVC10)
115     # Option is to enable the /MP switch for Visual Studio 2005 or later
116     option(GEOS_MSVC_ENABLE_MP
117       "Set to ON to build GEOS with the /MP option (Visual Studio 2005 and above)." ON)
118     mark_as_advanced(GEOS_MSVC_ENABLE_MP)
119     if(GEOS_MSVC_ENABLE_MP)
120       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
121     endif()
122     message(STATUS "Setting Visual Studio 2005+ option /MP to ${GEOS_MSVC_ENABLE_MP}")
123     
124     # Disable C4996: 'function': was declared deprecated
125     add_definitions(-D_SCL_SECURE_NO_WARNINGS)
126     add_definitions(-D_CRT_SECURE_NO_WARNINGS)
127   endif()
129 endif()
131 if(GEOS_ENABLE_INLINE)
132   add_definitions(-DGEOS_INLINE)
133 endif()
134 message(STATUS
135   "Setting GEOS compilation with small functions inlining - ${GEOS_ENABLE_INLINE}")
137 if(NOT MSVC)
138   if(GEOS_ENABLE_ASSERT)
139     string(REGEX REPLACE "[-/]D.*NDEBUG" "-U NDEBUG"
140       CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
141   endif()
142   message(STATUS
143     "Setting GEOS compilation with assert() macro enabled - ${GEOS_ENABLE_ASSERT}")
144 endif()
146 #################################################################################
147 # Setup C/C++ library features
148 #################################################################################
150 include(TestForSTDNamespace)
151 if (CMAKE_NO_STD_NAMESPACE)
152   message(FATAL_ERROR "Detected compiler does not support std namespace on STL classes")
153 endif()
155 # check header files
156 include(CheckIncludeFiles)
158 check_include_files(stdint.h HAVE_STDINT_H)
159 check_include_files(inttypes.h HAVE_INTTYPES_H)
160 check_include_files(ieeefp.h HAVE_IEEEFP_H)
162 # check types and sizes
163 include(CheckTypeSize)
165 if(MSVC)
166   check_type_size("__int64" HAVE_INT64_T_64)
167 else()
168   if(HAVE_STDINT_H OR HAVE_INTTYPES_H)
169     check_type_size("int64_t" HAVE_INT64_T_64)
170   else()
171     check_type_size("long long int" HAVE_LONG_LONG_INT_64)
172   endif()
173 endif()
175 # check functions and macros
176 include(CheckPrototypeExists)
177 include(CheckSymbolExists)
179 check_prototype_exists(isnan cmath HAVE_STD_ISNAN)
180 if(NOT HAVE_STD_ISNAN)
181   if(MSVC)
182     check_prototype_exists(_isnan float.h HAVE_ISNAN)
183   elseif(APPLE)
184     check_prototype_exists(__isnand math.h HAVE_ISNAND_XCODE)
185     if(NOT HAVE_ISNAND_XCODE)
186       check_prototype_exists(__inline_isnand math.h HAVE_INLINE_ISNAND_XCODE)
187     endif()
188   else()
189     check_symbol_exists(isnan math.h HAVE_ISNAN)
190   endif()
191 endif()
193 check_prototype_exists(isfinite cmath HAVE_STD_ISFINITE)
195 if(NOT HAVE_STD_ISFINITE)
196   if(MSVC)
197     check_prototype_exists(_finite float.h HAVE_FINITE)
198   else()
199     #CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
200     check_symbol_exists(isfinite math.h HAVE_ISFINITE)
201   endif()
202 endif()
204 ################################################################################
205 # Setup include directories
206 #################################################################################
208 # for including GEOS C++ API headers
209 include_directories(${CMAKE_SOURCE_DIR}/include)
211 # for including build-specific GEOS C API headers
212 include_directories(${CMAKE_BINARY_DIR}/capi)
214 # for including build-specific version.h, platform.h and geos_c.h
215 include_directories(${CMAKE_BINARY_DIR}/include)
217 #################################################################################
218 # Setup checks and generate config headers
219 #################################################################################
221 # TODO: output to CMAKE_CURRENT_BINARY_DIR instead of CMAKE_SOURCE_DIR
223 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
224   message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h")
226   if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
227     file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
228     set(PH_RESULT "removed")
229   else()
230     file(RENAME
231       ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h
232       ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.disabled)
233       set(PH_RESULT "renamed")
234   endif()
236   message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h - ${PH_RESULT}")
237 endif()
239 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.cmake 
240   ${CMAKE_CURRENT_BINARY_DIR}/include/geos/platform.h)
242 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/version.h.in
243   ${CMAKE_CURRENT_BINARY_DIR}/include/geos/version.h @ONLY)
245 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/capi/geos_c.h.in
246   ${CMAKE_CURRENT_BINARY_DIR}/capi/geos_c.h @ONLY)
248 #################################################################################
249 # Configure tests
250 #################################################################################
252 if(GEOS_ENABLE_TESTS)
254  # Include CTest support
255  include(CTest)
256  enable_testing()
258   # Define "make check" as alias for "make test"
259   add_custom_target(check COMMAND ctest)
261 endif()
263 #################################################################################
264 # Configure subdirectories
265 #################################################################################
267 add_subdirectory(include)
268 add_subdirectory(src)
269 add_subdirectory(capi)
270 add_subdirectory(tests)
271 add_subdirectory(tools)
273 #################################################################################
274 # Setup installation of common files not specific to any target
277 #################################################################################
278 # DEBUG settings - TODO: make a summary
280 message(STATUS "CMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator")
282 #message(STATUS "XXX: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
283 #message(STATUS "XXX: CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}")
284 #message(STATUS "XXX: CMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}")