• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23###########################################################################
24# Find the libpsl library
25#
26# Input variables:
27#
28# - `LIBPSL_INCLUDE_DIR`:   The libpsl include directory.
29# - `LIBPSL_LIBRARY`:       Path to `libpsl` library.
30#
31# Result variables:
32#
33# - `LIBPSL_FOUND`:         System has libpsl.
34# - `LIBPSL_INCLUDE_DIRS`:  The libpsl include directories.
35# - `LIBPSL_LIBRARIES`:     The libpsl library names.
36# - `LIBPSL_LIBRARY_DIRS`:  The libpsl library directories.
37# - `LIBPSL_PC_REQUIRES`:   The libpsl pkg-config packages.
38# - `LIBPSL_CFLAGS`:        Required compiler flags.
39# - `LIBPSL_VERSION`:       Version of libpsl.
40
41set(LIBPSL_PC_REQUIRES "libpsl")
42
43if(CURL_USE_PKGCONFIG AND
44   NOT DEFINED LIBPSL_INCLUDE_DIR AND
45   NOT DEFINED LIBPSL_LIBRARY)
46  find_package(PkgConfig QUIET)
47  pkg_check_modules(LIBPSL ${LIBPSL_PC_REQUIRES})
48endif()
49
50if(LIBPSL_FOUND AND LIBPSL_INCLUDE_DIRS)
51  string(REPLACE ";" " " LIBPSL_CFLAGS "${LIBPSL_CFLAGS}")
52  message(STATUS "Found Libpsl (via pkg-config): ${LIBPSL_INCLUDE_DIRS} (found version \"${LIBPSL_VERSION}\")")
53else()
54  find_path(LIBPSL_INCLUDE_DIR NAMES "libpsl.h")
55  find_library(LIBPSL_LIBRARY NAMES "psl" "libpsl")
56
57  unset(LIBPSL_VERSION CACHE)
58  if(LIBPSL_INCLUDE_DIR AND EXISTS "${LIBPSL_INCLUDE_DIR}/libpsl.h")
59    set(_version_regex "#[\t ]*define[\t ]+PSL_VERSION[\t ]+\"([^\"]*)\"")
60    file(STRINGS "${LIBPSL_INCLUDE_DIR}/libpsl.h" _version_str REGEX "${_version_regex}")
61    string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
62    set(LIBPSL_VERSION "${_version_str}")
63    unset(_version_regex)
64    unset(_version_str)
65  endif()
66
67  include(FindPackageHandleStandardArgs)
68  find_package_handle_standard_args(Libpsl
69    REQUIRED_VARS
70      LIBPSL_INCLUDE_DIR
71      LIBPSL_LIBRARY
72    VERSION_VAR
73      LIBPSL_VERSION
74  )
75
76  if(LIBPSL_FOUND)
77    set(LIBPSL_INCLUDE_DIRS ${LIBPSL_INCLUDE_DIR})
78    set(LIBPSL_LIBRARIES    ${LIBPSL_LIBRARY})
79  endif()
80
81  mark_as_advanced(LIBPSL_INCLUDE_DIR LIBPSL_LIBRARY)
82endif()
83