gtk.cmake 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Look for GTK, of any version.
  2. set(PUTTY_GTK_VERSION "ANY"
  3. CACHE STRING "Which major version of GTK to build with")
  4. set_property(CACHE PUTTY_GTK_VERSION
  5. PROPERTY STRINGS ANY 3 2 1 NONE)
  6. set(GTK_FOUND FALSE)
  7. macro(try_pkg_config_gtk VER PACKAGENAME)
  8. if(NOT GTK_FOUND AND
  9. (PUTTY_GTK_VERSION STREQUAL ANY OR PUTTY_GTK_VERSION STREQUAL ${VER}))
  10. find_package(PkgConfig)
  11. pkg_check_modules(GTK ${PACKAGENAME})
  12. if(GTK_FOUND)
  13. set(GTK_VERSION ${VER})
  14. endif()
  15. endif()
  16. endmacro()
  17. try_pkg_config_gtk(3 gtk+-3.0)
  18. try_pkg_config_gtk(2 gtk+-2.0)
  19. if(NOT GTK_FOUND AND
  20. (PUTTY_GTK_VERSION STREQUAL ANY OR PUTTY_GTK_VERSION STREQUAL 1))
  21. message("-- Checking for GTK1 (via gtk-config)")
  22. find_program(GTK_CONFIG gtk-config)
  23. if(GTK_CONFIG)
  24. execute_process(COMMAND ${GTK_CONFIG} --cflags
  25. OUTPUT_VARIABLE gtk_config_cflags
  26. OUTPUT_STRIP_TRAILING_WHITESPACE
  27. RESULT_VARIABLE gtk_config_cflags_result)
  28. execute_process(COMMAND ${GTK_CONFIG} --libs
  29. OUTPUT_VARIABLE gtk_config_libs
  30. OUTPUT_STRIP_TRAILING_WHITESPACE
  31. RESULT_VARIABLE gtk_config_libs_result)
  32. if(gtk_config_cflags_result EQUAL 0 AND gtk_config_libs_result EQUAL 0)
  33. set(GTK_INCLUDE_DIRS)
  34. set(GTK_LIBRARY_DIRS)
  35. set(GTK_LIBRARIES)
  36. separate_arguments(gtk_config_cflags NATIVE_COMMAND
  37. ${gtk_config_cflags})
  38. foreach(opt ${gtk_config_cflags})
  39. string(REGEX MATCH "^-I" ok ${opt})
  40. if(ok)
  41. string(REGEX REPLACE "^-I" "" optval ${opt})
  42. list(APPEND GTK_INCLUDE_DIRS ${optval})
  43. endif()
  44. endforeach()
  45. separate_arguments(gtk_config_libs NATIVE_COMMAND
  46. ${gtk_config_libs})
  47. foreach(opt ${gtk_config_libs})
  48. string(REGEX MATCH "^-l" ok ${opt})
  49. if(ok)
  50. list(APPEND GTK_LIBRARIES ${opt})
  51. endif()
  52. string(REGEX MATCH "^-L" ok ${opt})
  53. if(ok)
  54. string(REGEX REPLACE "^-L" "" optval ${opt})
  55. list(APPEND GTK_LIBRARY_DIRS ${optval})
  56. endif()
  57. endforeach()
  58. message("-- Found GTK1")
  59. set(GTK_FOUND TRUE)
  60. endif()
  61. endif()
  62. endif()
  63. if(GTK_FOUND)
  64. # Check for some particular Pango functions.
  65. function(pango_check_subscope)
  66. set(CMAKE_REQUIRED_INCLUDES ${GTK_INCLUDE_DIRS})
  67. set(CMAKE_REQUIRED_LINK_OPTIONS ${GTK_LDFLAGS})
  68. set(CMAKE_REQUIRED_LIBRARIES ${GTK_LIBRARIES})
  69. check_symbol_exists(pango_font_family_is_monospace "pango/pango.h"
  70. HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE)
  71. check_symbol_exists(pango_font_map_list_families "pango/pango.h"
  72. HAVE_PANGO_FONT_MAP_LIST_FAMILIES)
  73. set(HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE
  74. ${HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE} PARENT_SCOPE)
  75. set(HAVE_PANGO_FONT_MAP_LIST_FAMILIES
  76. ${HAVE_PANGO_FONT_MAP_LIST_FAMILIES} PARENT_SCOPE)
  77. check_c_source_compiles("
  78. #include <gtk/gtk.h>
  79. int f = G_APPLICATION_DEFAULT_FLAGS;
  80. int main(void) {}" HAVE_G_APPLICATION_DEFAULT_FLAGS)
  81. endfunction()
  82. pango_check_subscope()
  83. endif()