1*10ff414cSEd Maste# Fetched from https://github.com/JonathanSalwan/Triton/blob/master/CMakeModules/LibFindMacros.cmake 2*10ff414cSEd Maste# 3*10ff414cSEd Maste# Copyright: 4*10ff414cSEd Maste# 5*10ff414cSEd Maste# * Jonathan Salwan (Quarkslab) 6*10ff414cSEd Maste# * Pierrick Brunet (Quarkslab) 7*10ff414cSEd Maste# * Romain Thomas (Quarkslab) 8*10ff414cSEd Maste# * Florent Saudel (Bordeaux University) 9*10ff414cSEd Maste# 10*10ff414cSEd Maste# Licensed under the Apache License, Version 2.0 (the "License"); 11*10ff414cSEd Maste# you may not use this file except in compliance with the License. 12*10ff414cSEd Maste# You may obtain a copy of the License at 13*10ff414cSEd Maste# 14*10ff414cSEd Maste# https://www.apache.org/licenses/LICENSE-2.0 15*10ff414cSEd Maste# 16*10ff414cSEd Maste# Unless required by applicable law or agreed to in writing, software 17*10ff414cSEd Maste# distributed under the License is distributed on an "AS IS" BASIS, 18*10ff414cSEd Maste# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19*10ff414cSEd Maste# See the License for the specific language governing permissions and 20*10ff414cSEd Maste# limitations under the License. 21*10ff414cSEd Maste 22*10ff414cSEd Maste# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments 23*10ff414cSEd Maste# used for the current package. For this to work, the first parameter must be the 24*10ff414cSEd Maste# prefix of the current package, then the prefix of the new package etc, which are 25*10ff414cSEd Maste# passed to find_package. 26*10ff414cSEd Mastemacro (libfind_package PREFIX) 27*10ff414cSEd Maste set (LIBFIND_PACKAGE_ARGS ${ARGN}) 28*10ff414cSEd Maste if (${PREFIX}_FIND_QUIETLY) 29*10ff414cSEd Maste set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) 30*10ff414cSEd Maste endif (${PREFIX}_FIND_QUIETLY) 31*10ff414cSEd Maste if (${PREFIX}_FIND_REQUIRED) 32*10ff414cSEd Maste set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) 33*10ff414cSEd Maste endif (${PREFIX}_FIND_REQUIRED) 34*10ff414cSEd Maste find_package(${LIBFIND_PACKAGE_ARGS}) 35*10ff414cSEd Masteendmacro (libfind_package) 36*10ff414cSEd Maste 37*10ff414cSEd Maste# CMake developers made the UsePkgConfig system deprecated in the same release (2.6) 38*10ff414cSEd Maste# where they added pkg_check_modules. Consequently I need to support both in my scripts 39*10ff414cSEd Maste# to avoid those deprecated warnings. Here's a helper that does just that. 40*10ff414cSEd Maste# Works identically to pkg_check_modules, except that no checks are needed prior to use. 41*10ff414cSEd Mastemacro (libfind_pkg_check_modules PREFIX PKGNAME) 42*10ff414cSEd Maste if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 43*10ff414cSEd Maste include(UsePkgConfig) 44*10ff414cSEd Maste pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) 45*10ff414cSEd Maste else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 46*10ff414cSEd Maste find_package(PkgConfig) 47*10ff414cSEd Maste if (PKG_CONFIG_FOUND) 48*10ff414cSEd Maste pkg_check_modules(${PREFIX} ${PKGNAME}) 49*10ff414cSEd Maste endif (PKG_CONFIG_FOUND) 50*10ff414cSEd Maste endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 51*10ff414cSEd Masteendmacro (libfind_pkg_check_modules) 52*10ff414cSEd Maste 53*10ff414cSEd Maste# Do the final processing once the paths have been detected. 54*10ff414cSEd Maste# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain 55*10ff414cSEd Maste# all the variables, each of which contain one include directory. 56*10ff414cSEd Maste# Ditto for ${PREFIX}_PROCESS_LIBS and library files. 57*10ff414cSEd Maste# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. 58*10ff414cSEd Maste# Also handles errors in case library detection was required, etc. 59*10ff414cSEd Mastemacro (libfind_process PREFIX) 60*10ff414cSEd Maste # Skip processing if already processed during this run 61*10ff414cSEd Maste if (NOT ${PREFIX}_FOUND) 62*10ff414cSEd Maste # Start with the assumption that the library was found 63*10ff414cSEd Maste set (${PREFIX}_FOUND TRUE) 64*10ff414cSEd Maste 65*10ff414cSEd Maste # Process all includes and set _FOUND to false if any are missing 66*10ff414cSEd Maste foreach (i ${${PREFIX}_PROCESS_INCLUDES}) 67*10ff414cSEd Maste if (${i}) 68*10ff414cSEd Maste set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) 69*10ff414cSEd Maste mark_as_advanced(${i}) 70*10ff414cSEd Maste else (${i}) 71*10ff414cSEd Maste set (${PREFIX}_FOUND FALSE) 72*10ff414cSEd Maste endif (${i}) 73*10ff414cSEd Maste endforeach (i) 74*10ff414cSEd Maste 75*10ff414cSEd Maste # Process all libraries and set _FOUND to false if any are missing 76*10ff414cSEd Maste foreach (i ${${PREFIX}_PROCESS_LIBS}) 77*10ff414cSEd Maste if (${i}) 78*10ff414cSEd Maste set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) 79*10ff414cSEd Maste mark_as_advanced(${i}) 80*10ff414cSEd Maste else (${i}) 81*10ff414cSEd Maste set (${PREFIX}_FOUND FALSE) 82*10ff414cSEd Maste endif (${i}) 83*10ff414cSEd Maste endforeach (i) 84*10ff414cSEd Maste 85*10ff414cSEd Maste # Print message and/or exit on fatal error 86*10ff414cSEd Maste if (${PREFIX}_FOUND) 87*10ff414cSEd Maste if (NOT ${PREFIX}_FIND_QUIETLY) 88*10ff414cSEd Maste message (STATUS "Found ${PREFIX} include directory: ${${PREFIX}_INCLUDE_DIR}") 89*10ff414cSEd Maste message (STATUS "Found ${PREFIX} library: ${${PREFIX}_LIBRARY}") 90*10ff414cSEd Maste endif (NOT ${PREFIX}_FIND_QUIETLY) 91*10ff414cSEd Maste else (${PREFIX}_FOUND) 92*10ff414cSEd Maste if (${PREFIX}_FIND_REQUIRED) 93*10ff414cSEd Maste foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) 94*10ff414cSEd Maste message("${i}=${${i}}") 95*10ff414cSEd Maste endforeach (i) 96*10ff414cSEd Maste 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.") 97*10ff414cSEd Maste endif (${PREFIX}_FIND_REQUIRED) 98*10ff414cSEd Maste endif (${PREFIX}_FOUND) 99*10ff414cSEd Maste endif (NOT ${PREFIX}_FOUND) 100*10ff414cSEd Masteendmacro (libfind_process) 101*10ff414cSEd Maste 102*10ff414cSEd Mastemacro(libfind_library PREFIX basename) 103*10ff414cSEd Maste set(TMP "") 104*10ff414cSEd Maste if(MSVC80) 105*10ff414cSEd Maste set(TMP -vc80) 106*10ff414cSEd Maste endif(MSVC80) 107*10ff414cSEd Maste if(MSVC90) 108*10ff414cSEd Maste set(TMP -vc90) 109*10ff414cSEd Maste endif(MSVC90) 110*10ff414cSEd Maste set(${PREFIX}_LIBNAMES ${basename}${TMP}) 111*10ff414cSEd Maste if(${ARGC} GREATER 2) 112*10ff414cSEd Maste set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) 113*10ff414cSEd Maste string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) 114*10ff414cSEd Maste set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) 115*10ff414cSEd Maste endif(${ARGC} GREATER 2) 116*10ff414cSEd Maste find_library(${PREFIX}_LIBRARY 117*10ff414cSEd Maste NAMES ${${PREFIX}_LIBNAMES} 118*10ff414cSEd Maste PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} 119*10ff414cSEd Maste ) 120*10ff414cSEd Masteendmacro(libfind_library) 121