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