diff options
author | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-07-19 08:41:04 -0400 |
---|---|---|
committer | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-07-19 08:41:04 -0400 |
commit | 299b166ff820e8413f0c34ed5a2e7afac46cd477 (patch) | |
tree | b0b8e1520af740e8a63fd132ebae82326054e12f /cmake |
initial commit
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/FindGIO.cmake | 27 | ||||
-rw-r--r-- | cmake/FindGlib.cmake | 43 | ||||
-rw-r--r-- | cmake/LibFindMacros.cmake | 76 |
3 files changed, 146 insertions, 0 deletions
diff --git a/cmake/FindGIO.cmake b/cmake/FindGIO.cmake new file mode 100644 index 0000000..c32a3bf --- /dev/null +++ b/cmake/FindGIO.cmake @@ -0,0 +1,27 @@ +# - Try to find GIO 2.0 +# Once done, this will define +# +# GIO_FOUND - system has GIO +# GIO_INCLUDE_DIRS - the GIO include directories +# GIO_LIBRARIES - link these to use GIO + +include(LibFindMacros) + +# Dependencies +libfind_package(GIO Glib) + +# Use pkg-config to get hints about paths +libfind_pkg_check_modules(GIO_PKGCONF gio-2.0) + +# Find the library +find_library(GIO_LIBRARY + NAMES gio-2.0 + PATHS ${GIO_PKGCONF_LIBRARY_DIRS} +) + +# Set the include dir variables and the libraries and let libfind_process do the rest. +# NOTE: Singular variables for this library, plural for libraries this this lib depends on. +set(GIO_PROCESS_INCLUDES Glib_INCLUDE_DIRS) +set(GIO_PROCESS_LIBS GIO_LIBRARY Glib_LIBRARIES) +libfind_process(GIO) + diff --git a/cmake/FindGlib.cmake b/cmake/FindGlib.cmake new file mode 100644 index 0000000..cddc9f0 --- /dev/null +++ b/cmake/FindGlib.cmake @@ -0,0 +1,43 @@ +find_package(PkgConfig) +pkg_check_modules(GLIB_PKG glib-2.0) + +if (GLIB_PKG_FOUND) + find_path(GLIB_INCLUDE_DIR NAMES glib.h PATH_SUFFIXES glib-2.0 + PATHS + ${GLIB_PKG_INCLUDE_DIRS} + /usr/include/glib-2.0 + /usr/include + /usr/local/include + ) + find_path(GLIB_CONFIG_INCLUDE_DIR NAMES glibconfig.h PATHS ${GLIB_PKG_LIBDIR} PATH_SUFFIXES glib-2.0/include) + + find_library(GLIB_LIBRARIES NAMES glib-2.0 + PATHS + ${GLIB_PKG_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + ) + +else (GLIB_PKG_FOUND) + # Find Glib even if pkg-config is not working (eg. cross compiling to Windows) + find_library(GLIB_LIBRARIES NAMES glib-2.0) + string (REGEX REPLACE "/[^/]*$" "" GLIB_LIBRARIES_DIR ${GLIB_LIBRARIES}) + + find_path(GLIB_INCLUDE_DIR NAMES glib.h PATH_SUFFIXES glib-2.0) + find_path(GLIB_CONFIG_INCLUDE_DIR NAMES glibconfig.h PATHS ${GLIB_LIBRARIES_DIR} PATH_SUFFIXES glib-2.0/include) + +endif (GLIB_PKG_FOUND) + +if (GLIB_INCLUDE_DIR AND GLIB_CONFIG_INCLUDE_DIR AND GLIB_LIBRARIES) + set(GLIB_INCLUDE_DIRS ${GLIB_INCLUDE_DIR} ${GLIB_CONFIG_INCLUDE_DIR}) +endif (GLIB_INCLUDE_DIR AND GLIB_CONFIG_INCLUDE_DIR AND GLIB_LIBRARIES) + +if(GLIB_INCLUDE_DIRS AND GLIB_LIBRARIES) + set(GLIB_FOUND TRUE CACHE INTERNAL "glib-2.0 found") + message(STATUS "Found glib-2.0: ${GLIB_INCLUDE_DIR}, ${GLIB_LIBRARIES}") +else(GLIB_INCLUDE_DIRS AND GLIB_LIBRARIES) + set(GLIB_FOUND FALSE CACHE INTERNAL "glib-2.0 found") + message(STATUS "glib-2.0 not found.") +endif(GLIB_INCLUDE_DIRS AND GLIB_LIBRARIES) + +mark_as_advanced(GLIB_INCLUDE_DIR GLIB_CONFIG_INCLUDE_DIR GLIB_INCLUDE_DIRS GLIB_LIBRARIES) diff --git a/cmake/LibFindMacros.cmake b/cmake/LibFindMacros.cmake new file mode 100644 index 0000000..83b68b5 --- /dev/null +++ b/cmake/LibFindMacros.cmake @@ -0,0 +1,76 @@ +# Works the same as find_package, but forwards the "REQUIRED" argument used for +# the current package and always uses the "QUIET" flag. For this to work, the +# first parameter must be the prefix of the current package, then the prefix of +# the new package etc, which are passed to find_package. +macro (libfind_package PREFIX) + set (LIBFIND_PACKAGE_ARGS ${ARGN} QUIET) + if (${PREFIX}_FIND_REQUIRED) + set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) + endif (${PREFIX}_FIND_REQUIRED) + find_package(${LIBFIND_PACKAGE_ARGS}) +endmacro (libfind_package) + +# Damn CMake developers made the UsePkgConfig system deprecated in the same release (2.6) +# where they added pkg_check_modules. Consequently I need to support both in my scripts +# to avoid those deprecated warnings. Here's a helper that does just that. +# Works identically to pkg_check_modules, except that no checks are needed prior to use. +macro (libfind_pkg_check_modules PREFIX PKGNAME) + if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + include(UsePkgConfig) + pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) + else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules(${PREFIX} ${PKGNAME}) + endif (PKG_CONFIG_FOUND) + endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) +endmacro (libfind_pkg_check_modules) + +# Do the final processing once the paths have been detected. +# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain +# all the variables, each of which contain one include directory. +# Ditto for ${PREFIX}_PROCESS_LIBS and library files. +# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. +# Also handles errors in case library detection was required, etc. +macro (libfind_process PREFIX) + # Skip processing if already processed during this run + if (NOT ${PREFIX}_FOUND) + # Start with the assumption that the library was found + set (${PREFIX}_FOUND TRUE) + + # Process all includes and set _FOUND to false if any are missing + foreach (i ${${PREFIX}_PROCESS_INCLUDES}) + if (${i}) + set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) + mark_as_advanced(${i}) + else (${i}) + set (${PREFIX}_FOUND FALSE) + endif (${i}) + endforeach (i) + + # Process all libraries and set _FOUND to false if any are missing + foreach (i ${${PREFIX}_PROCESS_LIBS}) + if (${i}) + set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) + mark_as_advanced(${i}) + else (${i}) + set (${PREFIX}_FOUND FALSE) + endif (${i}) + endforeach (i) + + # Print message and/or exit on fatal error + if (${PREFIX}_FOUND) + if (NOT ${PREFIX}_FIND_QUIETLY) + message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") + endif (NOT ${PREFIX}_FIND_QUIETLY) + else (${PREFIX}_FOUND) + if (${PREFIX}_FIND_REQUIRED) + foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) + message("${i}=${${i}}") + endforeach (i) + message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") + endif (${PREFIX}_FIND_REQUIRED) + endif (${PREFIX}_FOUND) + endif (NOT ${PREFIX}_FOUND) +endmacro (libfind_process) + |