Commit Graph

51 Commits

Author SHA1 Message Date
Brad King
f4aa34daa7 Tests/RunCMake: Update cmake_minimum_required versions to 3.10
For policy-specific tests, use the version before the policy was
introduced.  Otherwise, use 3.10 where possible.
2024-10-03 11:52:22 -04:00
Kerem Aksu
9ddef32ba0 FindPkgConfig: Fix parsing of quoted lists with pkgconf <1.5.1
Unquote pkg-config output if they are printed within quotes. pkgconf
<1.5.1 and classic pkg-config <0.29.1 prints quoted variables without
unquoting them, this breaks returning variables with multiple values
as a list behavior of CMake.

Add a new test case for pkg_get_variable with multiple values to test
list behavior and backslash escaped spaces within variable values.

Fixes: #25904
2024-04-20 21:03:56 +03:00
Vladimir Petko
870500a326 Tests: Update RunCMake.FindPkgConfig gobject-introspection expectation
gobject-introspection 1.79+ uses binaries with an arch-specific prefix,
such as `/usr/bin/x86_64-linux-gnu-g-ir-scanner`.

Fixes: #25865
2024-04-08 18:09:59 -04:00
Corentin Noël
e0d00b9218 FindPkgConfig: Allow to override variables when calling pkg_get_variable
This is specifically useful when building applications within containers as we
sometimes need to redefine the prefix used in a variable.
2023-09-19 09:08:48 +02:00
Cristian Le
252c66c697 FindPkgConfig: Tolerate PKG_CONFIG_SYSTEM_INCLUDE_PATH in environment
Tell `pkg-config --cflags` not to filter out `-I` flags for entries of
`PKG_CONFIG_SYSTEM_INCLUDE_PATH` (and `CPATH` for `pkgconf`).

Fixes: #25228
2023-09-06 12:17:39 -04:00
Cristian Le
4507883135 Tests: Rename RunCMake.FindPkgConfig LIBRARY_PATH case to SYSTEM_PATH
Prepare to cover CFLAGS too.
2023-09-06 12:12:53 -04:00
Brad King
1edf138506 Tests/RunCMake: Update cmake_minimum_required versions
For policy-specific tests, use the version before the policy was
introduced.  Otherwise, use 3.5 where possible.

Also, remove `cmake_minimum_required()` and `project()` calls from
individual cases where they are handled by `CMakeLists.txt`.
2023-02-11 06:24:22 -05:00
Craig Scott
fc8f8d82f2 Tests: Disable parts of FindPkgConfig tests without wide supported
Some pkg-config implementations on Windows don't return the same
results as those on other platforms. They appear to be bugs in those
implementations, the one that comes with Strawberry perl being one
case where this was observed. The handling of Libs and Cflags entries
is incomplete, resulting in some flags not being reported where they
should be. These are faults in the pkg-config implementation, not in
CMake or its tests, so we disable those parts of the tests on Windows
to avoid reporting false positives.
2022-10-30 09:37:13 +11:00
Craig Scott
96d7b5a6d1 Tests: pkg_check_modules() doesn't allow spaces in a moduleSpec
The documentation of pkg_check_modules() is a little ambiguous about
whether spaces are allowed in a moduleSpec that includes a version
constraint. All examples in the docs do not have spaces, so it could be
claimed spaces are not supported. The tests fail on Windows when spaces
are included, likely because some pkg-config implementations don't
support that. Update the tests to not assume spaces are supported as
part of a moduleSpec.
2022-10-29 22:05:30 +11:00
Craig Scott
afd1b28cea Tests: Disable broken FindPkgConfig test cases for Windows
The Windows implementation of these tests have been found to not
handle Windows paths and path separators properly in a number of
areas. The whole approach taken in these tests appears dubious, so
they may need to be significantly rewritten. Disable them until then
so we don't get false positives.

Issue: #22031
2022-10-29 22:03:17 +11:00
makise-homura
bcdac84961 Tests/FindPkgConfig: correctly handle broken pkg-config
Older versions of pkg-config (e.g. 0.21 and 0.22) do not
handle correctly spaces in paths specified in .pc files.
It breaks RunCMake.FindPkgConfig test, if CMake is built
inside path containing spaces. In this case, we check if
we're inside such path, and if pkg-config is broken; and
if both are true, test is to be skipped.
2022-07-01 19:22:59 +03:00
Brad King
7e4adcac82 FindPkgConfig: Revert "Populate _STATIC_LINK_LIBRARIES. Add STATIC_TARGET."
Revert commit 020976d637 (FindPkgConfig: Populate
_STATIC_LINK_LIBRARIES. Add STATIC_TARGET., 2021-12-31,
v3.24.0-rc1~105^2).  Several regressions have been reported.
Revert the feature pending further discussion and design work.

Issue: #21714
Fixes: #23642
2022-06-22 10:13:00 -04:00
Alex Birch
020976d637 FindPkgConfig: Populate _STATIC_LINK_LIBRARIES. Add STATIC_TARGET.
Add LINK_LIBRARIES test to demonstrate static linking of transitive
dependencies.

Add STATIC_TARGET argument to pkg_check_modules() and pkg_search_module().
Influences the properties of target produced by IMPORTED_TARGET.
When enabled: target's properties will be populated from <XXX>_STATIC_*
variables instead of from <XXX>_* variables.

Update existing tests concerning properties of targets produced via
IMPORTED_TARGET, to test STATIC_TARGET variant too.
Update existing tests concerning <XXX>_* variables to test <XXX>_STATIC_*
variables too.

Breaking changes to pkg_check_modules() and pkg_search_module():
- Variables CMAKE_FIND_LIBRARY_PREFIXES and CMAKE_FIND_LIBRARY_SUFFIXES can no
longer be used to influence library lookup (i.e. the internal call to
find_library()), because FindPkgConfig now internally relies on these
variables to differentiate between shared and static library lookup.
Prefer CMAKE_SHARED_LIBRARY_PREFIX + CMAKE_SHARED_LIBRARY_SUFFIX, or
CMAKE_STATIC_LIBRARY_PREFIX + CMAKE_STATIC_LIBRARY_SUFFIX, depending on
whether you wish to impact static or shared lookup.
- <XXX>_LINK_LIBRARIES will now be populated only with libraries
located via CMAKE_SHARED_LIBRARY_PREFIX + CMAKE_SHARED_LIBRARY_SUFFIX match
- <XXX>_STATIC_LIBRARIES now processes -framework options
- <XXX>_STATIC_LDFLAGS_OTHER now processes -framework options
- <XXX>_STATIC_CFLAGS_OTHER now processes -isystem options
- <XXX>_STATIC_INCLUDE_DIRS now processes -isystem options

Fixes: #21714
2022-05-20 09:45:12 -04:00
Alex Birch
3c5cc79adb Tests: De-duplicate some code in RunCMake.FindPkgConfig 2022-05-20 09:25:07 -04:00
Alex Birch
5cfbc76371 FindPkgConfig: Fix parsing of backslash-escaped spaces in pkg-config output
Treat backslash-escaped spaces as "space within argument" rather than
"space delimiting arguments".

Update our `FindPkgConfig_LIBRARY_PATH` test case to escape spaces in
the path, and run it unconditionally.
2022-05-12 12:26:04 -04:00
Brad King
135e79038c Merge topic 'FindPkgConfig-restore-legacy-behavior'
17e4934dbf FindPkgConfig: Restore legacy behavior when CMP0126 is set to NEW

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6461
2021-08-19 10:27:24 -04:00
Marc Chevrier
17e4934dbf FindPkgConfig: Restore legacy behavior when CMP0126 is set to NEW
Module behavior must be independent from `CMP0126` policy.

Fixes: #22526
2021-08-18 14:51:50 -04:00
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
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
07d6390728 Tests: Add case covering FindPkgConfig creation of empty targets 2021-06-04 08:33:11 -04:00
Brad King
000b761777 Merge topic 'test-FindPkgConfig-isolate-env'
8b12982653 Merge branch 'backport-test-FindPkgConfig-isolate-env'
4c939b0d39 Tests: Isolate RunCMake.FindPkgConfig from caller environment
20eeb40aaf Tests: Isolate RunCMake.FindPkgConfig from caller environment

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5108
2020-08-10 10:45:54 -04:00
Brad King
20eeb40aaf Tests: Isolate RunCMake.FindPkgConfig from caller environment
Avoid interference from `CMAKE_PREFIX_PATH` and friends if they
happen to be set in the environment from which the tests are run.
2020-08-07 10:37:28 -04:00
Jean-Christophe Fillion-Robin
207373802e Fix typos identified using codespell
See https://github.com/codespell-project/codespell#readme

The following command was used:

```
codespell -q6 --skip="\
.git,\
*.json,\
./Copyright.txt,\
./Help/command/foreach.rst,\
./Help/prop_test/REQUIRED_FILES.rst,\
./Help/variable/CTEST_COVERAGE_COMMAND.rst,\
./Modules/CMakeCheckCompilerFlagCommonPatterns.cmake,\
./Modules/CMakeRCInformation.cmake,\
./Modules/Internal/CPack/NSIS.template.in,\
./Modules/FindMatlab.cmake,\
./Modules/MatlabTestsRedirect.cmake,\
./Modules/Platform/Windows-Clang.cmake,\
./Modules/Platform/Windows-Intel-Fortran.cmake,\
./Modules/Platform/Windows-MSVC.cmake,\
./Source/CMakeVersion.cmake,\
./Source/cmConvertMSBuildXMLToJSON.py,\
./Source/cmCreateTestSourceList.cxx,\
./Source/cmGlobalVisualStudio10Generator.cxx,\
./Source/cmExportBuildFileGenerator.cxx,\
./Source/cmExportInstallAndroidMKGenerator.cxx,\
./Source/cmExportInstallFileGenerator.cxx,\
./Source/cmExportSet.cxx,\
./Source/cmExportTryCompileFileGenerator.cxx,\
./Source/cmFindPackageCommand.cxx,\
./Source/cmInstallCommand.cxx,\
./Source/cmGeneratorExpressionLexer.cxx,\
./Source/cmLocalVisualStudio7Generator.cxx,\
./Source/cmOrderDirectories.cxx,\
./Source/cmTarget.cxx,\
./Source/kwsys/*,\
./Source/QtDialog/CMakeSetupDialog.ui,\
./Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx,\
./Source/CTest/cmParseCoberturaCoverage.h,\
./Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in,\
./Tests/RunCMake/CPack/tests/DMG_SLA/English.license.rtf,\
./Tests/RunCMake/CPack/tests/DMG_SLA/German.license.txt,\
./Tests/RunCMake/CPack/tests/DMG_SLA/German.menu.txt,\
./Tests/RunCMake/GoogleTest/xml_output.cpp,\
./Tests/RunCMake/Make/TargetMessages*,\
./Utilities/*,\
" \
-L "\
dependees,\
endwhile,\
fo,\
filetest,\
helpfull,\
nd,\
objext,\
stoll,\
supercedes,\
superceded,\
vas,\
varn,\
"
```
2020-07-22 12:44:47 -04:00
Brad King
9b99b4bfc8 Tests/RunCMake: Update cmake_minimum_required versions
Use 3.3 or 2.8.12 where possible.
2020-06-18 09:52:05 -04: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
Rolf Eike Beer
b7304f35b3 Tests: simplify FindPkgConfig_CMAKE_{FRAMEWORK,APPBUNDLE}_PATH tests
These tests are only run on Apple platforms, so remove code for all other
platforms form them.
2020-04-18 15:26:02 +02:00
Brad King
1c99f5df28 FindPkgConfig: Add test for specified pkg-config tool missing 2020-03-17 08:02:15 -04: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
78f23de70c More tests for pkg_get_variable
Issue: #15805
2019-03-20 17:18:01 -04:00
Radek Nadstawny
b759fa9b8e FindPkgConfig: Set linker flags on imported targets 2019-03-13 23:42:44 +01: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
Luz Paz
3ab7bf8285 Various typo fixes
Some are user-facing. Others are source comments.
2018-01-04 06:52:01 +11:00
Craig Scott
b0ff528adc FindPkgConfig: Make IMPORTED_TARGET test verify NO...PATH properly 2017-12-16 22:38:56 +11:00
Steven Newbury
d9bdcf34ef Tests: Add x32 tests to test suite 2017-03-08 17:23:30 +00: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
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
Benjamin Chrétien
1bfb527f56 FindPkgConfig: return actual error when a package is not found (#15810)
In some cases, CMake returned the following error:

-- Checking for module 'foo'
--   Package 'foo' not found

When the actual error returned by pkg-config was:

  Package 'bar', required by 'foo', not found

Now, the actual error is forwarded to the user.

-- Checking for module 'foo'
--   Package 'bar', required by 'foo', not found

For the standard case (i.e. the package was indeed not found), the
CMake error was:

-- Checking for module 'foo'
--   Package 'foo' not found

But it now prints:

-- Checking for module 'foo'
--   No package 'foo' found

The associated test was also updated. ${last} refers to the last
CLI argument.
2015-10-28 10:18:15 -04:00
Ben Boeckel
51b83f1445 FindPkgConfig: add a command to query arbitrary variables 2015-09-21 09:39:26 -04:00
Daniele E. Domenichelli
d4c6531a94 FindPkgConfig: Fix extra paths for CMAKE_{FRAMEWORK,APPBUNDLE}_PATH vars
The CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH cache variables are
supposed to be used to generate the extra paths passed to pkg-config,
but instead the CMAKE_PREFIX_PATH variable is used.

This bug was introduced by the refactor in commit v3.1.0-rc1~747^2~1.
2015-05-29 19:22:57 +02:00
Brad King
fa7d47ac5c Tests: Fix CMP0054 warnings
Hack the CMP0054 warning locally to be an error and run the test suite.
Resolve CMP0054 in Tests/* code as appropriate for each case.
2014-09-16 09:06:29 -04:00
Daniele E. Domenichelli
cc5a0d8f42 FindPkgConfig: More unit tests 2014-03-17 18:10:59 +01:00