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