|
Packit |
1fb8d4 |
# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
|
|
Packit |
1fb8d4 |
# used for the current package. For this to work, the first parameter must be the
|
|
Packit |
1fb8d4 |
# prefix of the current package, then the prefix of the new package etc, which are
|
|
Packit |
1fb8d4 |
# passed to find_package.
|
|
Packit |
1fb8d4 |
macro(libfind_package PREFIX)
|
|
Packit |
1fb8d4 |
set(LIBFIND_PACKAGE_ARGS $ {ARGN})
|
|
Packit |
1fb8d4 |
if($ {PREFIX} _FIND_QUIETLY)
|
|
Packit |
1fb8d4 |
set(LIBFIND_PACKAGE_ARGS $ {LIBFIND_PACKAGE_ARGS} QUIET)
|
|
Packit |
1fb8d4 |
endif($ {PREFIX} _FIND_QUIETLY)
|
|
Packit |
1fb8d4 |
if($ {PREFIX} _FIND_REQUIRED)
|
|
Packit |
1fb8d4 |
set(LIBFIND_PACKAGE_ARGS $ {LIBFIND_PACKAGE_ARGS} REQUIRED)
|
|
Packit |
1fb8d4 |
endif($ {PREFIX} _FIND_REQUIRED)
|
|
Packit |
1fb8d4 |
find_package($ {LIBFIND_PACKAGE_ARGS})
|
|
Packit |
1fb8d4 |
endmacro(libfind_package)
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
# CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
|
|
Packit |
1fb8d4 |
# where they added pkg_check_modules. Consequently I need to support both in my scripts
|
|
Packit |
1fb8d4 |
# to avoid those deprecated warnings. Here's a helper that does just that.
|
|
Packit |
1fb8d4 |
# Works identically to pkg_check_modules, except that no checks are needed prior to use.
|
|
Packit |
1fb8d4 |
macro (libfind_pkg_check_modules PREFIX PKGNAME)
|
|
Packit |
1fb8d4 |
if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
|
|
Packit |
1fb8d4 |
include(UsePkgConfig)
|
|
Packit |
1fb8d4 |
pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
|
|
Packit |
1fb8d4 |
else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
|
|
Packit |
1fb8d4 |
find_package(PkgConfig)
|
|
Packit |
1fb8d4 |
if (PKG_CONFIG_FOUND)
|
|
Packit |
1fb8d4 |
pkg_check_modules(${PREFIX} ${PKGNAME})
|
|
Packit |
1fb8d4 |
endif (PKG_CONFIG_FOUND)
|
|
Packit |
1fb8d4 |
endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
|
|
Packit |
1fb8d4 |
endmacro (libfind_pkg_check_modules)
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
# Do the final processing once the paths have been detected.
|
|
Packit |
1fb8d4 |
# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
|
|
Packit |
1fb8d4 |
# all the variables, each of which contain one include directory.
|
|
Packit |
1fb8d4 |
# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
|
|
Packit |
1fb8d4 |
# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
|
|
Packit |
1fb8d4 |
# Also handles errors in case library detection was required, etc.
|
|
Packit |
1fb8d4 |
macro (libfind_process PREFIX)
|
|
Packit |
1fb8d4 |
# Skip processing if already processed during this run
|
|
Packit |
1fb8d4 |
if (NOT ${PREFIX}_FOUND)
|
|
Packit |
1fb8d4 |
# Start with the assumption that the library was found
|
|
Packit |
1fb8d4 |
set (${PREFIX}_FOUND TRUE)
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
# Process all includes and set _FOUND to false if any are missing
|
|
Packit |
1fb8d4 |
foreach (i ${${PREFIX}_PROCESS_INCLUDES})
|
|
Packit |
1fb8d4 |
if (${i})
|
|
Packit |
1fb8d4 |
set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
|
|
Packit |
1fb8d4 |
mark_as_advanced(${i})
|
|
Packit |
1fb8d4 |
else (${i})
|
|
Packit |
1fb8d4 |
set (${PREFIX}_FOUND FALSE)
|
|
Packit |
1fb8d4 |
endif (${i})
|
|
Packit |
1fb8d4 |
endforeach (i)
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
# Process all libraries and set _FOUND to false if any are missing
|
|
Packit |
1fb8d4 |
foreach (i ${${PREFIX}_PROCESS_LIBS})
|
|
Packit |
1fb8d4 |
if (${i})
|
|
Packit |
1fb8d4 |
set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
|
|
Packit |
1fb8d4 |
mark_as_advanced(${i})
|
|
Packit |
1fb8d4 |
else (${i})
|
|
Packit |
1fb8d4 |
set (${PREFIX}_FOUND FALSE)
|
|
Packit |
1fb8d4 |
endif (${i})
|
|
Packit |
1fb8d4 |
endforeach (i)
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
# Print message and/or exit on fatal error
|
|
Packit |
1fb8d4 |
if (${PREFIX}_FOUND)
|
|
Packit |
1fb8d4 |
if (NOT ${PREFIX}_FIND_QUIETLY)
|
|
Packit |
1fb8d4 |
message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
|
|
Packit |
1fb8d4 |
endif (NOT ${PREFIX}_FIND_QUIETLY)
|
|
Packit |
1fb8d4 |
else (${PREFIX}_FOUND)
|
|
Packit |
1fb8d4 |
if (${PREFIX}_FIND_REQUIRED)
|
|
Packit |
1fb8d4 |
foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
|
|
Packit |
1fb8d4 |
message("${i}=${${i}}")
|
|
Packit |
1fb8d4 |
endforeach (i)
|
|
Packit |
1fb8d4 |
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.")
|
|
Packit |
1fb8d4 |
endif (${PREFIX}_FIND_REQUIRED)
|
|
Packit |
1fb8d4 |
endif (${PREFIX}_FOUND)
|
|
Packit |
1fb8d4 |
endif (NOT ${PREFIX}_FOUND)
|
|
Packit |
1fb8d4 |
endmacro (libfind_process)
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
macro(libfind_library PREFIX basename)
|
|
Packit |
1fb8d4 |
set(TMP "")
|
|
Packit |
1fb8d4 |
if(MSVC80)
|
|
Packit |
1fb8d4 |
set(TMP -vc80)
|
|
Packit |
1fb8d4 |
endif(MSVC80)
|
|
Packit |
1fb8d4 |
if(MSVC90)
|
|
Packit |
1fb8d4 |
set(TMP -vc90)
|
|
Packit |
1fb8d4 |
endif(MSVC90)
|
|
Packit |
1fb8d4 |
set(${PREFIX}_LIBNAMES ${basename}${TMP})
|
|
Packit |
1fb8d4 |
if(${ARGC} GREATER 2)
|
|
Packit |
1fb8d4 |
set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
|
|
Packit |
1fb8d4 |
string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
|
|
Packit |
1fb8d4 |
set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
|
|
Packit |
1fb8d4 |
endif(${ARGC} GREATER 2)
|
|
Packit |
1fb8d4 |
find_library(${PREFIX}_LIBRARY
|
|
Packit |
1fb8d4 |
NAMES ${${PREFIX}_LIBNAMES}
|
|
Packit |
1fb8d4 |
PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS})
|
|
Packit |
1fb8d4 |
endmacro(libfind_library)
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
SET(THREE_PART_VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+")
|
|
Packit |
1fb8d4 |
# Breaks up a string in the form n1.n2.n3 into three parts and stores
|
|
Packit |
1fb8d4 |
# them in major, minor, and patch. version should be a value, not a
|
|
Packit |
1fb8d4 |
# variable, while major, minor and patch should be variables.
|
|
Packit |
1fb8d4 |
MACRO(THREE_PART_VERSION_TO_VARS version major minor patch)
|
|
Packit |
1fb8d4 |
IF(${version} MATCHES ${THREE_PART_VERSION_REGEX})
|
|
Packit |
1fb8d4 |
STRING(REPLACE "." " " version_list ${version})
|
|
Packit |
1fb8d4 |
SEPARATE_ARGUMENTS(version_list)
|
|
Packit |
1fb8d4 |
LIST(GET version_list 0 ${major})
|
|
Packit |
1fb8d4 |
LIST(GET version_list 1 ${minor})
|
|
Packit |
1fb8d4 |
LIST(GET version_list 2 ${patch})
|
|
Packit |
1fb8d4 |
ELSE(${version} MATCHES ${THREE_PART_VERSION_REGEX})
|
|
Packit |
1fb8d4 |
MESSAGE("MACRO(THREE_PART_VERSION_TO_VARS ${version} ${major} ${minor} ${patch}")
|
|
Packit |
1fb8d4 |
MESSAGE(FATAL_ERROR "Problem parsing version string, I can't parse it properly.")
|
|
Packit |
1fb8d4 |
ENDIF(${version} MATCHES ${THREE_PART_VERSION_REGEX})
|
|
Packit |
1fb8d4 |
ENDMACRO(THREE_PART_VERSION_TO_VARS)
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
|