|
| 1 | +#.rst: |
| 2 | +# FindPROJ4 |
| 3 | +# -------- |
| 4 | +# |
| 5 | +# Find the proj includes and library. |
| 6 | +# |
| 7 | +# IMPORTED Targets |
| 8 | +# ^^^^^^^^^^^^^^^^ |
| 9 | +# |
| 10 | +# This module defines :prop_tgt:`IMPORTED` target ``PROJ4::proj``, |
| 11 | +# if Proj.4 has been found. |
| 12 | +# |
| 13 | +# Result Variables |
| 14 | +# ^^^^^^^^^^^^^^^^ |
| 15 | +# |
| 16 | +# This module defines the following variables: |
| 17 | +# |
| 18 | +# :: |
| 19 | +# |
| 20 | +# PROJ4_INCLUDE_DIRS - where to find proj_api.h, etc. |
| 21 | +# PROJ4_LIBRARIES - List of libraries when using libproj. |
| 22 | +# PROJ4_FOUND - True if libproj found. |
| 23 | +# |
| 24 | +# :: |
| 25 | +# |
| 26 | +# PROJ4_VERSION - The version of libproj found (x.y.z) |
| 27 | +# PROJ4_VERSION_MAJOR - The major version of libproj |
| 28 | +# PROJ4_VERSION_MINOR - The minor version of libproj |
| 29 | +# PROJ4_VERSION_PATCH - The patch version of libproj |
| 30 | +# PROJ4_VERSION_TWEAK - always 0 |
| 31 | +# PROJ4_VERSION_COUNT - The number of version components, always 3 |
| 32 | +# |
| 33 | +# Hints |
| 34 | +# ^^^^^ |
| 35 | +# |
| 36 | +# A user may set ``PROJ4_ROOT`` to a libproj installation root to tell this |
| 37 | +# module where to look exclusively. |
| 38 | + |
| 39 | +#============================================================================= |
| 40 | +# Copyright 2016 Kai Pastor |
| 41 | +# |
| 42 | +# |
| 43 | +# This file was derived from CMake 3.5's module FindZLIB.cmake |
| 44 | +# which has the following terms: |
| 45 | +# |
| 46 | +# Copyright 2001-2011 Kitware, Inc. |
| 47 | +# |
| 48 | +# Redistribution and use in source and binary forms, with or without |
| 49 | +# modification, are permitted provided that the following conditions are |
| 50 | +# met: |
| 51 | +# |
| 52 | +# * Redistributions of source code must retain the above copyright notice, |
| 53 | +# this list of conditions and the following disclaimer. |
| 54 | +# |
| 55 | +# * Redistributions in binary form must reproduce the above copyright notice, |
| 56 | +# this list of conditions and the following disclaimer in the documentation |
| 57 | +# and/or other materials provided with the distribution. |
| 58 | +# |
| 59 | +# * The names of Kitware, Inc., the Insight Consortium, or the names of |
| 60 | +# any consortium members, or of any contributors, may not be used to |
| 61 | +# endorse or promote products derived from this software without |
| 62 | +# specific prior written permission. |
| 63 | +# |
| 64 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' |
| 65 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 66 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 67 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR |
| 68 | +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 69 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 70 | +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 71 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 72 | +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 73 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 74 | +#============================================================================= |
| 75 | + |
| 76 | +# Search PROJ4_ROOT exclusively if it is set. |
| 77 | +if(PROJ4_ROOT) |
| 78 | + set(_PROJ4_SEARCH PATHS ${PROJ4_ROOT} NO_DEFAULT_PATH) |
| 79 | +else() |
| 80 | + set(_PROJ4_SEARCH) |
| 81 | +endif() |
| 82 | + |
| 83 | +find_path(PROJ4_INCLUDE_DIR NAMES proj_api.h ${_PROJ4_SEARCH} PATH_SUFFIXES include) |
| 84 | +mark_as_advanced(PROJ4_INCLUDE_DIR) |
| 85 | + |
| 86 | +if(PROJ4_INCLUDE_DIR AND EXISTS "${PROJ4_INCLUDE_DIR}/proj_api.h") |
| 87 | + file(STRINGS "${PROJ4_INCLUDE_DIR}/proj_api.h" PROJ4_H REGEX "^#define PJ_VERSION [0-9]+$") |
| 88 | + |
| 89 | + string(REGEX REPLACE "^.*PJ_VERSION ([0-9]).*$" "\\1" PROJ4_VERSION_MAJOR "${PROJ4_H}") |
| 90 | + string(REGEX REPLACE "^.*PJ_VERSION [0-9]([0-9]).*$" "\\1" PROJ4_VERSION_MINOR "${PROJ4_H}") |
| 91 | + string(REGEX REPLACE "^.*PJ_VERSION [0-9][0-9]([0-9]).*$" "\\1" PROJ4_VERSION_PATCH "${PROJ4_H}") |
| 92 | + set(PROJ4_VERSION "${PROJ4_VERSION_MAJOR}.${PROJ4_VERSION_MINOR}.${PROJ4_VERSION_PATCH}") |
| 93 | + set(PROJ4_VERSION_COUNT 3) |
| 94 | +endif() |
| 95 | + |
| 96 | +# Allow PROJ4_LIBRARY to be set manually, as the location of the proj library |
| 97 | +if(NOT PROJ4_LIBRARY) |
| 98 | + set(PROJ4_NAMES proj) |
| 99 | + set(PROJ4_NAMES_DEBUG projd) |
| 100 | + if(WIN32 AND DEFINED PROJ4_VERSION_MAJOR AND DEFINED PROJ4_VERSION_MINOR) |
| 101 | + list(APPEND PROJ4_NAMES proj_${PROJ4_VERSION_MAJOR}_${PROJ4_VERSION_MINOR}) |
| 102 | + list(APPEND PROJ4_NAMES projd_${PROJ4_VERSION_MAJOR}_${PROJ4_VERSION_MINOR}) |
| 103 | + endif() |
| 104 | + find_library(PROJ4_LIBRARY_RELEASE NAMES ${PROJ4_NAMES} ${_PROJ4_SEARCH} PATH_SUFFIXES lib) |
| 105 | + find_library(PROJ4_LIBRARY_DEBUG NAMES ${PROJ4_NAMES_DEBUG} ${_PROJ4_SEARCH} PATH_SUFFIXES lib) |
| 106 | + include(SelectLibraryConfigurations) |
| 107 | + select_library_configurations(PROJ4) |
| 108 | +endif() |
| 109 | + |
| 110 | +# handle the QUIETLY and REQUIRED arguments and set PROJ4_FOUND to TRUE if |
| 111 | +# all listed variables are TRUE |
| 112 | +include(FindPackageHandleStandardArgs) |
| 113 | +find_package_handle_standard_args(PROJ4 |
| 114 | + REQUIRED_VARS |
| 115 | + PROJ4_LIBRARY |
| 116 | + PROJ4_INCLUDE_DIR |
| 117 | + VERSION_VAR |
| 118 | + PROJ4_VERSION |
| 119 | +) |
| 120 | + |
| 121 | +if(PROJ4_FOUND) |
| 122 | + set(PROJ4_INCLUDE_DIRS ${PROJ4_INCLUDE_DIR}) |
| 123 | + |
| 124 | + if(NOT PROJ4_LIBRARIES) |
| 125 | + set(PROJ4_LIBRARIES ${PROJ4_LIBRARY}) |
| 126 | + endif() |
| 127 | + |
| 128 | + if(NOT TARGET PROJ4::proj) |
| 129 | + add_library(PROJ4::proj UNKNOWN IMPORTED) |
| 130 | + set_target_properties(PROJ4::proj PROPERTIES |
| 131 | + INTERFACE_INCLUDE_DIRECTORIES "${PROJ4_INCLUDE_DIRS}") |
| 132 | + |
| 133 | + if(PROJ4_LIBRARY_RELEASE) |
| 134 | + set_property(TARGET PROJ4::proj APPEND PROPERTY |
| 135 | + IMPORTED_CONFIGURATIONS RELEASE) |
| 136 | + set_target_properties(PROJ4::proj PROPERTIES |
| 137 | + IMPORTED_LOCATION_RELEASE "${PROJ4_LIBRARY_RELEASE}") |
| 138 | + endif() |
| 139 | + |
| 140 | + if(PROJ4_LIBRARY_DEBUG) |
| 141 | + set_property(TARGET PROJ4::proj APPEND PROPERTY |
| 142 | + IMPORTED_CONFIGURATIONS DEBUG) |
| 143 | + set_target_properties(PROJ4::proj PROPERTIES |
| 144 | + IMPORTED_LOCATION_DEBUG "${PROJ4_LIBRARY_DEBUG}") |
| 145 | + endif() |
| 146 | + |
| 147 | + if(NOT PROJ4_LIBRARY_RELEASE AND NOT PROJ4_LIBRARY_DEBUG) |
| 148 | + set_property(TARGET PROJ4::proj APPEND PROPERTY |
| 149 | + IMPORTED_LOCATION "${PROJ4_LIBRARY}") |
| 150 | + endif() |
| 151 | + endif() |
| 152 | +endif() |
0 commit comments