|
| 1 | +# Top-level CMakeLists.txt for the CMake-based build and test system |
| 2 | +# of the shapelib software. |
| 3 | + |
| 4 | +# Copyright (C) 2012-2013 Alan W. Irwin |
| 5 | + |
| 6 | +# See README.CMake |
| 7 | + |
| 8 | +# This file is free software; you can redistribute it and/or modify |
| 9 | +# it under the terms of the GNU Library General Public License as published |
| 10 | +# by the Free Software Foundation; version 2 of the License. |
| 11 | +# |
| 12 | +# This file is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU Library General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU Library General Public License |
| 18 | +# along with this file; if not, write to the Free Software |
| 19 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | + |
| 21 | +# It is a fatal error if no working C compiler is available to build |
| 22 | +# the shapelib library and utilities |
| 23 | +project(shapelib C) |
| 24 | + |
| 25 | +message(STATUS "CMake version = ${CMAKE_VERSION}") |
| 26 | +message(STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}") |
| 27 | + |
| 28 | +# Version 2.8.5 or above of cmake is currently required for all platforms. |
| 29 | +cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR) |
| 30 | + |
| 31 | +# libraries are all shared by default. |
| 32 | +option(BUILD_SHARED_LIBS "Build shared libraries" ON) |
| 33 | + |
| 34 | +# Use rpath? |
| 35 | +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 36 | + # No rpath on Darwin. Setting it will only cause trouble. |
| 37 | +else(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 38 | + option(USE_RPATH "Use -rpath when linking libraries, executables" ON) |
| 39 | +endif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 40 | + |
| 41 | +# In windows all created dlls are gathered in the dll directory |
| 42 | +# if you add this directory to your PATH all shared libraries are available |
| 43 | +if(BUILD_SHARED_LIBS AND WIN32 AND NOT CYGWIN) |
| 44 | + set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dll) |
| 45 | +endif(BUILD_SHARED_LIBS AND WIN32 AND NOT CYGWIN) |
| 46 | + |
| 47 | +set(PACKAGE shp) |
| 48 | + |
| 49 | +# Set up install locations. |
| 50 | +set( |
| 51 | + CMAKE_INSTALL_BINDIR |
| 52 | + ${CMAKE_INSTALL_PREFIX}/bin |
| 53 | + CACHE PATH "install location for user executables" |
| 54 | + ) |
| 55 | + |
| 56 | +set( |
| 57 | + CMAKE_INSTALL_LIBDIR |
| 58 | + ${CMAKE_INSTALL_PREFIX}/lib |
| 59 | + CACHE PATH "install location for object code libraries" |
| 60 | + ) |
| 61 | + |
| 62 | +set( |
| 63 | + CMAKE_INSTALL_INCLUDEDIR |
| 64 | + ${CMAKE_INSTALL_PREFIX}/include |
| 65 | + CACHE PATH "install location for C header files" |
| 66 | + ) |
| 67 | + |
| 68 | +set( |
| 69 | + CMAKE_INSTALL_SHP_DATADIR |
| 70 | + ${CMAKE_INSTALL_PREFIX}/share/${PACKAGE} |
| 71 | + CACHE PATH "install location for read-only architecture-independent shp data" |
| 72 | + ) |
| 73 | + |
| 74 | +# Export build information to help other projects link installed |
| 75 | +# shapelib software. Only one of these signatures is required |
| 76 | +# for the export_shp name. |
| 77 | +install(EXPORT export_shp DESTINATION ${CMAKE_INSTALL_SHP_DATADIR}) |
| 78 | + |
| 79 | +# Initial boilerplate done, now build library and executables. |
| 80 | + |
| 81 | +set(lib_SRC |
| 82 | + shpopen.c |
| 83 | + dbfopen.c |
| 84 | + safileio.c |
| 85 | + shptree.c |
| 86 | + sbnsearch.c |
| 87 | + ) |
| 88 | +option(SHP_DROP_UNABLE_TO_OPEN_MSG "Drop \"unable to open\" error messages" ON) |
| 89 | +if(SHP_DROP_UNABLE_TO_OPEN_MSG) |
| 90 | + #define the SHP_DROP_UNABLE_TO_OPEN_MSG C macro for this source file. |
| 91 | + set_source_files_properties(shpopen.c |
| 92 | + PROPERTIES |
| 93 | + COMPILE_DEFINITIONS SHP_DROP_UNABLE_TO_OPEN_MSG |
| 94 | + ) |
| 95 | +endif(SHP_DROP_UNABLE_TO_OPEN_MSG) |
| 96 | + |
| 97 | +add_library(shp ${lib_SRC}) |
| 98 | + |
| 99 | +if(WIN32 AND NOT CYGWIN) |
| 100 | + set_target_properties(shp |
| 101 | + PROPERTIES |
| 102 | + COMPILE_DEFINITIONS SHAPELIB_DLLEXPORT |
| 103 | + ) |
| 104 | +endif(WIN32 AND NOT CYGWIN) |
| 105 | + |
| 106 | +if(UNIX) |
| 107 | + find_library(M_LIB m) |
| 108 | + if(M_LIB) |
| 109 | + TARGET_LINK_LIBRARIES(shp -lm) |
| 110 | + endif() |
| 111 | +endif(UNIX) |
| 112 | + |
| 113 | +set(shp_SOVERSION 1) |
| 114 | +set(shp_VERSION 1.4.1) |
| 115 | +set_target_properties(shp |
| 116 | + PROPERTIES |
| 117 | + SOVERSION ${shp_SOVERSION} |
| 118 | + VERSION ${shp_VERSION} |
| 119 | + INSTALL_NAME_DIR "${CMAKE_INSTALL_LIBDIR}" |
| 120 | + ) |
| 121 | + |
| 122 | +if(USE_RPATH) |
| 123 | + set_target_properties(shp |
| 124 | + PROPERTIES |
| 125 | + INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}" |
| 126 | + ) |
| 127 | +endif(USE_RPATH) |
| 128 | + |
| 129 | +install(TARGETS shp |
| 130 | + EXPORT export_shp |
| 131 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 132 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 133 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 134 | + ) |
| 135 | + |
| 136 | +# executables to be built and installed. |
| 137 | +set(executables |
| 138 | + shpcreate |
| 139 | + shpadd |
| 140 | + shpdump |
| 141 | + shprewind |
| 142 | + dbfcreate |
| 143 | + dbfadd |
| 144 | + dbfdump |
| 145 | + shptreedump |
| 146 | + ) |
| 147 | + |
| 148 | +find_program(BASH_EXECUTABLE bash) |
| 149 | +find_program(SED_EXECUTABLE sed) |
| 150 | +if(BASH_EXECUTABLE AND SED_EXECUTABLE) |
| 151 | + set(BUILD_TEST ON) |
| 152 | +else(BASH_EXECUTABLE AND SED_EXECUTABLE) |
| 153 | + message(STATUS "WARNING: sed or bash not available so disabling testing") |
| 154 | +endif(BASH_EXECUTABLE AND SED_EXECUTABLE) |
| 155 | + |
| 156 | +# For the first series of tests, the user needs to have downloaded |
| 157 | +# from http://dl.maptools.org/dl/shapelib/shape_eg_data.zip, unpacked |
| 158 | +# that file, and specified the location of that directory with |
| 159 | +# the cmake option, -DEG_DATA:PATH=whatever |
| 160 | +if(BUILD_TEST) |
| 161 | + if(EG_DATA) |
| 162 | + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/script.sed "s?/u/www/projects/shapelib/eg_data?${EG_DATA}?\n") |
| 163 | + else(EG_DATA) |
| 164 | + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/script.sed "") |
| 165 | + message(STATUS "WARNING: EG_DATA:PATH not set to point to downloaded eg_data directory so the eg_data part of testing will be ignored.") |
| 166 | + endif(EG_DATA) |
| 167 | +endif(BUILD_TEST) |
| 168 | + |
| 169 | +foreach(executable ${executables}) |
| 170 | + add_executable(${executable} ${executable}.c) |
| 171 | + target_link_libraries(${executable} shp) |
| 172 | + if(USE_RPATH) |
| 173 | + set_target_properties(${executable} |
| 174 | + PROPERTIES |
| 175 | + INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}" |
| 176 | + ) |
| 177 | + endif(USE_RPATH) |
| 178 | + if(BUILD_TEST) |
| 179 | + get_target_property(${executable}_LOC ${executable} LOCATION) |
| 180 | + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/script.sed "s?\\./${executable}?${${executable}_LOC}?\n") |
| 181 | + endif(BUILD_TEST) |
| 182 | + install(TARGETS ${executable} DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 183 | +endforeach(executable ${executables}) |
| 184 | + |
| 185 | +# Install header |
| 186 | +install(FILES shapefil.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 187 | + |
| 188 | +if(BUILD_TEST) |
| 189 | + # Set up tests: |
| 190 | + |
| 191 | + enable_testing() |
| 192 | + |
| 193 | + # Other executables to be built to facilitate tests. |
| 194 | + foreach(executable shptest shputils) |
| 195 | + add_executable(${executable} ${executable}.c) |
| 196 | + target_link_libraries(${executable} shp) |
| 197 | + get_target_property(${executable}_LOC ${executable} LOCATION) |
| 198 | + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/script.sed "s?\\./${executable}?${${executable}_LOC}?\n") |
| 199 | + endforeach(executable shptest shputils) |
| 200 | + |
| 201 | + # Write this as a shell script since execute_process cannot handle |
| 202 | + # anything like redirection. |
| 203 | + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/script.sh "${SED_EXECUTABLE} -f script.sed < $1 >| $2") |
| 204 | + execute_process( |
| 205 | + COMMAND |
| 206 | + ${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/script.sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test1.sh ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test1.sh |
| 207 | + ) |
| 208 | + |
| 209 | + execute_process( |
| 210 | + COMMAND |
| 211 | + ${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/script.sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test2.sh ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test2.sh |
| 212 | + ) |
| 213 | + |
| 214 | + execute_process( |
| 215 | + COMMAND |
| 216 | + ${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/script.sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test3.sh ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test3.sh |
| 217 | + ) |
| 218 | + |
| 219 | + if(EG_DATA) |
| 220 | + # These tests correspond to everything in test1.sh |
| 221 | + add_test( |
| 222 | + NAME test1 |
| 223 | + COMMAND ${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test1.sh |
| 224 | + ) |
| 225 | + endif(EG_DATA) |
| 226 | + # These tests correspond to everything in test2.sh |
| 227 | + add_test( |
| 228 | + NAME test2 |
| 229 | + COMMAND ${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test2.sh |
| 230 | + ) |
| 231 | + |
| 232 | + # These tests correspond to everything in test3.sh |
| 233 | + add_test( |
| 234 | + NAME test3 |
| 235 | + COMMAND ${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test3.sh |
| 236 | + ) |
| 237 | +endif(BUILD_TEST) |
0 commit comments