1 #################################################################################
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 #################################################################################
15 cmake_minimum_required(VERSION 2.6)
19 "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
22 # Location of custom CMake modules with macros used by GEOS
23 set(CMAKE_MODULE_PATH "${geos_SOURCE_DIR}/cmake/modules")
25 #################################################################################
27 #################################################################################
29 # GEOS release version
30 # GEOS C++ library SONAME will use these encoding ABI break at every release
34 set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
36 # JTS_PORT is the version of JTS this release is bound to
38 message(STATUS "Setting GEOS version ${VERSION} as port of JTS ${JTS_PORT}")
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)
62 option(GEOS_ENABLE_ASSERT
63 "Set to ON|OFF (default) to build GEOS with assert() macro enabled" OFF)
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)
71 #################################################################################
72 # Setup C/C++ compiler options
73 #################################################################################
75 if(NOT CMAKE_BUILD_TYPE)
76 set(CMAKE_BUILD_TYPE Debug CACHE STRING
77 "Choose the type of build, options are: None Debug Release" FORCE)
79 message(STATUS "Setting GEOS build type - ${CMAKE_BUILD_TYPE}")
81 if(CMAKE_BUILD_TYPE STREQUAL Debug)
82 add_definitions(-D_DEBUG)
85 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
88 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -ansi")
91 if(GEOS_ENABLE_FLOATSTORE)
92 # Remove extra precision by forcing conformance to IEEE 754 rather than IEEE 854
93 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffloat-store")
96 "Forcing IEEE 754 using flag -ffloat-store - ${GEOS_ENABLE_FLOATSTORE}")
98 # Warnings specification
99 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long")
101 # Turn on Position Independent Code generation for GEOS C shared library
102 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
104 # Enable glibc ISO C99 features (macros isfinite, isnan)
105 set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_ISOC99_SOURCE=1")
109 # Set pedantic mode by default
110 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
111 string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
112 message(STATUS "Z: ${CMAKE_CXX_FLAGS}")
114 if(MSVC80 OR MSVC90 OR MSVC10)
116 # Option is to enable the /MP switch for Visual Studio 2005 or later
117 option(GEOS_MSVC_ENABLE_MP
118 "Set to ON to build GEOS with the /MP option (Visual Studio 2005 and above)." ON)
119 mark_as_advanced(GEOS_MSVC_ENABLE_MP)
120 if(GEOS_MSVC_ENABLE_MP)
121 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
123 message(STATUS "Setting Visual Studio 2005+ option /MP to ${GEOS_MSVC_ENABLE_MP}")
125 # Disable C4996: 'function': was declared deprecated
126 add_definitions(-D_SCL_SECURE_NO_WARNINGS)
127 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
132 if(GEOS_ENABLE_INLINE)
133 add_definitions(-DGEOS_INLINE)
136 "Setting GEOS compilation with small functions inlining - ${GEOS_ENABLE_INLINE}")
139 if(GEOS_ENABLE_ASSERT)
140 string(REGEX REPLACE "[-/]D.*NDEBUG" "-U NDEBUG"
141 CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
144 "Setting GEOS compilation with assert() macro enabled - ${GEOS_ENABLE_ASSERT}")
147 #################################################################################
148 # Setup C/C++ library features
149 #################################################################################
151 include(TestForSTDNamespace)
152 if (CMAKE_NO_STD_NAMESPACE)
153 message(FATAL_ERROR "Detected compiler does not support std namespace on STL classes")
157 include(CheckIncludeFiles)
159 check_include_files(stdint.h HAVE_STDINT_H)
160 check_include_files(inttypes.h HAVE_INTTYPES_H)
161 check_include_files(ieeefp.h HAVE_IEEEFP_H)
163 # check types and sizes
164 include(CheckTypeSize)
167 check_type_size("__int64" HAVE_INT64_T_64)
169 if(HAVE_STDINT_H OR HAVE_INTTYPES_H)
170 check_type_size("int64_t" HAVE_INT64_T_64)
172 check_type_size("long long int" HAVE_LONG_LONG_INT_64)
176 # check functions and macros
177 include(CheckPrototypeExists)
178 include(CheckSymbolExists)
180 check_prototype_exists(isnan cmath HAVE_STD_ISNAN)
181 if(NOT HAVE_STD_ISNAN)
183 check_prototype_exists(_isnan float.h HAVE_ISNAN)
185 check_prototype_exists(__isnand math.h HAVE_ISNAND_XCODE)
186 if(NOT HAVE_ISNAND_XCODE)
187 check_prototype_exists(__inline_isnand math.h HAVE_INLINE_ISNAND_XCODE)
190 check_symbol_exists(isnan math.h HAVE_ISNAN)
194 check_prototype_exists(isfinite cmath HAVE_STD_ISFINITE)
196 if(NOT HAVE_STD_ISFINITE)
198 check_prototype_exists(_finite float.h HAVE_FINITE)
200 #CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
201 check_symbol_exists(isfinite math.h HAVE_ISFINITE)
205 ################################################################################
206 # Setup include directories
207 #################################################################################
209 # for including GEOS C++ API headers
210 include_directories(${geos_SOURCE_DIR}/include)
212 # for including build-specific GEOS C API headers
213 include_directories(${geos_BINARY_DIR}/capi)
215 # for including build-specific version.h, platform.h and geos_c.h
216 include_directories(${geos_BINARY_DIR}/include)
218 #################################################################################
219 # Setup checks and generate config headers
220 #################################################################################
222 # TODO: output to CMAKE_CURRENT_BINARY_DIR instead of CMAKE_SOURCE_DIR
224 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
225 message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h")
227 if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
228 file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
229 set(PH_RESULT "removed")
232 ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h
233 ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.disabled)
234 set(PH_RESULT "renamed")
237 message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h - ${PH_RESULT}")
240 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.cmake
241 ${CMAKE_CURRENT_BINARY_DIR}/include/geos/platform.h)
243 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/version.h.in
244 ${CMAKE_CURRENT_BINARY_DIR}/include/geos/version.h @ONLY)
246 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/capi/geos_c.h.in
247 ${CMAKE_CURRENT_BINARY_DIR}/capi/geos_c.h @ONLY)
249 #################################################################################
251 #################################################################################
253 if(GEOS_ENABLE_TESTS)
255 # Include CTest support
259 # Define "make check" as alias for "make test"
260 add_custom_target(check COMMAND ctest)
264 #################################################################################
265 # Configure subdirectories
266 #################################################################################
268 add_subdirectory(include)
269 add_subdirectory(src)
270 add_subdirectory(capi)
271 add_subdirectory(tests)
272 add_subdirectory(tools)
274 #################################################################################
276 #################################################################################
278 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
279 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
282 add_custom_target(uninstall
283 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
285 #################################################################################
286 # DEBUG settings - TODO: make a summary
288 message(STATUS "CMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator")
290 #message(STATUS "XXX: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
291 #message(STATUS "XXX: CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}")
292 #message(STATUS "XXX: CMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}")