• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# - Try to find jansson
2# Once done this will define
3#  JANSSON_FOUND        - System has jansson
4#  JANSSON_INCLUDE_DIRS - The jansson include directories
5#  JANSSON_LIBRARIES    - The libraries needed to use jansson
6
7find_package(PkgConfig QUIET)
8pkg_check_modules(PC_JANSSON QUIET jansson)
9
10find_path(JANSSON_INCLUDE_DIR
11  NAMES jansson.h
12  HINTS ${PC_JANSSON_INCLUDE_DIRS}
13)
14find_library(JANSSON_LIBRARY
15  NAMES jansson
16  HINTS ${PC_JANSSON_LIBRARY_DIRS}
17)
18
19if(JANSSON_INCLUDE_DIR)
20  set(_version_regex "^#define[ \t]+JANSSON_VERSION[ \t]+\"([^\"]+)\".*")
21  file(STRINGS "${JANSSON_INCLUDE_DIR}/jansson.h"
22    JANSSON_VERSION REGEX "${_version_regex}")
23  string(REGEX REPLACE "${_version_regex}" "\\1"
24    JANSSON_VERSION "${JANSSON_VERSION}")
25  unset(_version_regex)
26endif()
27
28include(FindPackageHandleStandardArgs)
29# handle the QUIETLY and REQUIRED arguments and set JANSSON_FOUND to TRUE
30# if all listed variables are TRUE and the requested version matches.
31find_package_handle_standard_args(Jansson REQUIRED_VARS
32                                  JANSSON_LIBRARY JANSSON_INCLUDE_DIR
33                                  VERSION_VAR JANSSON_VERSION)
34
35if(JANSSON_FOUND)
36  set(JANSSON_LIBRARIES     ${JANSSON_LIBRARY})
37  set(JANSSON_INCLUDE_DIRS  ${JANSSON_INCLUDE_DIR})
38endif()
39
40mark_as_advanced(JANSSON_INCLUDE_DIR JANSSON_LIBRARY)
41