Use CMake to find GTK2 headers and libraries
authorSteffen Pankratz <kratz00@gmx.de>
Fri, 01 May 2015 13:56:40 +0200
changeset 881 1fa99479169e
parent 880 f948cd94b3b3
child 882 2ed29bdb4561
Use CMake to find GTK2 headers and libraries
CMakeLists.txt
--- a/CMakeLists.txt	Thu Jun 18 13:45:12 2015 -0400
+++ b/CMakeLists.txt	Fri May 01 13:56:40 2015 +0200
@@ -24,7 +24,7 @@
     PROJECT(MojoSetup CXX)
 ENDIF(NOT BEOS)
 
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
 
 # !!! FIXME: correct this to new policy and bump minimum cmake requirement.
 IF(COMMAND CMAKE_POLICY)
@@ -497,30 +497,28 @@
 IF(UNIX)
 IF(NOT BEOS)
 IF(NOT MACOSX)
-#FIND_PACKAGE(PkgConfig)
-#PKGCONFIG(libgtk-2.0 LIBGTK_INCLUDE_DIR LIBGTK_LINK_DIR LIBGTK_LINK_FLAGS LIBGTK_CFLAGS)
-# !!! FIXME
+FIND_PACKAGE(GTK2 REQUIRED gtk)
+# In order to reduce the GTK2 library dependencies at link time, we only link against 'gtk-x11-2.0'.
+# This is more portable, as the dynamic linker/loader will take care of the other library dependencies at run time.
 SET(LIBGTK_LINK_FLAGS "-lgtk-x11-2.0")
-SET(LIBGTK_CFLAGS "-DPNG_NO_MMX_CODE -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12")
-IF(NOT LIBGTK_LINK_FLAGS)
+IF(NOT GTK2_FOUND)
     MESSAGE(STATUS "Can't find GTK+v2 headers/libraries. Can't build GTK+ GUI.")
-ELSE(NOT LIBGTK_LINK_FLAGS)
+ELSE(NOT GTK2_FOUND)
     OPTION(MOJOSETUP_GUI_GTKPLUS2 "Enable GTK+ 2.0 GUI" TRUE)
     IF(MOJOSETUP_GUI_GTKPLUS2)
         ADD_DEFINITIONS(-DSUPPORT_GUI_GTKPLUS2=1)
-        #INCLUDE_DIRECTORIES(${LIBGTK_INCLUDE_DIR})
+        INCLUDE_DIRECTORIES(${GTK2_INCLUDE_DIRS})
         OPTION(MOJOSETUP_GUI_GTKPLUS2_STATIC "Statically link GTK+ GUI" FALSE)
         IF(MOJOSETUP_GUI_GTKPLUS2_STATIC)
-            ADD_DEFINITIONS(-DGUI_STATIC_LINK_GTKPLUS2=1 ${LIBGTK_CFLAGS})
+            ADD_DEFINITIONS(-DGUI_STATIC_LINK_GTKPLUS2=1)
             SET(OPTIONAL_SRCS ${OPTIONAL_SRCS} gui_gtkplus2.c)
             SET(OPTIONAL_LIBS ${OPTIONAL_LIBS} ${LIBGTK_LINK_FLAGS})
         ELSE(MOJOSETUP_GUI_GTKPLUS2_STATIC)
             MOJOSETUP_ADD_LIBRARY(mojosetupgui_gtkplus2 gui_gtkplus2.c)
-            ADD_DEFINITIONS(${LIBGTK_CFLAGS})
             TARGET_LINK_LIBRARIES(mojosetupgui_gtkplus2 ${LIBGTK_LINK_FLAGS})
         ENDIF(MOJOSETUP_GUI_GTKPLUS2_STATIC)
     ENDIF(MOJOSETUP_GUI_GTKPLUS2)
-ENDIF(NOT LIBGTK_LINK_FLAGS)
+ENDIF(NOT GTK2_FOUND)
 ENDIF(NOT MACOSX)
 ENDIF(NOT BEOS)
 ENDIF(UNIX)