Search code examples
macoscmakemacports

cmake cannot find glib2


On OS X 10.8.2, I have macports and have installed:

glib2
pkg-config

among other things. The cmake I run tries to use pkg-config to find glib2. Running pkg-config --libs glib-2.0:

-L/opt/local/lib -lglib-2.0 -lintl

and --cflags:

-I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include

Yet, when I try to enter these in (individually, or all of them using ; or :), and all sorts of combinations, or when I tried downloading gtk and using the glib2 dirs of that: cmake complains it can't find the directories:

checking for module 'gstreamer-0.10'
  found gstreamer-0.10, version 0.10.36
checking for module 'glib-2.0'
  found glib-2.0, version 2.34.3
CMake Error at /Applications/CMake 2.8-10.app/Contents/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (message):
  Could NOT find GLib2 (missing: GLIB2_LIBDIR GLIB2_INCLUDE_DIRS)
Call Stack (most recent call first):
  /Applications/CMake 2.8-10.app/Contents/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:291 (_FPHSA_FAILURE_MESSAGE)
  cmake/Modules/FindGLib2.cmake:127 (find_package_handle_standard_args)
  cmake/Modules/FindGStreamer.cmake:12 (find_package)
  CMakeLists.txt:32 (find_package)

I saw this page about conflicting pkg-config's with MonoDevelop. I uninstalled Mono, don't have any other pkg-config binaries that I can find, and cleared the cmake cache without any luck. I've looked at the cmake specifics, and its looking for glib.h and glibconfig.h, which are in those directories. Why can't it just behave?


Solution

  • Try to use this file: http://svn.opensync.org/branches/3rd-party-cmake-modules/modules/FindGLIB2.cmake

    In your main CMakeLists.txt file, enter the following line:

    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/helper/")
    

    This is assuming that the above FindGLIB2.cmake is stored in directory /helper off the src.

    The contents of this file will help CMake to better find GLIB2.

    This link will help you understand how these files work: http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries#Writing_find_modules