FindGLIB2.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # - Try to find the GLIB2 libraries
  2. # Once done this will define
  3. #
  4. # GLIB2_FOUND - system has glib2
  5. # GLIB2_INCLUDE_DIR - the glib2 include directory
  6. # GLIB2_LIBRARIES - glib2 library
  7. # Copyright (c) 2008 Laurent Montel, <montel@kde.org>
  8. #
  9. # Redistribution and use is allowed according to the terms of the BSD license.
  10. # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
  11. if(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES)
  12. # Already in cache, be silent
  13. set(GLIB2_FIND_QUIETLY TRUE)
  14. endif(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES)
  15. find_package(PkgConfig)
  16. pkg_check_modules(PC_LibGLIB2 QUIET glib-2.0)
  17. find_path(GLIB2_MAIN_INCLUDE_DIR
  18. NAMES glib.h
  19. HINTS ${PC_LibGLIB2_INCLUDEDIR}
  20. PATH_SUFFIXES glib-2.0)
  21. find_library(GLIB2_LIBRARY
  22. NAMES glib-2.0
  23. HINTS ${PC_LibGLIB2_LIBDIR}
  24. )
  25. set(GLIB2_LIBRARIES ${GLIB2_LIBRARY})
  26. # search the glibconfig.h include dir under the same root where the library is found
  27. get_filename_component(glib2LibDir "${GLIB2_LIBRARIES}" PATH)
  28. find_path(GLIB2_INTERNAL_INCLUDE_DIR glibconfig.h
  29. PATH_SUFFIXES glib-2.0/include
  30. HINTS ${PC_LibGLIB2_INCLUDEDIR} "${glib2LibDir}" ${CMAKE_SYSTEM_LIBRARY_PATH})
  31. set(GLIB2_INCLUDE_DIR "${GLIB2_MAIN_INCLUDE_DIR}")
  32. # not sure if this include dir is optional or required
  33. # for now it is optional
  34. if(GLIB2_INTERNAL_INCLUDE_DIR)
  35. set(GLIB2_INCLUDE_DIR ${GLIB2_INCLUDE_DIR} "${GLIB2_INTERNAL_INCLUDE_DIR}")
  36. endif(GLIB2_INTERNAL_INCLUDE_DIR)
  37. include(FindPackageHandleStandardArgs)
  38. find_package_handle_standard_args(GLIB2 DEFAULT_MSG GLIB2_LIBRARIES GLIB2_MAIN_INCLUDE_DIR)
  39. mark_as_advanced(GLIB2_INCLUDE_DIR GLIB2_LIBRARIES)