]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
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(MSVC AND NOT DEFINED ZSTD_MSVC_LIB_PREFIX) | |
19 | set(ZSTD_MSVC_LIB_PREFIX "lib") | |
20 | endif() | |
21 | set(ZSTD_LIB_NAME_BASE "${ZSTD_MSVC_LIB_PREFIX}zstd") | |
22 | ||
23 | if(ARROW_ZSTD_USE_SHARED) | |
24 | set(ZSTD_LIB_NAMES) | |
25 | if(CMAKE_IMPORT_LIBRARY_SUFFIX) | |
26 | list(APPEND | |
27 | ZSTD_LIB_NAMES | |
28 | "${CMAKE_IMPORT_LIBRARY_PREFIX}${ZSTD_LIB_NAME_BASE}${CMAKE_IMPORT_LIBRARY_SUFFIX}" | |
29 | ) | |
30 | endif() | |
31 | list(APPEND ZSTD_LIB_NAMES | |
32 | "${CMAKE_SHARED_LIBRARY_PREFIX}${ZSTD_LIB_NAME_BASE}${CMAKE_SHARED_LIBRARY_SUFFIX}" | |
33 | ) | |
34 | else() | |
35 | if(MSVC AND NOT DEFINED ZSTD_MSVC_STATIC_LIB_SUFFIX) | |
36 | set(ZSTD_MSVC_STATIC_LIB_SUFFIX "_static") | |
37 | endif() | |
38 | set(ZSTD_STATIC_LIB_SUFFIX | |
39 | "${ZSTD_MSVC_STATIC_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") | |
40 | set(ZSTD_LIB_NAMES | |
41 | "${CMAKE_STATIC_LIBRARY_PREFIX}${ZSTD_LIB_NAME_BASE}${ZSTD_STATIC_LIB_SUFFIX}") | |
42 | endif() | |
43 | ||
44 | # First, find via if specified ZSTD_ROOT | |
45 | if(ZSTD_ROOT) | |
46 | message(STATUS "Using ZSTD_ROOT: ${ZSTD_ROOT}") | |
47 | find_library(ZSTD_LIB | |
48 | NAMES ${ZSTD_LIB_NAMES} | |
49 | PATHS ${ZSTD_ROOT} | |
50 | PATH_SUFFIXES ${ARROW_LIBRARY_PATH_SUFFIXES} | |
51 | NO_DEFAULT_PATH) | |
52 | find_path(ZSTD_INCLUDE_DIR | |
53 | NAMES zstd.h | |
54 | PATHS ${ZSTD_ROOT} | |
55 | NO_DEFAULT_PATH | |
56 | PATH_SUFFIXES ${ARROW_INCLUDE_PATH_SUFFIXES}) | |
57 | ||
58 | else() | |
59 | # Second, find via pkg_check_modules | |
60 | find_package(PkgConfig QUIET) | |
61 | pkg_check_modules(ZSTD_PC libzstd) | |
62 | if(ZSTD_PC_FOUND) | |
63 | set(ZSTD_INCLUDE_DIR "${ZSTD_PC_INCLUDEDIR}") | |
64 | ||
65 | list(APPEND ZSTD_PC_LIBRARY_DIRS "${ZSTD_PC_LIBDIR}") | |
66 | find_library(ZSTD_LIB | |
67 | NAMES ${ZSTD_LIB_NAMES} | |
68 | PATHS ${ZSTD_PC_LIBRARY_DIRS} | |
69 | NO_DEFAULT_PATH | |
70 | PATH_SUFFIXES ${ARROW_LIBRARY_PATH_SUFFIXES}) | |
71 | else() | |
72 | # Third, check all other CMake paths | |
73 | find_library(ZSTD_LIB | |
74 | NAMES ${ZSTD_LIB_NAMES} | |
75 | PATH_SUFFIXES ${ARROW_LIBRARY_PATH_SUFFIXES}) | |
76 | find_path(ZSTD_INCLUDE_DIR | |
77 | NAMES zstd.h | |
78 | PATH_SUFFIXES ${ARROW_INCLUDE_PATH_SUFFIXES}) | |
79 | endif() | |
80 | endif() | |
81 | ||
82 | find_package_handle_standard_args(zstd REQUIRED_VARS ZSTD_LIB ZSTD_INCLUDE_DIR) | |
83 | ||
84 | if(zstd_FOUND) | |
85 | add_library(zstd::libzstd UNKNOWN IMPORTED) | |
86 | set_target_properties(zstd::libzstd | |
87 | PROPERTIES IMPORTED_LOCATION "${ZSTD_LIB}" | |
88 | INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIR}") | |
89 | endif() |