terom@6: # Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments terom@6: # used for the current package. For this to work, the first parameter must be the terom@6: # prefix of the current package, then the prefix of the new package etc, which are terom@6: # passed to find_package. terom@6: macro (libfind_package PREFIX) terom@6: set (LIBFIND_PACKAGE_ARGS ${ARGN}) terom@6: if (${PREFIX}_FIND_QUIETLY) terom@6: set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) terom@6: endif (${PREFIX}_FIND_QUIETLY) terom@6: if (${PREFIX}_FIND_REQUIRED) terom@6: set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) terom@6: endif (${PREFIX}_FIND_REQUIRED) terom@6: find_package(${LIBFIND_PACKAGE_ARGS}) terom@6: endmacro (libfind_package) terom@6: terom@6: # Damn CMake developers made the UsePkgConfig system deprecated in the same release (2.6) terom@6: # where they added pkg_check_modules. Consequently I need to support both in my scripts terom@6: # to avoid those deprecated warnings. Here's a helper that does just that. terom@6: # Works identically to pkg_check_modules, except that no checks are needed prior to use. terom@6: macro (libfind_pkg_check_modules PREFIX PKGNAME) terom@6: if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) terom@6: include(UsePkgConfig) terom@6: pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) terom@6: else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) terom@6: find_package(PkgConfig) terom@6: if (PKG_CONFIG_FOUND) terom@6: pkg_check_modules(${PREFIX} ${PKGNAME}) terom@6: endif (PKG_CONFIG_FOUND) terom@6: endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) terom@6: endmacro (libfind_pkg_check_modules) terom@6: terom@6: # Do the final processing once the paths have been detected. terom@6: # If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain terom@6: # all the variables, each of which contain one include directory. terom@6: # Ditto for ${PREFIX}_PROCESS_LIBS and library files. terom@6: # Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. terom@6: # Also handles errors in case library detection was required, etc. terom@6: macro (libfind_process PREFIX) terom@6: # Skip processing if already processed during this run terom@6: if (NOT ${PREFIX}_FOUND) terom@6: # Start with the assumption that the library was found terom@6: set (${PREFIX}_FOUND TRUE) terom@6: terom@6: # Process all includes and set _FOUND to false if any are missing terom@6: foreach (i ${${PREFIX}_PROCESS_INCLUDES}) terom@6: if (${i}) terom@6: set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) saiam@9: mark_as_advanced(${i}) terom@6: else (${i}) terom@6: set (${PREFIX}_FOUND FALSE) terom@6: endif (${i}) terom@6: endforeach (i) terom@6: terom@6: # Process all libraries and set _FOUND to false if any are missing terom@6: foreach (i ${${PREFIX}_PROCESS_LIBS}) terom@6: if (${i}) terom@6: set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) saiam@9: mark_as_advanced(${i}) terom@6: else (${i}) terom@6: set (${PREFIX}_FOUND FALSE) terom@6: endif (${i}) terom@6: endforeach (i) terom@6: terom@6: # Print message and/or exit on fatal error terom@6: if (${PREFIX}_FOUND) terom@6: if (NOT ${PREFIX}_FIND_QUIETLY) saiam@9: message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") terom@6: endif (NOT ${PREFIX}_FIND_QUIETLY) terom@6: else (${PREFIX}_FOUND) terom@6: if (${PREFIX}_FIND_REQUIRED) terom@6: foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) terom@6: message("${i}=${${i}}") terom@6: endforeach (i) terom@6: 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.") terom@6: endif (${PREFIX}_FIND_REQUIRED) terom@6: endif (${PREFIX}_FOUND) terom@6: endif (NOT ${PREFIX}_FOUND) terom@6: endmacro (libfind_process) terom@6: saiam@9: macro(libfind_library PREFIX basename) saiam@9: set(TMP "") saiam@9: if(MSVC80) saiam@9: set(TMP -vc80) saiam@9: endif(MSVC80) saiam@9: if(MSVC90) saiam@9: set(TMP -vc90) saiam@9: endif(MSVC90) saiam@9: set(${PREFIX}_LIBNAMES ${basename}${TMP}) saiam@9: if(${ARGC} GREATER 2) saiam@9: set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) saiam@9: string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) saiam@9: set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) saiam@9: endif(${ARGC} GREATER 2) saiam@9: find_library(${PREFIX}_LIBRARY saiam@9: NAMES ${${PREFIX}_LIBNAMES} saiam@9: PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} saiam@9: ) saiam@9: endmacro(libfind_library) saiam@9: