1 # Copyright (c) 2016 WorkWare Systems http://www.workware.net.au/
6 # The 'pkg-config' module allows package information to be found via 'pkg-config'.
8 # If not cross-compiling, the package path should be determined automatically
10 # If cross-compiling, the default package path is the compiler sysroot.
11 # If the C compiler doesn't support '-print-sysroot', the path can be supplied
12 # by the '--sysroot' option or by defining 'SYSROOT'.
14 # 'PKG_CONFIG' may be set to use an alternative to 'pkg-config'.
19 sysroot
:dir
=> "Override compiler sysroot for pkg-config search path"
22 # @pkg-config-init ?required?
24 # Initialises the 'pkg-config' system. Unless '$required' is set to 0,
25 # it is a fatal error if a usable 'pkg-config' is not found .
27 # This command will normally be called automatically as required,
28 # but it may be invoked explicitly if lack of 'pkg-config' is acceptable.
30 # Returns 1 if ok, or 0 if 'pkg-config' not found/usable (only if '$required' is 0).
32 proc pkg-config-init
{{required
1}} {
33 if {[is-defined HAVE_PKG_CONFIG
]} {
34 return [get-define HAVE_PKG_CONFIG
]
38 define PKG_CONFIG
[get-env PKG_CONFIG pkg-config
]
39 msg-checking
"Checking for pkg-config..."
41 if {[catch {exec [get-define PKG_CONFIG
] --version} version
]} {
42 msg-result
"[get-define PKG_CONFIG] (not found)"
44 user-error
"No usable pkg-config"
48 define PKG_CONFIG_VERSION
$version
52 if {[opt-str sysroot o
]} {
53 define SYSROOT
[file-normalize
$o]
54 msg-result
"Using specified sysroot [get-define SYSROOT]"
55 } elseif
{[get-define build
] ne
[get-define host
]} {
56 if {[catch {exec-with-stderr
[get-define CC
] -print-sysroot
} result errinfo
] == 0} {
57 # Use the compiler sysroot, if there is one
58 define SYSROOT
$result
59 msg-result
"Found compiler sysroot $result"
61 set msg
"pkg-config: Cross compiling, but no compiler sysroot and no --sysroot supplied"
70 if {[is-defined SYSROOT
]} {
71 set sysroot
[get-define SYSROOT
]
73 # XXX: It's possible that these should be set only when invoking pkg-config
75 set env
(PKG_CONFIG_DIR
) ""
76 # Do we need to try /usr/local as well or instead?
77 set env
(PKG_CONFIG_LIBDIR
) $sysroot/usr
/lib
/pkgconfig
:$sysroot/usr
/share
/pkgconfig
78 set env
(PKG_CONFIG_SYSROOT_DIR
) $sysroot
81 define HAVE_PKG_CONFIG
$found
85 # @pkg-config module ?requirements?
87 # Use 'pkg-config' to find the given module meeting the given requirements.
90 ## pkg-config pango >= 1.37.0
92 # If found, returns 1 and sets 'HAVE_PKG_PANGO' to 1 along with:
94 ## PKG_PANGO_VERSION to the found version
95 ## PKG_PANGO_LIBS to the required libs (--libs-only-l)
96 ## PKG_PANGO_LDFLAGS to the required linker flags (--libs-only-L)
97 ## PKG_PANGO_CFLAGS to the required compiler flags (--cflags)
99 # If not found, returns 0.
101 proc pkg-config
{module args
} {
102 set ok
[pkg-config-init
]
104 msg-checking
"Checking for $module $args..."
107 msg-result
"no pkg-config"
111 if {[catch {exec [get-define PKG_CONFIG
] --modversion "$module $args"} version
]} {
112 msg-result
"not found"
113 configlog
"pkg-config --modversion $module $args: $version"
117 set prefix
[feature-define-name
$module PKG_
]
118 define HAVE_
${prefix
}
119 define
${prefix
}_VERSION
$version
120 define
${prefix
}_LIBS
[exec pkg-config
--libs-only
-l
$module]
121 define
${prefix
}_LDFLAGS
[exec pkg-config
--libs-only
-L
$module]
122 define
${prefix
}_CFLAGS
[exec pkg-config
--cflags $module]
126 # @pkg-config-get module setting
128 # Convenience access to the results of 'pkg-config'.
130 # For example, '[pkg-config-get pango CFLAGS]' returns
131 # the value of 'PKG_PANGO_CFLAGS', or '""' if not defined.
132 proc pkg-config-get
{module name
} {
133 set prefix
[feature-define-name
$module PKG_
]
134 get-define
${prefix
}_
${name
} ""