Assert that the variable used as array index is not negative before using it.
[geos.git] / CMakeLists.txt
blob90b38aa1e6cfc9519eb57bed6dbe688a5991dc0d
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
19       "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
20 endif()
22 # Location of custom CMake modules with macros used by GEOS
23 set(CMAKE_MODULE_PATH "${geos_SOURCE_DIR}/cmake/modules")
25 #################################################################################
26 # Setup GEOS version
27 #################################################################################
29 # GEOS release version
30 # GEOS C++ library SONAME will use these encoding ABI break at every release
31 set(VERSION_MAJOR 3)
32 set(VERSION_MINOR 3)
33 set(VERSION_PATCH 0)
34 set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
36 # JTS_PORT is the version of JTS this release is bound to
37 set(JTS_PORT 1.10.0)
38 message(STATUS "Setting GEOS version ${VERSION} as port of JTS ${JTS_PORT}")
40 # GEOS C API version
41 set(CAPI_INTERFACE_CURRENT 7)
42 set(CAPI_INTERFACE_REVISION 1)
43 set(CAPI_INTERFACE_AGE 6)
45 math(EXPR CAPI_VERSION_MAJOR "${CAPI_INTERFACE_CURRENT} - ${CAPI_INTERFACE_AGE}")
46 set(CAPI_VERSION_MINOR ${CAPI_INTERFACE_AGE})
47 set(CAPI_VERSION_PATCH ${CAPI_INTERFACE_REVISION})
48 set(CAPI_VERSION "${CAPI_VERSION_MAJOR}.${CAPI_VERSION_MINOR}.${CAPI_VERSION_PATCH}")
49 message(STATUS "Setting GEOS C API version ${CAPI_VERSION}")
51 #################################################################################
52 # Check custom global options
53 #################################################################################
55 option(GEOS_ENABLE_TESTS
56   "Set to OFF|ON (default) to control build of GEOS tests package" ON)
58 option(GEOS_ENABLE_INLINE
59   "Set to OFF|ON (default) to control GEOS compilation with small functions inlining" ON)
61 if(NOT MSVC)
62   option(GEOS_ENABLE_ASSERT
63     "Set to ON|OFF (default) to build GEOS with assert() macro enabled" OFF) 
64 endif()
66 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
67   option(GEOS_ENABLE_FLOATSTORE
68     "Set to OFF|ON (default) to control IEEE754 conformance and remove extra precision" ON)
69 endif()
71 if(APPLE)
72   option(GEOS_ENABLE_MACOSX_FRAMEWORK
73     "Set to OFF|ON (default) to build GEOS as a Mac OS X framework" ON)
74   option(GEOS_ENABLE_MACOSX_FRAMEWORK_UNIXCOMPAT
75     "Set to ON|OFF (default) to add Unix compatibility to the Mac OS X framework" OFF)
76 endif()
78 #################################################################################
79 # Setup C/C++ compiler options
80 #################################################################################
82 if(NOT MSVC_IDE)
83   if(NOT CMAKE_BUILD_TYPE)
84     set(CMAKE_BUILD_TYPE Debug CACHE STRING
85       "Choose the type of build, options are: None Debug Release" FORCE)
86   endif()
87   message(STATUS "Setting GEOS build type - ${CMAKE_BUILD_TYPE}")
88 endif()
90 if(CMAKE_BUILD_TYPE STREQUAL Debug)
91   add_definitions(-D_DEBUG)
92 endif()
94 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
96   # General options
97   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -ansi")
99   # Numerical stability
100   if(GEOS_ENABLE_FLOATSTORE)
101     # Remove extra precision by forcing conformance to IEEE 754 rather than IEEE 854
102     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffloat-store")
103   endif()
104   message(STATUS
105     "Forcing IEEE 754 using flag -ffloat-store - ${GEOS_ENABLE_FLOATSTORE}")
107   # Warnings specification
108   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long")
110   # Turn on Position Independent Code generation for GEOS C shared library
111   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
113   # Enable glibc ISO C99 features (macros isfinite, isnan)
114   set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_ISOC99_SOURCE=1")
116 elseif(MSVC)
117     
118   # Set pedantic mode by default
119   #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
120   string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
122   if(MSVC80 OR MSVC90 OR MSVC10)
124     # Option is to enable the /MP switch for Visual Studio 2005 or later
125     option(GEOS_MSVC_ENABLE_MP
126       "Set to ON to build GEOS with the /MP option (Visual Studio 2005 and above)." ON)
127     mark_as_advanced(GEOS_MSVC_ENABLE_MP)
128     if(GEOS_MSVC_ENABLE_MP)
129       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
130     endif()
131     message(STATUS "Setting Visual Studio 2005+ option /MP to ${GEOS_MSVC_ENABLE_MP}")
132     
133     add_definitions(-D_SCL_SECURE_NO_WARNINGS)
134     add_definitions(-D_CRT_SECURE_NO_WARNINGS)
135     add_definitions(-DNOMINMAX)
136   endif()
138 endif()
140 if(GEOS_ENABLE_INLINE)
141   add_definitions(-DGEOS_INLINE)
142 endif()
143 message(STATUS
144   "Setting GEOS compilation with small functions inlining - ${GEOS_ENABLE_INLINE}")
146 if(NOT MSVC)
147   if(GEOS_ENABLE_ASSERT)
148     string(REGEX REPLACE "[-/]D.*NDEBUG" "-U NDEBUG"
149       CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
150   endif()
151   message(STATUS
152     "Setting GEOS compilation with assert() macro enabled - ${GEOS_ENABLE_ASSERT}")
153 endif()
155 #################################################################################
156 # Setup C/C++ library features
157 #################################################################################
159 include(TestForSTDNamespace)
160 if (CMAKE_NO_STD_NAMESPACE)
161   message(FATAL_ERROR "Detected compiler does not support std namespace on STL classes")
162 endif()
164 # check header files
165 include(CheckIncludeFiles)
167 check_include_files(stdint.h HAVE_STDINT_H)
168 check_include_files(inttypes.h HAVE_INTTYPES_H)
169 check_include_files(ieeefp.h HAVE_IEEEFP_H)
171 # check types and sizes
172 include(CheckTypeSize)
174 if(MSVC)
175   check_type_size("__int64" HAVE_INT64_T_64)
176 else()
177   if(HAVE_STDINT_H OR HAVE_INTTYPES_H)
178     check_type_size("int64_t" HAVE_INT64_T_64)
179   else()
180     check_type_size("long long int" HAVE_LONG_LONG_INT_64)
181   endif()
182 endif()
184 # check functions and macros
185 include(CheckPrototypeExists)
186 include(CheckSymbolExists)
188 check_prototype_exists(isnan cmath HAVE_STD_ISNAN)
189 if(NOT HAVE_STD_ISNAN)
190   if(MSVC)
191     check_prototype_exists(_isnan float.h HAVE_ISNAN)
192   elseif(APPLE)
193     check_prototype_exists(__isnand math.h HAVE_ISNAND_XCODE)
194     if(NOT HAVE_ISNAND_XCODE)
195       check_prototype_exists(__inline_isnand math.h HAVE_INLINE_ISNAND_XCODE)
196     endif()
197   else()
198     check_symbol_exists(isnan math.h HAVE_ISNAN)
199   endif()
200 endif()
202 check_prototype_exists(isfinite cmath HAVE_STD_ISFINITE)
204 if(NOT HAVE_STD_ISFINITE)
205   if(MSVC)
206     check_prototype_exists(_finite float.h HAVE_FINITE)
207   else()
208     #CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
209     check_symbol_exists(isfinite math.h HAVE_ISFINITE)
210   endif()
211 endif()
213 ################################################################################
214 # Setup build directories
215 #################################################################################
217 # Put the libaries and binaries that get built into directories at the
218 # top of the build tree rather than in hard-to-find leaf
219 # directories. This simplifies manual testing and the use of the build
220 # tree rather than installed Boost libraries.
221 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
222 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
223 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
225 ################################################################################
226 # Setup include directories
227 #################################################################################
229 # for including GEOS C++ API headers
230 include_directories(${geos_SOURCE_DIR}/include)
232 # for including build-specific GEOS C API headers
233 include_directories(${geos_BINARY_DIR}/capi)
235 # for including build-specific version.h, platform.h and geos_c.h
236 include_directories(${geos_BINARY_DIR}/include)
238 #################################################################################
239 # Setup checks and generate config headers
240 #################################################################################
242 # TODO: output to CMAKE_CURRENT_BINARY_DIR instead of CMAKE_SOURCE_DIR
244 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
245   message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h")
247   if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
248     file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
249     set(PH_RESULT "removed")
250   else()
251     file(RENAME
252       ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h
253       ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.disabled)
254       set(PH_RESULT "renamed")
255   endif()
257   message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h - ${PH_RESULT}")
258 endif()
260 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.cmake 
261   ${CMAKE_CURRENT_BINARY_DIR}/include/geos/platform.h)
263 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/version.h.in
264   ${CMAKE_CURRENT_BINARY_DIR}/include/geos/version.h @ONLY)
266 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/capi/geos_c.h.in
267   ${CMAKE_CURRENT_BINARY_DIR}/capi/geos_c.h @ONLY)
269 #################################################################################
270 # Configure tests
271 #################################################################################
273 if(GEOS_ENABLE_TESTS)
275  # Include CTest support
276  include(CTest)
277  enable_testing()
279   # Define "make check" as alias for "make test"
280   add_custom_target(check COMMAND ctest)
282 endif()
284 #################################################################################
285 # Configure subdirectories
286 #################################################################################
288 add_subdirectory(include)
289 add_subdirectory(src)
290 add_subdirectory(capi)
291 add_subdirectory(tests)
292 add_subdirectory(tools)
294 #################################################################################
295 # Install/Uninstall
296 #################################################################################
298 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
299   "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
300   IMMEDIATE @ONLY)
302 add_custom_target(uninstall
303   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake") 
305 #################################################################################
306 # DEBUG settings - TODO: make a summary
308 message(STATUS "CMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator")
310 #message(STATUS "XXX: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
311 #message(STATUS "XXX: CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}")
312 #message(STATUS "XXX: CMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}")