Add GEOSSTRtree_nearest API
[geos.git] / CMakeLists.txt
blobe4ebe0ba9f6c3eb58e807d818aa96c3643954854
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 "${PROJECT_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 6)
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.13.0)
37 message(STATUS "Setting GEOS version ${VERSION} as port of JTS ${JTS_PORT}")
39 # GEOS C API version
40 set(CAPI_INTERFACE_CURRENT 11)
41 set(CAPI_INTERFACE_REVISION 0)
42 set(CAPI_INTERFACE_AGE 10)
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(NOT (MSVC_VERSION LESS 1400)) # Visual Studio 2005 or later
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   endif()
140 endif()
142 if(GEOS_ENABLE_INLINE)
143   add_definitions(-DGEOS_INLINE)
144 endif()
145 message(STATUS
146   "Setting GEOS compilation with small functions inlining - ${GEOS_ENABLE_INLINE}")
148 if(NOT MSVC)
149   if(GEOS_ENABLE_ASSERT)
150     string(REGEX REPLACE "[-/]D.*NDEBUG" "-U NDEBUG"
151       CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
152   endif()
153   message(STATUS
154     "Setting GEOS compilation with assert() macro enabled - ${GEOS_ENABLE_ASSERT}")
155 endif()
157 #################################################################################
158 # Setup C/C++ library features
159 #################################################################################
161 # check header files
162 include(CheckIncludeFiles)
164 check_include_files(stdint.h HAVE_STDINT_H)
165 check_include_files(inttypes.h HAVE_INTTYPES_H)
166 check_include_files(ieeefp.h HAVE_IEEEFP_H)
168 # check types and sizes
169 include(CheckTypeSize)
171 if(MSVC)
172   check_type_size("__int64" HAVE_INT64_T_64)
173 else()
174   if(HAVE_STDINT_H OR HAVE_INTTYPES_H)
175     check_type_size("int64_t" HAVE_INT64_T_64)
176   else()
177     check_type_size("long long int" HAVE_LONG_LONG_INT_64)
178   endif()
179 endif()
181 # check functions and macros
182 include(CheckPrototypeExists)
183 include(CheckSymbolExists)
185 check_prototype_exists(isnan cmath HAVE_STD_ISNAN)
186 if(NOT HAVE_STD_ISNAN)
187   if(MSVC)
188     check_prototype_exists(_isnan float.h HAVE_ISNAN)
189   elseif(APPLE)
190     check_prototype_exists(__isnand math.h HAVE_ISNAND_XCODE)
191     if(NOT HAVE_ISNAND_XCODE)
192       check_prototype_exists(__inline_isnand math.h HAVE_INLINE_ISNAND_XCODE)
193     endif()
194   else()
195     check_symbol_exists(isnan math.h HAVE_ISNAN)
196   endif()
197 endif()
199 check_prototype_exists(isfinite cmath HAVE_STD_ISFINITE)
201 if(NOT HAVE_STD_ISFINITE)
202   if(MSVC)
203     check_prototype_exists(_finite float.h HAVE_FINITE)
204   else()
205     #CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
206     check_symbol_exists(isfinite math.h HAVE_ISFINITE)
207   endif()
208 endif()
210 ################################################################################
211 # Setup build directories
212 #################################################################################
214 # Put the libaries and binaries that get built into directories at the
215 # top of the build tree rather than in hard-to-find leaf
216 # directories. This simplifies manual testing and the use of the build
217 # tree rather than installed Boost libraries.
218 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
219 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
220 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
222 ################################################################################
223 # Setup include directories
224 #################################################################################
226 # for including GEOS C++ API headers
227 include_directories(${PROJECT_SOURCE_DIR}/include)
229 # for including build-specific GEOS C API headers
230 include_directories(${PROJECT_BINARY_DIR}/capi)
232 # for including build-specific version.h, platform.h and geos_c.h
233 include_directories(${PROJECT_BINARY_DIR}/include)
235 #################################################################################
236 # Setup checks and generate config headers
237 #################################################################################
239 #################################################################################
240 #  MACRO: GET_SVN_REVISION
241 #  
242 #  DESCRIPTION:
243 #      MACRO FOR GETTING THE SVN revision for this build
244 #################################################################################
245 MACRO (GET_SVN_REVISION)
246    FIND_PACKAGE(Subversion)
247    IF(SUBVERSION_FOUND)
248       Subversion_WC_INFO(${PROJECT_SOURCE_DIR} Project)
249       # MESSAGE("Current revision is ${Project_WC_REVISION}")
250       # Subversion_WC_LOG(${PROJECT_SOURCE_DIR} Project)
251       # MESSAGE("Last changed log is ${Project_LAST_CHANGED_LOG}")
252    ENDIF()
253 ENDMACRO(GET_SVN_REVISION)
255 # Determine SVN/Git revision
256 set(GEOS_BUILD_PACKAGED TRUE)
257 if(EXISTS "${PROJECT_SOURCE_DIR}/.svn")
258   set(GEOS_BUILD_PACKAGED FALSE)
259   GET_SVN_REVISION()
260 elseif(EXISTS "${PROJECT_SOURCE_DIR}/.git")
261   set(GEOS_BUILD_PACKAGED FALSE)
262 endif()
264 if (NOT GEOS_BUILD_PACKAGED)
265   message(STATUS "Generating GEOS revision header in ${PROJECT_BINARY_DIR}/geos_svn_revision.h")
266   if ( NOT ${Project_WC_REVISION} EQUAL 0 )
267      set( GEOS_SVN_REVISION ${Project_WC_REVISION} )
268      configure_file ( 
269         "${PROJECT_SOURCE_DIR}/tools/geos_svn_revision_cmake.h.in"
270         "${PROJECT_BINARY_DIR}/include/geos_svn_revision.h" )
271   else()
272      find_program(SH sh)
273      if(SH)
274         execute_process(COMMAND ${SH} -c 
275         "cd ${PROJECT_SOURCE_DIR} && ${PROJECT_SOURCE_DIR}/tools/svn_repo_revision.sh")
277         file(RENAME "${PROJECT_SOURCE_DIR}/geos_svn_revision.h"
278         "${PROJECT_BINARY_DIR}/geos_svn_revision.h")
279      else()
280         message("*** sh-compatible command not found, cannot create geos_svn_revision.h")
281         message("*** Check SVN revision and create revision header manually:")
282         message("*** echo '#define GEOS_SVN_REVISION XYZ' > ${PROJECT_SOURCE_DIR}/geos_svn_revision.h")
283      endif()
284   endif()
285 endif()
286 # End: Determine SVN/Git revision
288 if(EXISTS ${PROJECT_SOURCE_DIR}/include/geos/platform.h)
289   message(STATUS "Disabling existing ${PROJECT_SOURCE_DIR}/include/geos/platform.h")
291   if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
292     file(REMOVE ${PROJECT_SOURCE_DIR}/include/geos/platform.h)
293     set(PH_RESULT "removed")
294   else()
295     file(RENAME
296       ${PROJECT_SOURCE_DIR}/include/geos/platform.h
297       ${PROJECT_SOURCE_DIR}/include/geos/platform.h.disabled)
298       set(PH_RESULT "renamed")
299   endif()
301   message(STATUS "Disabling existing ${PROJECT_SOURCE_DIR}/include/geos/platform.h - ${PH_RESULT}")
302 endif()
304 message(STATUS "Generating GEOS ${PROJECT_BINARY_DIR}/include/geos/platform.h")
305 configure_file(${PROJECT_SOURCE_DIR}/include/geos/platform.h.cmake 
306   ${PROJECT_BINARY_DIR}/include/geos/platform.h)
308 message(STATUS "Generating GEOS ${PROJECT_BINARY_DIR}/include/geos/version.h")
309 configure_file(${PROJECT_SOURCE_DIR}/include/geos/version.h.in
310   ${PROJECT_BINARY_DIR}/include/geos/version.h @ONLY)
312 message(STATUS "Generating GEOS ${PROJECT_BINARY_DIR}/capi/geos_c.h")
313 configure_file(${PROJECT_SOURCE_DIR}/capi/geos_c.h.in
314   ${PROJECT_BINARY_DIR}/capi/geos_c.h @ONLY)
316 #################################################################################
317 # Configure tests
318 #################################################################################
320 if(GEOS_ENABLE_TESTS)
321   enable_testing()
322   # Define "make check" as alias for "make test"
323   add_custom_target(check COMMAND ctest)
324 endif()
326 #################################################################################
327 # Configure subdirectories
328 #################################################################################
329 include(GenerateSourceGroups)
331 add_subdirectory(include)
332 add_subdirectory(src)
333 add_subdirectory(capi)
334 add_subdirectory(tests)
335 add_subdirectory(tools)
337 #################################################################################
338 # Install/Uninstall
339 #################################################################################
341 configure_file("${PROJECT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
342   "${PROJECT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
343   IMMEDIATE @ONLY)
345 add_custom_target(uninstall
346   "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake/cmake_uninstall.cmake") 
348 #################################################################################
349 # DEBUG settings - TODO: make a summary
351 message(STATUS "CMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator")
353 #message(STATUS "XXX: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
354 #message(STATUS "XXX: CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}")
355 #message(STATUS "XXX: CMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}")