Abort if HotPixel is constructed with zero scale (#529)
[geos.git] / CMakeLists.txt
blob74acffa38ee75091ced06e87fe42c6f4a6d777e3
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 "${geos_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 4)
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.12.0)
37 message(STATUS "Setting GEOS version ${VERSION} as port of JTS ${JTS_PORT}")
39 # GEOS C API version
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 #################################################################################
51 # Check custom global options
52 #################################################################################
54 option(GEOS_ENABLE_TESTS
55   "Set to OFF|ON (default) to control build of GEOS tests package" ON)
57 option(GEOS_ENABLE_INLINE
58   "Set to OFF|ON (default) to control GEOS compilation with small functions inlining" ON)
60 if(NOT MSVC)
61   option(GEOS_ENABLE_ASSERT
62     "Set to ON|OFF (default) to build GEOS with assert() macro enabled" OFF) 
63 endif()
65 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
66   option(GEOS_ENABLE_FLOATSTORE
67     "Set to OFF|ON (default) to control IEEE754 conformance and remove extra precision" ON)
68 endif()
70 if(APPLE)
71   option(GEOS_ENABLE_MACOSX_FRAMEWORK
72     "Set to OFF|ON (default) to build GEOS as a Mac OS X framework" OFF)
73   option(GEOS_ENABLE_MACOSX_FRAMEWORK_UNIXCOMPAT
74     "Set to ON|OFF (default) to add Unix compatibility to the Mac OS X framework" OFF)
75 endif()
77 #################################################################################
78 # Setup C/C++ compiler options
79 #################################################################################
81 if(NOT MSVC_IDE)
82   if(NOT CMAKE_BUILD_TYPE)
83     set(CMAKE_BUILD_TYPE Debug CACHE STRING
84       "Choose the type of build, options are: None Debug Release" FORCE)
85   endif()
86   message(STATUS "Setting GEOS build type - ${CMAKE_BUILD_TYPE}")
87 endif()
89 if(CMAKE_BUILD_TYPE STREQUAL Debug)
90   add_definitions(-D_DEBUG)
91 endif()
93 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
95   # General options
96   set(CMAKE_CXX_FLAGS "-pedantic -ansi ${CMAKE_CXX_FLAGS}")
98   # Numerical stability
99   if(GEOS_ENABLE_FLOATSTORE)
100     # Remove extra precision by forcing conformance to IEEE 754 rather than IEEE 854
101     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffloat-store")
102   endif()
103   message(STATUS
104     "Forcing IEEE 754 using flag -ffloat-store - ${GEOS_ENABLE_FLOATSTORE}")
106   # Warnings specification
107   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long")
109   # Turn on Position Independent Code generation for GEOS C shared library
110   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
112   # Enable glibc ISO C99 features (macros isfinite, isnan)
113   set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_ISOC99_SOURCE=1")
115 elseif(MSVC)
116     
117   # Set pedantic mode by default
118   #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
119   string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
121   if(MSVC80 OR MSVC90 OR MSVC10)
123     # Option is to enable the /MP switch for Visual Studio 2005 or later
124     option(GEOS_MSVC_ENABLE_MP
125       "Set to ON to build GEOS with the /MP option (Visual Studio 2005 and above)." ON)
126     mark_as_advanced(GEOS_MSVC_ENABLE_MP)
127     if(GEOS_MSVC_ENABLE_MP)
128       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
129     endif()
130     message(STATUS "Setting Visual Studio 2005+ option /MP to ${GEOS_MSVC_ENABLE_MP}")
131     
132     add_definitions(-D_SCL_SECURE_NO_WARNINGS)
133     add_definitions(-D_CRT_SECURE_NO_WARNINGS)
134     add_definitions(-DNOMINMAX)
135   endif()
137 endif()
139 if(GEOS_ENABLE_INLINE)
140   add_definitions(-DGEOS_INLINE)
141 endif()
142 message(STATUS
143   "Setting GEOS compilation with small functions inlining - ${GEOS_ENABLE_INLINE}")
145 if(NOT MSVC)
146   if(GEOS_ENABLE_ASSERT)
147     string(REGEX REPLACE "[-/]D.*NDEBUG" "-U NDEBUG"
148       CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
149   endif()
150   message(STATUS
151     "Setting GEOS compilation with assert() macro enabled - ${GEOS_ENABLE_ASSERT}")
152 endif()
154 #################################################################################
155 # Setup C/C++ library features
156 #################################################################################
158 # check header files
159 include(CheckIncludeFiles)
161 check_include_files(stdint.h HAVE_STDINT_H)
162 check_include_files(inttypes.h HAVE_INTTYPES_H)
163 check_include_files(ieeefp.h HAVE_IEEEFP_H)
165 # check types and sizes
166 include(CheckTypeSize)
168 if(MSVC)
169   check_type_size("__int64" HAVE_INT64_T_64)
170 else()
171   if(HAVE_STDINT_H OR HAVE_INTTYPES_H)
172     check_type_size("int64_t" HAVE_INT64_T_64)
173   else()
174     check_type_size("long long int" HAVE_LONG_LONG_INT_64)
175   endif()
176 endif()
178 # check functions and macros
179 include(CheckPrototypeExists)
180 include(CheckSymbolExists)
182 check_prototype_exists(isnan cmath HAVE_STD_ISNAN)
183 if(NOT HAVE_STD_ISNAN)
184   if(MSVC)
185     check_prototype_exists(_isnan float.h HAVE_ISNAN)
186   elseif(APPLE)
187     check_prototype_exists(__isnand math.h HAVE_ISNAND_XCODE)
188     if(NOT HAVE_ISNAND_XCODE)
189       check_prototype_exists(__inline_isnand math.h HAVE_INLINE_ISNAND_XCODE)
190     endif()
191   else()
192     check_symbol_exists(isnan math.h HAVE_ISNAN)
193   endif()
194 endif()
196 check_prototype_exists(isfinite cmath HAVE_STD_ISFINITE)
198 if(NOT HAVE_STD_ISFINITE)
199   if(MSVC)
200     check_prototype_exists(_finite float.h HAVE_FINITE)
201   else()
202     #CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
203     check_symbol_exists(isfinite math.h HAVE_ISFINITE)
204   endif()
205 endif()
207 ################################################################################
208 # Setup build directories
209 #################################################################################
211 # Put the libaries and binaries that get built into directories at the
212 # top of the build tree rather than in hard-to-find leaf
213 # directories. This simplifies manual testing and the use of the build
214 # tree rather than installed Boost libraries.
215 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
216 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
217 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
219 ################################################################################
220 # Setup include directories
221 #################################################################################
223 # for including GEOS C++ API headers
224 include_directories(${geos_SOURCE_DIR}/include)
226 # for including build-specific GEOS C API headers
227 include_directories(${geos_BINARY_DIR}/capi)
229 # for including build-specific version.h, platform.h and geos_c.h
230 include_directories(${geos_BINARY_DIR}/include)
232 #################################################################################
233 # Setup checks and generate config headers
234 #################################################################################
236 # TODO: output to CMAKE_CURRENT_BINARY_DIR instead of CMAKE_SOURCE_DIR
238 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
239   message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h")
241   if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
242     file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
243     set(PH_RESULT "removed")
244   else()
245     file(RENAME
246       ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h
247       ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.disabled)
248       set(PH_RESULT "renamed")
249   endif()
251   message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h - ${PH_RESULT}")
252 endif()
254 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.cmake 
255   ${CMAKE_CURRENT_BINARY_DIR}/include/geos/platform.h)
257 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/version.h.in
258   ${CMAKE_CURRENT_BINARY_DIR}/include/geos/version.h @ONLY)
260 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/capi/geos_c.h.in
261   ${CMAKE_CURRENT_BINARY_DIR}/capi/geos_c.h @ONLY)
263 #################################################################################
264 # Configure tests
265 #################################################################################
267 if(GEOS_ENABLE_TESTS)
269  # Include CTest support
270  include(CTest)
271  enable_testing()
273   # Define "make check" as alias for "make test"
274   add_custom_target(check COMMAND ctest)
276 endif()
278 #################################################################################
279 # Configure subdirectories
280 #################################################################################
282 add_subdirectory(include)
283 add_subdirectory(src)
284 add_subdirectory(capi)
285 add_subdirectory(tests)
286 add_subdirectory(tools)
288 #################################################################################
289 # Install/Uninstall
290 #################################################################################
292 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
293   "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
294   IMMEDIATE @ONLY)
296 add_custom_target(uninstall
297   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake") 
299 #################################################################################
300 # DEBUG settings - TODO: make a summary
302 message(STATUS "CMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator")
304 #message(STATUS "XXX: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
305 #message(STATUS "XXX: CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}")
306 #message(STATUS "XXX: CMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}")