FindGLib.cmake 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if (NOT WIN32)
  16. find_package(PkgConfig QUIET)
  17. if (PKG_CONFIG_FOUND)
  18. pkg_check_modules(PKG_GLIB QUIET glib-2.0)
  19. endif ()
  20. endif (NOT WIN32)
  21. find_path(GLIB2_MAIN_INCLUDE_DIR glib.h
  22. PATH_SUFFIXES glib-2.0
  23. HINTS ${PKG_GLIB_INCLUDE_DIRS} ${PKG_GLIB_INCLUDEDIR})
  24. # search the glibconfig.h include dir under the same root where the library is found
  25. find_library(GLIB2_LIBRARIES
  26. NAMES glib-2.0
  27. HINTS ${PKG_GLIB_LIBRARY_DIRS} ${PKG_GLIB_LIBDIR})
  28. find_path(GLIB2_INTERNAL_INCLUDE_DIR glibconfig.h
  29. PATH_SUFFIXES glib-2.0/include ../lib/glib-2.0/include
  30. HINTS ${PKG_GLIB_INCLUDE_DIRS} ${PKG_GLIB_LIBRARIES} ${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)
  40. find_program(GLIB2_GENMARSHAL_UTIL glib-genmarshal)
  41. macro(glib2_genmarshal output_name)
  42. file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/genmarshal_tmp)
  43. foreach (_declaration ${ARGN})
  44. file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/genmarshal_tmp "${_declaration}\n")
  45. endforeach ()
  46. add_custom_command(
  47. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${output_name}.h ${CMAKE_CURRENT_BINARY_DIR}/${output_name}.c
  48. COMMAND ${GLIB2_GENMARSHAL_UTIL} --header genmarshal_tmp > ${output_name}.h
  49. COMMAND ${GLIB2_GENMARSHAL_UTIL} --body genmarshal_tmp > ${output_name}.c
  50. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  51. )
  52. endmacro()