Add a simple test for MCIndexSnapRounderTest
[geos.git] / CMakeLists.txt
blob61e59bb89cdeb7f3ca2a3e411b71f24992974c27
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 dev)
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 include(TestForSTDNamespace)
159 if (CMAKE_NO_STD_NAMESPACE)
160   message(FATAL_ERROR "Detected compiler does not support std namespace on STL classes")
161 endif()
163 # check header files
164 include(CheckIncludeFiles)
166 check_include_files(stdint.h HAVE_STDINT_H)
167 check_include_files(inttypes.h HAVE_INTTYPES_H)
168 check_include_files(ieeefp.h HAVE_IEEEFP_H)
170 # check types and sizes
171 include(CheckTypeSize)
173 if(MSVC)
174   check_type_size("__int64" HAVE_INT64_T_64)
175 else()
176   if(HAVE_STDINT_H OR HAVE_INTTYPES_H)
177     check_type_size("int64_t" HAVE_INT64_T_64)
178   else()
179     check_type_size("long long int" HAVE_LONG_LONG_INT_64)
180   endif()
181 endif()
183 # check functions and macros
184 include(CheckPrototypeExists)
185 include(CheckSymbolExists)
187 check_prototype_exists(isnan cmath HAVE_STD_ISNAN)
188 if(NOT HAVE_STD_ISNAN)
189   if(MSVC)
190     check_prototype_exists(_isnan float.h HAVE_ISNAN)
191   elseif(APPLE)
192     check_prototype_exists(__isnand math.h HAVE_ISNAND_XCODE)
193     if(NOT HAVE_ISNAND_XCODE)
194       check_prototype_exists(__inline_isnand math.h HAVE_INLINE_ISNAND_XCODE)
195     endif()
196   else()
197     check_symbol_exists(isnan math.h HAVE_ISNAN)
198   endif()
199 endif()
201 check_prototype_exists(isfinite cmath HAVE_STD_ISFINITE)
203 if(NOT HAVE_STD_ISFINITE)
204   if(MSVC)
205     check_prototype_exists(_finite float.h HAVE_FINITE)
206   else()
207     #CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
208     check_symbol_exists(isfinite math.h HAVE_ISFINITE)
209   endif()
210 endif()
212 ################################################################################
213 # Setup build directories
214 #################################################################################
216 # Put the libaries and binaries that get built into directories at the
217 # top of the build tree rather than in hard-to-find leaf
218 # directories. This simplifies manual testing and the use of the build
219 # tree rather than installed Boost libraries.
220 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
221 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
222 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
224 ################################################################################
225 # Setup include directories
226 #################################################################################
228 # for including GEOS C++ API headers
229 include_directories(${geos_SOURCE_DIR}/include)
231 # for including build-specific GEOS C API headers
232 include_directories(${geos_BINARY_DIR}/capi)
234 # for including build-specific version.h, platform.h and geos_c.h
235 include_directories(${geos_BINARY_DIR}/include)
237 #################################################################################
238 # Setup checks and generate config headers
239 #################################################################################
241 # TODO: output to CMAKE_CURRENT_BINARY_DIR instead of CMAKE_SOURCE_DIR
243 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
244   message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h")
246   if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
247     file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h)
248     set(PH_RESULT "removed")
249   else()
250     file(RENAME
251       ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h
252       ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.disabled)
253       set(PH_RESULT "renamed")
254   endif()
256   message(STATUS "Disabling existing ${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h - ${PH_RESULT}")
257 endif()
259 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/platform.h.cmake 
260   ${CMAKE_CURRENT_BINARY_DIR}/include/geos/platform.h)
262 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/geos/version.h.in
263   ${CMAKE_CURRENT_BINARY_DIR}/include/geos/version.h @ONLY)
265 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/capi/geos_c.h.in
266   ${CMAKE_CURRENT_BINARY_DIR}/capi/geos_c.h @ONLY)
268 #################################################################################
269 # Configure tests
270 #################################################################################
272 if(GEOS_ENABLE_TESTS)
274  # Include CTest support
275  include(CTest)
276  enable_testing()
278   # Define "make check" as alias for "make test"
279   add_custom_target(check COMMAND ctest)
281 endif()
283 #################################################################################
284 # Configure subdirectories
285 #################################################################################
287 add_subdirectory(include)
288 add_subdirectory(src)
289 add_subdirectory(capi)
290 add_subdirectory(tests)
291 add_subdirectory(tools)
293 #################################################################################
294 # Install/Uninstall
295 #################################################################################
297 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
298   "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
299   IMMEDIATE @ONLY)
301 add_custom_target(uninstall
302   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake") 
304 #################################################################################
305 # DEBUG settings - TODO: make a summary
307 message(STATUS "CMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator")
309 #message(STATUS "XXX: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
310 #message(STATUS "XXX: CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}")
311 #message(STATUS "XXX: CMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}")