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 #################################################################################
14 cmake_minimum_required(VERSION 2.6)
18 "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
21 # Location of custom CMake modules with macros used by GEOS
22 set(CMAKE_MODULE_PATH "${geos_SOURCE_DIR}/cmake/modules")
24 #################################################################################
26 #################################################################################
28 # GEOS release version
29 # GEOS C++ library SONAME will use these encoding ABI break at every release
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
37 message(STATUS "Setting GEOS version ${VERSION} as port of JTS ${JTS_PORT}")
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}")
50 set(CAPI_SOVERSION ${CAPI_VERSION_MAJOR})
51 message(STATUS "Setting GEOS C API soversion ${CAPI_SOVERSION}")
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)
65 option(GEOS_ENABLE_ASSERT
66 "Set to ON|OFF (default) to build GEOS with assert() macro enabled" OFF)
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)
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)
81 #################################################################################
82 # Setup C/C++ compiler options
83 #################################################################################
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)
90 message(STATUS "Setting GEOS build type - ${CMAKE_BUILD_TYPE}")
93 if(CMAKE_BUILD_TYPE STREQUAL Debug)
94 add_definitions(-D_DEBUG)
97 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
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")
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")
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")
134 message(STATUS "Setting Visual Studio 2005+ option /MP to ${GEOS_MSVC_ENABLE_MP}")
136 add_definitions(-D_SCL_SECURE_NO_WARNINGS)
137 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
138 add_definitions(-DNOMINMAX)
143 if(GEOS_ENABLE_INLINE)
144 add_definitions(-DGEOS_INLINE)
147 "Setting GEOS compilation with small functions inlining - ${GEOS_ENABLE_INLINE}")
150 if(GEOS_ENABLE_ASSERT)
151 string(REGEX REPLACE "[-/]D.*NDEBUG" "-U NDEBUG"
152 CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
155 "Setting GEOS compilation with assert() macro enabled - ${GEOS_ENABLE_ASSERT}")
158 #################################################################################
159 # Setup C/C++ library features
160 #################################################################################
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)
173 check_type_size("__int64" HAVE_INT64_T_64)
175 if(HAVE_STDINT_H OR HAVE_INTTYPES_H)
176 check_type_size("int64_t" HAVE_INT64_T_64)
178 check_type_size("long long int" HAVE_LONG_LONG_INT_64)
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)
189 check_prototype_exists(_isnan float.h HAVE_ISNAN)
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)
196 check_symbol_exists(isnan math.h HAVE_ISNAN)
200 check_prototype_exists(isfinite cmath HAVE_STD_ISFINITE)
202 if(NOT HAVE_STD_ISFINITE)
204 check_prototype_exists(_finite float.h HAVE_FINITE)
206 #CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
207 check_symbol_exists(isfinite math.h HAVE_ISFINITE)
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")
250 ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h
251 ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.disabled)
252 set(PH_RESULT "renamed")
255 message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h - ${PH_RESULT}")
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 #################################################################################
269 #################################################################################
271 if(GEOS_ENABLE_TESTS)
273 # Include CTest support
277 # Define "make check" as alias for "make test"
278 add_custom_target(check COMMAND ctest)
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 #################################################################################
294 #################################################################################
296 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
297 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
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}")