-
Notifications
You must be signed in to change notification settings - Fork 1
/
FindPrereqs.cmake
84 lines (65 loc) · 2.94 KB
/
FindPrereqs.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# Copyright © 2015, RedJack, LLC.
# All rights reserved.
#
# Please see the COPYING file in this distribution for license details.
# ----------------------------------------------------------------------
#-----------------------------------------------------------------------
# Configuration options that control all of the below
set(PKG_CONFIG_PATH CACHE STRING "pkg-config search path")
if (PKG_CONFIG_PATH)
set(ENV{PKG_CONFIG_PATH} "${PKG_CONFIG_PATH}:$ENV{PKG_CONFIG_PATH}")
endif (PKG_CONFIG_PATH)
#-----------------------------------------------------------------------
# pkg-config prerequisites
find_package(PkgConfig)
function(pkgconfig_prereq DEP)
set(options OPTIONAL)
set(one_args)
set(multi_args)
cmake_parse_arguments(_ "${options}" "${one_args}" "${multi_args}" ${ARGN})
string(REGEX REPLACE "[<>=].*" "" SHORT_NAME "${DEP}")
string(REPLACE "-" "_" SHORT_NAME "${SHORT_NAME}")
string(TOUPPER ${SHORT_NAME} UPPER_SHORT_NAME)
string(TOLOWER ${SHORT_NAME} LOWER_SHORT_NAME)
set(USE_CUSTOM_${UPPER_SHORT_NAME} NO CACHE BOOL
"Whether you want to provide custom details for ${LOWER_SHORT_NAME}")
if (NOT USE_CUSTOM_${UPPER_SHORT_NAME})
set(PKG_CHECK_ARGS)
if (NOT __OPTIONAL)
list(APPEND PKG_CHECK_ARGS REQUIRED)
endif (NOT __OPTIONAL)
list(APPEND PKG_CHECK_ARGS ${DEP})
pkg_check_modules(${UPPER_SHORT_NAME} ${PKG_CHECK_ARGS})
endif (NOT USE_CUSTOM_${UPPER_SHORT_NAME})
include_directories(${${UPPER_SHORT_NAME}_INCLUDE_DIRS})
link_directories(${${UPPER_SHORT_NAME}_LIBRARY_DIRS})
endfunction(pkgconfig_prereq)
#-----------------------------------------------------------------------
# find_library prerequisites
function(library_prereq LIB_NAME)
set(options OPTIONAL)
set(one_args)
set(multi_args)
cmake_parse_arguments(_ "${options}" "${one_args}" "${multi_args}" ${ARGN})
string(REPLACE "-" "_" SHORT_NAME "${LIB_NAME}")
string(TOUPPER ${SHORT_NAME} UPPER_SHORT_NAME)
string(TOLOWER ${SHORT_NAME} LOWER_SHORT_NAME)
set(USE_CUSTOM_${UPPER_SHORT_NAME} NO CACHE BOOL
"Whether you want to provide custom details for ${LOWER_SHORT_NAME}")
if (USE_CUSTOM_${UPPER_SHORT_NAME})
include_directories(${${UPPER_SHORT_NAME}_INCLUDE_DIRS})
link_directories(${${UPPER_SHORT_NAME}_LIBRARY_DIRS})
if (NOT ${UPPER_SHORT_NAME}_STATIC_LDFLAGS)
set(${UPPER_SHORT_NAME}_STATIC_LDFLAGS
${${UPPER_SHORT_NAME}_LDFLAGS}
PARENT_SCOPE)
endif (NOT ${UPPER_SHORT_NAME}_STATIC_LDFLAGS)
else (USE_CUSTOM_${UPPER_SHORT_NAME})
find_library(${UPPER_SHORT_NAME}_LDFLAGS ${LIB_NAME})
set(${UPPER_SHORT_NAME}_STATIC_LDFLAGS
${${UPPER_SHORT_NAME}_LDFLAGS}
PARENT_SCOPE)
endif (USE_CUSTOM_${UPPER_SHORT_NAME})
endfunction(library_prereq)