aboutsummaryrefslogtreecommitdiff
path: root/cmake/modules/FindJansson.cmake
blob: feed563be0536027fd5dba27dd075b8a8eacee70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# .rst
# FindJansson
# -----------
#
# Find Jansson library and headers
#
# The module defines the following variables:
#
# ::
#
#   Jansson_FOUND       - true if Jansson was found
#   Jansson_INCLUDE_DIR - include search path
#   Jansson_LIBRARIES   - libraries to link
#   Jansson_VERSION     - libmagic 3-component version number

if(Jansson_INCLUDE_DIRS AND Jansson_LIBRARIES)
  set(Jansson_FOUND TRUE)
else()
  find_package(PkgConfig QUIET)
  pkg_check_modules(PC_JANSSON QUIET jansson)

  find_path(Jansson_INCLUDE_DIR
            NAMES
              jansson.h
            HINTS
              ${PC_JANSSON_INCLUDEDIR}
              ${PC_JANSSON_INCLUDE_DIRS}
              ${CMAKE_INSTALL_FULL_INCLUDEDIR})
  find_library(Jansson_LIBRARIES
               NAMES
                 jansson
                 libjansson
               HINTS
                 ${PC_JANSSON_LIBDIR}
                 ${PC_JANSSON_LIBRARY_DIRS}
                 ${CMAKE_INSTALL_FULL_LIBDIR})

  if(Jansson_INCLUDE_DIR AND EXISTS "${Jansson_INCLUDE_DIR}/jansson.h")
    file(STRINGS "${Jansson_INCLUDE_DIR}/jansson.h" jansson_version_str
         REGEX "^#[ ]*define[ ]+JANSSON_VERSION[ ]+\".*\"")
    string(REGEX
           REPLACE "^[ ]*define[ ]+JANSSON_VERSION[ ]+\"([^\"]*)\".*" "\\1"
           Jansson_VERSION_STRING "${jansson_version_str}")
    unset(jansson_version_str)
  endif()

  include(FindPackageHandleStandardArgs)
  find_package_handle_standard_args(Jansson
                                    REQUIRED_VARS
                                      Jansson_INCLUDE_DIR
                                      Jansson_LIBRARIES
                                    VERSION_VAR
                                      Jansson_VERSION_STRING)
  mark_as_advanced(Jansson_INCLUDE_DIR Jansson_LIBRARIES)
endif()