FindGio.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # cmake-format: off
  2. # * Try to find Gio Once done this will define
  3. #
  4. # GIO_FOUND - system has Gio GIO_INCLUDE_DIRS - the Gio include directory
  5. # GIO_LIBRARIES - the libraries needed to use Gio GIO_DEFINITIONS - Compiler
  6. # switches required for using Gio
  7. # Use pkg-config to get the directories and then use these values in the
  8. # find_path() and find_library() calls
  9. # cmake-format: on
  10. find_package(PkgConfig QUIET)
  11. if(PKG_CONFIG_FOUND)
  12. pkg_check_modules(_GIO gio-2.0 gio-unix-2.0)
  13. endif()
  14. find_path(
  15. GIO_INCLUDE_DIR
  16. NAMES gio.h
  17. HINTS ${_GIO_INCLUDE_DIRS}
  18. PATHS /usr/include /usr/local/include /opt/local/include /sw/include
  19. PATH_SUFFIXES glib-2.0/gio/)
  20. find_library(
  21. GIO_LIB
  22. NAMES gio-2.0 libgio-2.0 gio-unix-2.0
  23. HINTS ${_GIO_LIBRARY_DIRS}
  24. PATHS /usr/lib /usr/local/lib /opt/local/lib /sw/lib)
  25. include(FindPackageHandleStandardArgs)
  26. find_package_handle_standard_args(Gio REQUIRED_VARS GIO_LIB GIO_INCLUDE_DIR)
  27. mark_as_advanced(GIO_INCLUDE_DIR GIO_LIB)
  28. if(GIO_FOUND)
  29. set(GIO_INCLUDE_DIRS ${GIO_INCLUDE_DIR})
  30. set(GIO_LIBRARIES ${GIO_LIB})
  31. if(NOT TARGET GIO::GIO)
  32. if(IS_ABSOLUTE "${GIO_LIBRARIES}")
  33. add_library(GIO::GIO UNKNOWN IMPORTED)
  34. set_target_properties(GIO::GIO PROPERTIES IMPORTED_LOCATION "${GIO_LIBRARIES}")
  35. else()
  36. add_library(GIO::GIO INTERFACE IMPORTED)
  37. set_target_properties(GIO::GIO PROPERTIES IMPORTED_LIBNAME "${GIO_LIBRARIES}")
  38. endif()
  39. # Special case for gio, as both the
  40. set_target_properties(GIO::GIO PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_GIO_INCLUDE_DIRS}")
  41. target_compile_options(GIO::GIO INTERFACE ${_GIO_CFLAGS})
  42. endif()
  43. endif()