Commit Graph

83 Commits

Author SHA1 Message Date
Brad King
36979f5b43 FindPkgConfig: Tolerate PKG_CONFIG_SYSTEM_LIBRARY_PATH in environment
Tell `pkg-config --libs` not to filter out `-L` flags for entries of
`PKG_CONFIG_SYSTEM_LIBRARY_PATH` (and `LIBRARY_PATH` for `pkgconf`).
We should always search everywhere the `.pc` file expects.

Fixes: #22148
2021-07-13 10:33:16 -04:00
Alexander Neumann
94a84dc0af FindPkgConfig: add pkgconf to the search list. 2021-07-02 17:06:31 +02:00
Christopher Degawa
35d3e00e4e FindPkgConfig: split args if loaded from environment
It's common for some people to use the PKG_CONFIG environment variable
to not only load a custom pkg-config/pkgconf but also to load some
default arguments such as `--static` or `--keep-system-libs` which often
worked since shell scripts would call `$PKG_CONFIG --libs pkg` without
quotes, but this breaks FindPkgConfig since it uses the full string as
`argv[0]` and might try looking for a binary called `pkgconf --static`,
instead of looking for `pkgconf` and adding `--static` as the `argv[1]`

Additionally adds RunCMake.FindPkgConfig ARGN test case

Fixes: #22305
Signed-off-by: Christopher Degawa <ccom@randomderp.com>
2021-06-18 11:10:12 -04:00
Adam Badura
6f14205e08 FindPkgConfig: Always create the imported target
Fixes: #22180
2021-06-04 08:33:27 -04:00
Brad King
87c6fe4997 Merge topic 'FindPkgConfig-NAMES_PER_DIR'
c7bd2d0d97 FindPkgConfig: Restore preference for first pkg-config in PATH

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5914
2021-03-17 09:38:47 -04:00
Brad King
c7bd2d0d97 FindPkgConfig: Restore preference for first pkg-config in PATH
Since commit ab8bd48352 (FindPkgConfig: Search for pkg-config.bat file
on a Windows host, 2020-09-25, v3.19.0-rc1~98^2) we prefer
`pkg-config.bat` over `pkg-config` regardless of the order they appear
in the `PATH`.  Tell `find_program` to consider all names in each
directory so that the first one in `PATH` of any name wins.

Issue: #21239
2021-03-16 09:04:56 -04:00
Nikita Nemkin
8fea95319b Help: Add .. versionadded directives to module docs
Issue: #19715
2020-12-02 21:00:30 +05:00
Alexandru Croitor
ab8bd48352 FindPkgConfig: Search for pkg-config.bat file on a Windows host
The strawberry perl distribution ships a pkg-config file and a
pkg-config.bat file.

find_program() does not usually look for a .bat file program unless
explicitly specified in the NAMES argument. This would cause
CMake to find the non-bat file, and executing that with
execute_process() leads to a
'%1 is not a valid Win32 application' error.

Prefer to search for pkg-config.bat file when on a Windows host, in
additiona to the regular pkg-config file.

Fixes: #21239
2020-09-25 15:56:05 +02:00
Alexandru Croitor
3201dd521e FindPkgConfig: Show more info when pkg-config --version fails
Fixes: #21239
2020-09-25 15:49:18 +02:00
Rolf Eike Beer
cd31a8acef FindPkgConfig: also handle "-isystem" prefixes for include directories
Fixes: #20652
2020-05-05 18:38:50 +02:00
Rolf Eike Beer
95ead38375 FindPkgConfig: fix handling of frameworks 2020-04-18 17:14:56 +02:00
Brad King
b59f36aad8 FindPkgConfig: Unset results when pkg-config is broken
Inspired-by: FUJI Goro <goro@fastly.com>
2020-03-16 12:27:11 -04:00
Brad King
2b615e6f5e Merge topic 'FindPkgConfig-scope'
c3e0d1ffe9 FindPkgConfig: set policies CMP0054 and CMP0057 to new

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4388
2020-02-25 08:55:50 -05:00
Rolf Eike Beer
c3e0d1ffe9 FindPkgConfig: set policies CMP0054 and CMP0057 to new
One may encounter warnings if FindPkgConfig is used in any project, even
indirectly, that has set any of these policies to old explicitely or requires
an older version.
2020-02-24 16:42:34 +01:00
Hugo Beauzée-Luyssen
f92a4b2399 FindPkgConfig: Fix path manipulations when cross compiling
When cross compiling from a unix machine, if(UNIX) is false,
whih causes the path not to be fixed for unix, leading to false
negative if PKG_CONFIG_PATH needs to be probed
2019-12-02 16:47:04 +01:00
Chuck Atkins
28cb86d796 FindPkgConfig: Allow libraries that can't be found with their full path
pkg-config's .pc files can sometimes provide libraries that are visible to
the linker but not present in CMake's known search paths.  In the case
where CMake can find some, but not all of the library dependencies
provided in a .pc file, this allows them to be passed through as "-lfoo"
when the full path can't be found.

This also removes the test failure cases that occured because of this
scenario and adjsuts the remaining tests to account for not-found
libraries
2019-09-16 13:02:08 -04:00
Christophe Giboudeaux
fe68387695 FindPkgConfig: return the module found by pkg_search_module
When running `pkg_search_module`, it may be useful to get the matching
module name in order to run `pkg_get_variable`.

`pkg_search_module` now defines `<prefix>_MODULE_NAME` which contains
the first matching module name.

Fixes: #19648
2019-08-29 21:50:49 +02:00
Dan Kegel
f401a57160 pkg_get_variable now sets PKG_CONFIG_PATH like pkg_check_modules
Fixes: #15805
2019-03-20 17:21:47 -04:00
Dan Kegel
4d76941924 FindPkgConfig: hoist PKG_CONFIG_PATH ops out into _pkg_set_path_internal 2019-03-20 17:20:30 -04:00
Radek Nadstawny
b759fa9b8e FindPkgConfig: Set linker flags on imported targets 2019-03-13 23:42:44 +01:00
Sylvain Joubert
f5c46dd84e PkgConfig: Be less verbose by mark(ing)_as_advanced the find_library result 2018-11-07 14:08:02 +01:00
Joachim Wuttke (o)
fc7ee1ca45 Help: Override pygments CMakeLexer to support <..> and [..]
* The code snippets in the docs consist of CMake code mixed
  with syntax definition punctuation like < > [ ] ... Therefore
  a pure CMake lexer is inadequate. Here it is replaced by a
  CMake syntax definition parser.
* Fixed syntax definition snippets in FindPkgConfig.cmake to
  make best use of syntax highlighting. This source file is the
  hardest to support because it contains comparison operators
  <= = >=, which need special attention to avoid confusion
  with the placeholder indicators <...>.
* Fixed syntax in execute_process.rst (there were unbalanced
  brackets).
* Disabled syntax highlighting for long string examples in
  cmake-language.7.rst.
* No highlighting of removed syntax in CMP0049
* To inspect the outcome of this patch, see e.g. the pages
  * manual/cmake-buildsystem.7.html
  * module/ExternalProject.html
  * module/FindPkgConfig.html
  which are particularly rich in complex code snippets.
2018-10-19 07:25:34 +11:00
Joachim Wuttke (l)
74b3eacdc7 Help: Use appropriate list types in FindPkgConfig 2018-10-17 23:50:22 +11:00
Craig Scott
7f2bc70c5e FindPkgConfig: Document support for > and < operators
This was left out of commit v3.13.0-rc1~14^2 (FindPkgConfig: support
also > and < operators for version compares, 2018-10-02).
2018-10-15 10:14:51 -04:00
Rolf Eike Beer
aa51bfd74f FindPkgConfig: support also > and < operators for version compares
Fixes: #18416
2018-10-04 10:32:13 -04:00
Rolf Eike Beer
7aa26cf0e9 FindPkgConfig: allow to create global imported targets 2018-07-22 13:33:04 +02:00
Rolf Eike Beer
92ac721a44 FindPkgConfig: export the list of found libraries also as variable 2018-05-11 19:35:53 +02:00
Aleksandr Mezin
ac5731a7e3 FindPkgConfig: correct library search path for imported targets.
`-L` in LDFLAGS doesn't mean that standard search paths should be
excluded. Example:

    $ pkg-config --libs libmutter-2
    -L/usr/lib/mutter -lmutter-2 -lgtk-3 -lgdk-3 -lmutter-clutter-2 -lcairo-gobject -latk-1.0 -lpangocairo-1.0 -lpango-1.0 -lfribidi -ljson-glib-1.0 -lgio-2.0 -lwayland-egl -lwayland-client -lXtst -lXi -lmutter-cogl-2 -lcairo
-lgmodule-2.0 -pthread -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0 -lgbm -ldrm -lwayland-server -lEGL -lXext -lXdamage -lXfixes -lXcomposite -lXrandr -lX11

Most of these libraries are located at standard paths, not in
`/usr/lib/mutter`.

Fixes: #17954
2018-05-02 04:16:55 +06:00
Rolf Eike Beer
946846aaf5 FindPkgConfig: do not unset unused variable
_props is never used, it was a leftover from a development step.
2018-04-24 13:46:41 -04:00
Craig Scott
40b95ee8e6 FindPkgConfig: Fix IMPORTED_TARGET NO...PATH option handling 2017-12-16 22:40:40 +11:00
Craig Scott
adf4913795 FindPkgConfig: Cleanup docs
- Moved block of misplaced comments to correct section
- Improved grammar, readability and consistency
- Updated to conform to style guidelines
2017-12-10 22:50:39 +11:00
Shin-ya Murakami
07a4be0d9c FindPkgConfig: On FreeBSD search in libdata/pkgconfig
The pkgconfig dir is placed at `${PREFIX}/libdata/pkgconfig` on FreeBSD
instead of `${PREFIX}/lib/pkgconfig`, where `${PREFIX}` is `/usr/local`
as default.
2017-08-07 10:51:16 -04:00
Rolf Eike Beer
3cf267cfbf FindPkgConfig: do not always rerun pkg_check_modules() with 2 arguments
Since commit v3.8.0-rc1~47^2 (FindPkgConfig: Recheck pkg-config on
parameter change, 2017-01-17) calling `pkg_check_modules` always
re-runs.  The problem is that if there are only 2 arguments passed to
`pkg_check_modules```, then `_module0` will be set and `ARGN` will be
empty.  When this is written to cache it will be stored as just the
value of `_module0` without any semicolon, so on the next run this
doesn't match the expected value and the search is rerun.

Revise the logic to handle the case of empty `ARGN` separately.

Fixes: #17003
2017-07-10 11:16:51 -04:00
Rolf Eike Beer
70a6cb70f6 FindPkgConfig: mention that variables will be ;-lists 2017-06-12 22:03:20 +02:00
Rolf Eike Beer
6610fdbed2 FindPkgConfig: fix confusing indentation 2017-06-12 22:03:20 +02:00
Yuriy Khokhulya
2e293c39da FindPkgConfig: Fix pkg_check_modules() non-standard location search
During search of the library file `pkg_check_modules()` attempts to find
it in last specified library path in `${_prefix}_LDFLAGS`, that after
dependency resolving contains path to standard location.

So in case when `${_prefix}_LDFLAGS` has:

    -L/prefix;-L/usr/local/lib;-llibrary_from_prefix;-ldependency

`library_from_prefix` will not be found.

As solution need try to find the library in all paths preceding to the
library.

Fixes: #16873
2017-05-12 09:21:21 -04:00
Steven Newbury
462cf25427 Add support for x32-abi
Detect x32-abi through CMakeCompilerABI infrastruture and use this
information at runtime to determine the correct library paths with
`FIND_LIBRARY_USE_LIBX32_PATHS`.

Fixes: #15994
2017-03-07 15:22:55 -05:00
Gautier Pelloux-Prayer
8d71fa9283 FindPkgConfig: use new version checking "library >= version" syntax
Instead of the deprecated --atleast-version one.
2017-02-28 10:45:25 +01:00
Matthew Hanna
796dea67a6 FindPkgConfig: Recheck pkg-config on parameter change.
Currently, once pkg_check_modules succeeds, it will never call
_pkg_check_modules_internal again.  That means that if the parameters
to pkg_check_modules are changed, cmake will be called to reconfigure,
but nothing will change.  This change is to store the full string of
arguments to pkg_check_modules and override the FOUND optimization so
that the arguments are reevaluated when modified.
2017-01-24 22:02:14 -05:00
Gautier Pelloux-Prayer
cbccebbac9 FindPkgConfig: Fix missing error text when library version is specified
Calls like `pkg_check_modules(somelibrary>=3.22)` that specify a version
requirement should still display an informative error when the package
is not found.  Fix our logic accordingly.
2016-11-28 16:18:07 -05:00
Florent Castelli
61898de641 PkgConfig: Fix FindPkgConfig imported target feature
The options to the find_library call to create the imported target
used a literal string "HINTS /path NO_DEFAULT_PATH" instead of a
list of options. This resulted in never finding any library in my
testing.
2016-11-04 23:35:27 +01:00
Brad King
86578eccf2 Simplify CMake per-source license notices
Per-source copyright/license notice headers that spell out copyright holder
names and years are hard to maintain and often out-of-date or plain wrong.
Precise contributor information is already maintained automatically by the
version control tool.  Ultimately it is the receiver of a file who is
responsible for determining its licensing status, and per-source notices are
merely a convenience.  Therefore it is simpler and more accurate for
each source to have a generic notice of the license name and references to
more detailed information on copyright holders and full license terms.

Our `Copyright.txt` file now contains a list of Contributors whose names
appeared source-level copyright notices.  It also references version control
history for more precise information.  Therefore we no longer need to spell
out the list of Contributors in each source file notice.

Replace CMake per-source copyright/license notice headers with a short
description of the license and links to `Copyright.txt` and online information
available from "https://cmake.org/licensing".  The online URL also handles
cases of modules being copied out of our source into other projects, so we
can drop our notices about replacing links with full license text.

Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority
of the replacements mechanically.  Manually fix up shebang lines and trailing
newlines in a few files.  Manually update the notices in a few files that the
script does not handle.
2016-09-27 15:14:44 -04:00
Daniel Pfeifer
5d0d980d99 Use string(APPEND) in Modules
Automate with:

find Modules -type f -print0 | xargs -0 perl -i -0pe \
's/set\(([a-zA-Z0-9_]+)(\s+)"\$\{\1\}([^"])/string(APPEND \1\2"\3/g'
2016-07-28 00:41:13 +02:00
Brad King
95c5e00186 Merge topic 'pkgconfig-targets'
8345c646 FindPkgConfig: define the imported targets also when the data comes from cache
2016-06-20 09:55:59 -04:00
Rolf Eike Beer
8345c6463d FindPkgConfig: define the imported targets also when the data comes from cache 2016-06-19 09:35:05 +02:00
Daniel Scharrer
896ad251de Teach find_library and find_package to search lib32 paths (#11260)
Add a ``FIND_LIBRARY_USE_LIB32_PATHS`` global property analogous to the
``FIND_LIBRARY_USE_LIB64_PATHS`` property.  This helps find commands on
multilib systems that use ``lib32`` directories and either do not have
``lib`` symlinks or point ``lib`` to ``lib64``.
2016-06-10 11:09:16 -04:00
Rolf Eike Beer
df97b9793f FindPkgConfig: optionally create imported target for the found libraries 2016-05-14 09:31:41 +02:00
Ben Boeckel
6f4f905483 FindPkgConfig: set correctly named variables in cache (#15903)
The fix in commit v3.5.0-rc1~27^2 (FindPkgConfig: set standard variables
in the cache, 2016-01-20) added the wrong variable name to the cache.
The test was only testing that the cache variable existed, not that it
also had the correct value.  Update the test to ensure that the cache
value matches the local variable value.

Reported-by: Bernd Lörwald
2016-03-21 08:58:12 -04:00
Ben Boeckel
40249bccdf FindPkgConfig: set standard variables in the cache
Fixes a regression introduced when the code was simplified to use the
variable queries.

Fixes #15903.

Reported-by: Bernd Lörwald
2016-01-21 10:38:30 -05:00
Rob Gowin
53511936e4 FindPkgConfig: Quote ${_pkgconfig_path} to protect semicolons on Windows 2016-01-19 09:39:04 -05:00