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
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 3)
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 OR MSVC11 OR MSVC12 OR MSVC13)
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 #################################################################################
241 # MACRO: GET_SVN_REVISION
244 # MACRO FOR GETTING THE SVN revision for this build
245 #################################################################################
246 MACRO (GET_SVN_REVISION)
247 FIND_PACKAGE(Subversion)
249 Subversion_WC_INFO(${PROJECT_SOURCE_DIR} Project)
250 # MESSAGE("Current revision is ${Project_WC_REVISION}")
251 # Subversion_WC_LOG(${PROJECT_SOURCE_DIR} Project)
252 # MESSAGE("Last changed log is ${Project_LAST_CHANGED_LOG}")
254 ENDMACRO(GET_SVN_REVISION)
256 # Determine SVN/Git revision
257 if(EXISTS "${CMAKE_SOURCE_DIR}/.svn")
260 if ( NOT ${Project_WC_REVISION} EQUAL 0 )
261 set( GEOS_SVN_REVISION ${Project_WC_REVISION} )
263 "${PROJECT_SOURCE_DIR}/tools/geos_svn_revision_cmake.h.in"
264 "${PROJECT_SOURCE_DIR}/geos_svn_revision.h" )
265 # "${geos_BINARY_DIR}/include/geos_svn_revision.h" )
267 message(STATUS "Generating revision header ${CMAKE_SOURCE_DIR}/geos_svn_revision.h")
270 execute_process(COMMAND ${SH} -c
271 "cd ${CMAKE_SOURCE_DIR} && ${CMAKE_SOURCE_DIR}/tools/svn_repo_revision.sh")
273 file(RENAME "${CMAKE_SOURCE_DIR}/geos_svn_revision.h"
274 "${CMAKE_BINARY_DIR}/geos_svn_revision.h")
276 message("*** sh-compatible command not found, cannot create geos_svn_revision.h")
277 message("*** Check SVN revision and create revision header manually:")
278 message("*** echo '#define GEOS_SVN_REVISION XYZ' > ${CMAKE_SOURCE_DIR}/geos_svn_revision.h")
281 # End: Determine SVN/Git revision
283 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
284 message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h")
286 if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
287 file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
288 set(PH_RESULT "removed")
291 ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h
292 ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.disabled)
293 set(PH_RESULT "renamed")
296 message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h - ${PH_RESULT}")
299 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.cmake
300 ${CMAKE_CURRENT_BINARY_DIR}/include/geos/platform.h)
302 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/version.h.in
303 ${CMAKE_CURRENT_BINARY_DIR}/include/geos/version.h @ONLY)
305 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/capi/geos_c.h.in
306 ${CMAKE_CURRENT_BINARY_DIR}/capi/geos_c.h @ONLY)
308 #################################################################################
310 #################################################################################
312 if(GEOS_ENABLE_TESTS)
314 # Include CTest support
318 # Define "make check" as alias for "make test"
319 add_custom_target(check COMMAND ctest)
323 #################################################################################
324 # Configure subdirectories
325 #################################################################################
327 add_subdirectory(include)
328 add_subdirectory(src)
329 add_subdirectory(capi)
330 add_subdirectory(tests)
331 add_subdirectory(tools)
333 #################################################################################
335 #################################################################################
337 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
338 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
341 add_custom_target(uninstall
342 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
344 #################################################################################
345 # DEBUG settings - TODO: make a summary
347 message(STATUS "CMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator")
349 #message(STATUS "XXX: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
350 #message(STATUS "XXX: CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}")
351 #message(STATUS "XXX: CMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}")