|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +if(SnappyAlt_FOUND) |
| 19 | + return() |
| 20 | +endif() |
| 21 | + |
| 22 | +set(find_package_args) |
| 23 | +if(SnappyAlt_FIND_VERSION) |
| 24 | + list(APPEND find_package_args ${SnappyAlt_FIND_VERSION}) |
| 25 | +endif() |
| 26 | +if(SnappyAlt_FIND_QUIETLY) |
| 27 | + list(APPEND find_package_args QUIET) |
| 28 | +endif() |
| 29 | + |
| 30 | +# Try to find Snappy using standard find_package first |
| 31 | +find_package(Snappy ${find_package_args}) |
| 32 | +if(Snappy_FOUND) |
| 33 | + if(PAIMON_SNAPPY_USE_SHARED) |
| 34 | + set(Snappy_TARGET Snappy::snappy) |
| 35 | + set(SnappyAlt_FOUND TRUE) |
| 36 | + return() |
| 37 | + else() |
| 38 | + if(TARGET Snappy::snappy-static) |
| 39 | + set(Snappy_TARGET Snappy::snappy-static) |
| 40 | + set(SnappyAlt_FOUND TRUE) |
| 41 | + return() |
| 42 | + else() |
| 43 | + get_target_property(Snappy_TYPE Snappy::snappy TYPE) |
| 44 | + if(Snappy_TYPE STREQUAL "STATIC_LIBRARY" OR Snappy_TYPE STREQUAL "INTERFACE_LIBRARY") |
| 45 | + set(Snappy_TARGET Snappy::snappy) |
| 46 | + set(SnappyAlt_FOUND TRUE) |
| 47 | + return() |
| 48 | + endif() |
| 49 | + endif() |
| 50 | + endif() |
| 51 | +endif() |
| 52 | + |
| 53 | +# Manual search if standard find_package didn't work |
| 54 | +set(PAIMON_LIBRARY_PATH_SUFFIXES |
| 55 | + lib |
| 56 | + lib64 |
| 57 | + lib/${CMAKE_LIBRARY_ARCHITECTURE}) |
| 58 | +set(PAIMON_INCLUDE_PATH_SUFFIXES include) |
| 59 | + |
| 60 | +if(PAIMON_SNAPPY_USE_SHARED) |
| 61 | + set(SNAPPY_LIB_NAMES) |
| 62 | + if(CMAKE_IMPORT_LIBRARY_SUFFIX) |
| 63 | + list(APPEND SNAPPY_LIB_NAMES |
| 64 | + "${CMAKE_IMPORT_LIBRARY_PREFIX}snappy${CMAKE_IMPORT_LIBRARY_SUFFIX}") |
| 65 | + endif() |
| 66 | + list(APPEND SNAPPY_LIB_NAMES |
| 67 | + "${CMAKE_SHARED_LIBRARY_PREFIX}snappy${CMAKE_SHARED_LIBRARY_SUFFIX}") |
| 68 | +else() |
| 69 | + set(SNAPPY_LIB_NAMES |
| 70 | + "${CMAKE_STATIC_LIBRARY_PREFIX}snappy${CMAKE_STATIC_LIBRARY_SUFFIX}") |
| 71 | +endif() |
| 72 | + |
| 73 | +if(Snappy_ROOT) |
| 74 | + find_library(Snappy_LIB |
| 75 | + NAMES ${SNAPPY_LIB_NAMES} |
| 76 | + PATHS ${Snappy_ROOT} |
| 77 | + PATH_SUFFIXES ${PAIMON_LIBRARY_PATH_SUFFIXES} |
| 78 | + NO_DEFAULT_PATH) |
| 79 | + find_path(Snappy_INCLUDE_DIR |
| 80 | + NAMES snappy.h |
| 81 | + PATHS ${Snappy_ROOT} |
| 82 | + NO_DEFAULT_PATH |
| 83 | + PATH_SUFFIXES ${PAIMON_INCLUDE_PATH_SUFFIXES}) |
| 84 | +else() |
| 85 | + find_library(Snappy_LIB NAMES ${SNAPPY_LIB_NAMES} |
| 86 | + PATH_SUFFIXES ${PAIMON_LIBRARY_PATH_SUFFIXES}) |
| 87 | + find_path(Snappy_INCLUDE_DIR |
| 88 | + NAMES snappy.h |
| 89 | + PATH_SUFFIXES ${PAIMON_INCLUDE_PATH_SUFFIXES}) |
| 90 | +endif() |
| 91 | + |
| 92 | +find_package_handle_standard_args(SnappyAlt REQUIRED_VARS Snappy_LIB Snappy_INCLUDE_DIR) |
| 93 | + |
| 94 | +if(SnappyAlt_FOUND) |
| 95 | + if(PAIMON_SNAPPY_USE_SHARED) |
| 96 | + set(Snappy_TARGET Snappy::snappy) |
| 97 | + set(Snappy_TARGET_TYPE SHARED) |
| 98 | + else() |
| 99 | + set(Snappy_TARGET Snappy::snappy) |
| 100 | + set(Snappy_TARGET_TYPE STATIC) |
| 101 | + endif() |
| 102 | + |
| 103 | + if(NOT TARGET ${Snappy_TARGET}) |
| 104 | + add_library(${Snappy_TARGET} ${Snappy_TARGET_TYPE} IMPORTED) |
| 105 | + set_target_properties(${Snappy_TARGET} |
| 106 | + PROPERTIES IMPORTED_LOCATION "${Snappy_LIB}" |
| 107 | + INTERFACE_INCLUDE_DIRECTORIES "${Snappy_INCLUDE_DIR}") |
| 108 | + endif() |
| 109 | +endif() |
0 commit comments