Commit Graph

322 Commits

Author SHA1 Message Date
Alex Turbov
19366408fe cmFindPackageCommand: Protect overrides of cmDirectoryListGenerator
Move virtual function overrides into a protected section of class.
2022-08-04 09:41:59 -04:00
Alex Turbov
e55c154c5b cmFindPackageCommand: Add one more search path
The `PREFIX/(Foo|foo|FOO).*/(cmake|CMake)/(Foo|foo|FOO).*/` search
path is the similar to the one already exists
`PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/cmake/(Foo|foo|FOO).*/`.
2022-08-04 09:41:59 -04:00
Alex Turbov
2f69c0233c cmFindPackageCommand: Optimize the last calls to TryGeneratedPaths 2022-08-02 09:46:52 -04:00
Alex Turbov
076a4b44b0 cmFindPackageCommand: Path generators are actually reusable 2022-08-02 09:46:52 -04:00
Alex Turbov
664abd486f cmFindPackageCommand: Better names for template parameters 2022-08-02 09:46:52 -04:00
Alex Turbov
c862797a40 cmFindPackageCommand: Rename some generators
The point is that `cmFileListBlahBlahGenerator` actually "generate"
directory names and never files.

The `cmBlahBlahStringGenerators` produce paths in fact. Ok, paths
nowadays are also strings but...
2022-08-02 09:46:52 -04:00
Alex Turbov
fdd14b1744 cmFindPackageCommand: Deduplicate directory listing code
The `cmFileListGeneratorProject` and `cmFileListGeneratorMacProject`
was look very similar 'cept few lines.

Now they have a base class and the generator-specific logic has moved
to overrides.
2022-08-02 09:46:52 -04:00
Alex Turbov
08e7fb3cfa cmFindPackageCommand: Compile-time path generator expressions
Original code had path generators built at run-time using a linked list
of dynamically allocated nodes each of which was responsible to generate
a path segment.

However, the combination of used generators is totally well known at
compile time.
2022-08-02 09:46:48 -04:00
Alex Turbov
61eb5d4de5 cmFindPackageCommand: Avoid friendship between command class and generator 2022-07-11 17:14:02 +04:00
Alex Turbov
ef62f213f8 cmFindPackageCommand: Drop dead code
The `cmFindPackageFileList` instances always constructed w/ the only
parameter. The boolean flag is always `true` (default value).

Also, `cmFindPackageCommand::InitialPass` adds an empty string
to the `cmFindPackageCommand::SearchPathSuffixes` vector. Meaning
that `cmFindPackageCommand::CheckDirectory()` gonna be called for
the suffix-less path, so `cmFindPackageFileList::Visit` may call
only `cmFindPackageCommand::SearchDirectory` and get the same result.
2022-07-11 17:14:02 +04:00
Alex Turbov
468d04ef14 cmFindPackageCommand: Move methods implementation into the class definition 2022-07-11 17:14:02 +04:00
Alex Turbov
898ba76d1b cmFindPackageCommand: Drop redundant std::ostream::operator<< calls 2022-07-11 17:14:02 +04:00
Alex Turbov
5be13907a0 cmFindPackageCommand: Use vector instead of set to store arg indices
They are unique by design. I.e., when the algorithm iterates over
args doing only one push per iteration indices gonna be unique ;-)
So, no need for `std::set` here.
2022-07-11 17:14:02 +04:00
Alex Turbov
66c3932e58 cmFindPackageCommand: Move comment inside the else if block 2022-07-11 17:14:02 +04:00
Alex Turbov
285c994905 cmFindPackageCommand: Named lambda w/o capture to normal function 2022-07-11 17:14:02 +04:00
Alex Turbov
f9f4e104b0 cmFindPackageCommand: Constness 2022-07-11 17:14:02 +04:00
Alex Turbov
c67b82c998 cmFindPackageCommand: Enclose file list generators into anonymous ns 2022-07-11 17:14:01 +04:00
Alex Turbov
f71b88c4c1 cmFindPackageCommand: Move cmFindPackageCommandHoldFile to anonymous ns
Also, avoid `#include` in the middle of the module.
2022-07-11 17:14:01 +04:00
Alex Turbov
865cfaa492 cmFindPackageCommand: Move collectPathsForDebug() to anonymous namespace 2022-07-11 17:14:01 +04:00
Alex Turbov
6a95ab97e7 cmFindPackageCommand: Deduplicate version string comparator code 2022-07-11 17:14:01 +04:00
Alex Turbov
c6d3ef1c95 cmFindPackageCommand: Replace empty string literal w/ default std::string{} 2022-07-11 17:14:01 +04:00
Alex Turbov
f2a4e4f6fa cmFindPackageCommand: Simplify if-return-else-return into single return stmt 2022-07-11 17:14:01 +04:00
Alex Turbov
a3fe1aca0c cmFindPackageCommand: Replace strcmp with array subscription 2022-07-11 17:14:01 +04:00
Alex Turbov
b5f880d5c6 cmFindPackageCommand: Deduplicate code to exclude . and .. dir entries 2022-07-11 17:14:01 +04:00
Alex Turbov
045e36fe36 cmFindPackageCommand: Replace single-char string literals with char literals 2022-07-11 17:14:01 +04:00
Alex Turbov
1bed0be2cd cmFindPackageCommand: Use std::any_of instead of "manual" for loops 2022-07-11 17:14:01 +04:00
Sean McBride
d5694e4623 Source: Replace uses of sprintf with safer snprintf 2022-06-22 08:59:40 -04:00
FeRD (Frank Dana)
98a10290a8 cmSystemTools: Fix 'ErrorOccurred' spelling
Rename the booleans 's_ErrorOccured' and 's_FatalErrorOccured' to
's_ErrorOccurred' and 's_FatalErrorOccurred', respectively.

Rename the getters and setters to 'Get[Fatal]ErrorOccurred' and
'Set[Fatal]ErrorOccurred', and fix all uses across the codebase.
2022-06-13 09:05:24 -04:00
Craig Scott
2aa83fa15b Dependency providers: Add find_package and FetchContent support
Fixes: #22619
2022-05-25 08:46:18 +10:00
Craig Scott
74a6ddc339 cmFindPackageCommand: Handle Makefile variable definitions more robustly
During argument parsing in InitialPass(), Makefile variables were
being added for components. Most other such variables were set
in the call to SetModuleVariables(), which happens much later.
Both sets of variables were then restored to their previous values
as part of a call to AppendSuccessInformation(), but that is not an
obvious nor robust place to undo those variable changes.

InitialPass() also pushes a new item to the package root stack, but
the corresponding pop was in AppendSuccessInformation().
Again, this puts a symmetric operation in an asymmetric place.

Refactor the code slightly such that Makefile variables are set in
one clear location, then restored later in the same function.
Also move the package root stack pop into the same function as
the push. AppendSuccessInformation() now has one clear
responsibility and doesn't perform any unrelated cleanup on
behalf of InitialPass().
2022-05-17 14:33:29 +10:00
Craig Scott
c5dff5ace2 Merge topic 'FetchContent_find_package_integration'
29e31e2825 Packages: Integrate FetchContent and find_package()

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Acked-by: huangqinjin <huangqinjin@gmail.com>
Merge-request: !5688
2022-05-06 08:33:38 -04:00
Craig Scott
29e31e2825 Packages: Integrate FetchContent and find_package()
Allow FetchContent_MakeAvailable() to try a call to
find_package() first, or redirect a find_package() call to
FetchContent_MakeAvailable(). The user can set variables
to control which of these are allowed or tried by default.

Fixes: #21687
2022-05-03 16:48:11 +10:00
Marc Chevrier
8d7e80cf3d find_* commands: add control over Windows registry views
Fixes: #22775
2022-04-29 22:00:02 +02:00
Robert Maynard
42f7e39789 Find: Support per call disabling of CMAKE_INSTALL_PREFIX
Fixes #23359
2022-04-15 09:33:55 -04:00
John Parent
2f1ffa003c find_package: Add support for default GLOBAL imported targets
Allow find package to promote scope of imported targets by specifying
an argument to `find_package` or by specifying a CMake variable.
    * Add support for CMAKE_GLOBAL_IMPORT_SCOPE variable
    * Add support for GLOBAL argument to find_package

Additionally add testing for above features.
2022-03-10 12:44:36 -05:00
Brad King
38de1bef2d find_package: Improve --debug-find-pkg= when using a find module
Extend the feature added by commit d7b18895bc (cmake: Add filtered
debug-find options, 2021-12-07, v3.23.0-rc1~217^2) to enable debug
output for `find_*` calls within a find module or cmake package
configuration file.

Fixes: #23211
2022-02-10 16:30:10 -05:00
Brad King
d634d20397 find_package: Avoid printing debug output header multiple times 2022-02-10 16:30:10 -05:00
Brad King
df3e29450a find_package: Mention package name in Config mode debug output
Otherwise, if there are no paths considered then the output does not
specify the name of the package.
2022-02-10 16:30:09 -05:00
Brad King
636ca7f25c find_package: Fix find module name in --debug-find output 2022-02-10 16:30:09 -05:00
Brad King
596e185409 find_package: Improve formatting of --debug-find output
Also spell out more complete content in the test's expect output.
2022-02-10 16:30:04 -05:00
Brad King
a690523fcf cmFindPackageCommand: Drop ComputeIfDebugModeWanted overload
The overload for `--debug-find-pkg` has the same signature as the base
class method for `--debug-find-var`.  To avoid confusion, drop the
overload and inline it its only call site.
2022-02-10 15:25:05 -05:00
Kyle Edwards
201d8c4298 find_*(): Add CMAKE_IGNORE_PREFIX_PATH variable
Fixes: #20878
2022-02-02 11:09:00 -05:00
Kyle Edwards
bd805a51ae Refactor: Keep track of prefixes in cmSearchPath 2022-02-02 11:09:00 -05:00
Kyle Edwards
11f97d1968 find_package(): Refactor CMAKE_[SYSTEM_]IGNORE_PATH
In the old implementation, CMAKE_[SYSTEM_]IGNORE_PATH was handled
in cmFindCommon. Move it into cmFindPackageCommand.
2022-01-31 10:41:04 -05:00
John Parent
d7b18895bc cmake: Add filtered debug-find options
Add a `--debug-find-pkg=` option to debug find calls for specific
packages.

Add a `--debug-find-var=` option to debug find calls for specific
return variables.

Fixes: #21880
2021-12-17 08:55:21 -05:00
Sean McBride
5ba6e8ac59 Source: Replace most calls to sprintf with snprintf 2021-10-25 18:23:13 -04:00
Marc Chevrier
cc56dc7468 Rename cmProp in cmValue 2021-09-21 17:14:04 +02:00
Eugene Shalygin
a2e9fe38e4 find_package: Add variable to make package REQUIRED
Add a `CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>` variable is complement
to `CMAKE_DISABLE_FIND_PACKAGE_<PackageName>` with just the opposite
behaviour: it turns non-required find_package call into the required one.

While optional package dependencies usually result in simple and clean
build logic, sometimes people want to be sure those optional
dependencies will be found and used. Examples are reproducible builds
and build instructions for 3rd parties. People choose to make
find_package calls REQUIRED and put them behind an option(). Such
workarounds blend build logic with build environment management and do
not look elegant.
2021-07-08 08:03:38 -04:00
Marc Chevrier
d96eb55282 set(CACHE): do not remove normal variable
Fixes: #22038
2021-05-20 17:50:13 +02:00
Ben Boeckel
ef935b17ab clang-tidy: fix readability-use-anyofallof warnings 2021-01-27 08:54:18 -05:00