Code

Cmake: Improve Gtkmm dependency checking, add new files to CMakeLists.txts, remove...
[inkscape.git] / CMakeScripts / FindGtkMM.cmake
1 # - Try to find GtkMM (glibmm-2.4 gdkmm-2.4 pangomm-1.4 atkmm-1.6)
2 #  Where not going to find gtk+-2.0 as this is covered using FindGTK2
3 # Once done this will define
4 #
5 #  GTKMM_FOUND - system has GtkMM
6 #  GTKMM_INCLUDE_DIRS - the GtkMM include directory
7 #  GTKMM_LIBRARIES - Link these to use GtkMM
8 #  GTKMM_DEFINITIONS - Compiler switches required for using GtkMM
9 #
10 #  Copyright (c) 2008 Joshua L. Blocher <verbalshadow@gmail.com>
11 #
12 #  Redistribution and use is allowed according to the terms of the New
13 #  BSD license.
14 #  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
15 #
16 SET(SubLibs
17 gtkmm-2.4
18 glibmm-2.4
19 gdkmm-2.4
20 pangomm-1.4
21 atkmm-1.6
22 )
23 \r
24 if (GTKMM_LIBRARIES AND GTKMM_INCLUDE_DIRS)
25   # in cache already
26   set(GTKMM_FOUND TRUE)
27 else (GTKMM_LIBRARIES AND GTKMM_INCLUDE_DIRS)
28 FOREACH(_SUBLIB ${SubLibs})
29   # Clean library name for header file
30   STRING(REGEX REPLACE "[-]([^ ]+)" "" _H_${_SUBLIB}  "${_SUBLIB}" )
31   # use pkg-config to get the directories and then use these values
32   # in the FIND_PATH() and FIND_LIBRARY() calls
33   if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
34     include(UsePkgConfig)
35     pkgconfig(${_SUBLIB} _${_SUBLIB}_INCLUDEDIR _${_SUBLIB}_LIBDIR _${_SUBLIB}_LDFLAGS _${_SUBLIB}_CFLAGS)
36   else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
37     find_package(PkgConfig)
38     if (PKG_CONFIG_FOUND)
39       pkg_check_modules(_${_SUBLIB} ${_SUBLIB})
40     endif (PKG_CONFIG_FOUND)
41   endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
42   find_path(${_SUBLIB}_INCLUDE_DIR
43     NAMES
44       ${_H_${_SUBLIB}}.h
45     PATHS
46       ${_${_SUBLIB}_INCLUDEDIR}
47       /usr/include
48       /usr/local/include
49       /opt/local/include
50       /sw/include
51     PATH_SUFFIXES
52       ${_SUBLIB}
53   )
55   find_library(${_SUBLIB}_LIBRARY
56     NAMES
57       ${_SUBLIB}
58     PATHS
59       ${_${_SUBLIB}_LIBDIR}
60       /usr/lib
61       /usr/local/lib
62       /opt/local/lib
63       /sw/lib
64   )
66   if (${_SUBLIB}_LIBRARY)
67     set(${_SUBLIB}_FOUND TRUE)
68   endif (${_SUBLIB}_LIBRARY)
70   LIST(APPEND GTKMM_INCLUDE_DIRS
71     ${${_SUBLIB}_INCLUDE_DIR}
72   )
74   if (${_SUBLIB}_FOUND)
75     LIST(APPEND GTKMM_LIBRARIES
76       ${${_SUBLIB}_LIBRARIES}
77       ${${_SUBLIB}_LIBRARY}
78     )
79   endif (${_SUBLIB}_FOUND)
80 ENDFOREACH(_SUBLIB)
82   if (GTKMM_INCLUDE_DIRS AND GTKMM_LIBRARIES)
83      set(GTKMM_FOUND TRUE)
84   endif (GTKMM_INCLUDE_DIRS AND GTKMM_LIBRARIES)
86   if (GTKMM_FOUND)
87     if (NOT GtkMM_FIND_QUIETLY)
88       message(STATUS "Found GtkMM: ${GTKMM_LIBRARIES}")
89     endif (NOT GtkMM_FIND_QUIETLY)
90   else (GTKMM_FOUND)
91     if (GtkMM_FIND_REQUIRED)
92       message(FATAL_ERROR "Could not find GtkMM")
93     endif (GtkMM_FIND_REQUIRED)
94   endif (GTKMM_FOUND)
96   # show the GTKMM_INCLUDE_DIRS and GTKMM_LIBRARIES variables only in the advanced view
97   mark_as_advanced(GTKMM_INCLUDE_DIRS GTKMM_LIBRARIES)
99 endif (GTKMM_LIBRARIES AND GTKMM_INCLUDE_DIRS)