Commit Graph

169 Commits

Author SHA1 Message Date
Ben Boeckel
5aefc8b7b8 cmFindBase: let the debug state know if it has already been found
This avoids reporting a "not found" state for searches that had cached
results.
2025-06-09 12:24:31 -04:00
Brad King
6be0c6d26a Merge topic 'astgrep-cmstrcat'
557c44b93e cmStrCat: use character literals where possible
23779057fd cmStrCat: combine neighboring arguments where possible
483d13daf4 ast-grep: add a rule to turn strings into characters
61743471d9 ast-grep: add a rule to find adjacent string literals in cmStrCat calls

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10790
2025-05-22 08:47:15 -04:00
Ben Boeckel
557c44b93e cmStrCat: use character literals where possible
Found and replaced using the `cmstrcat-to-char-literal` rule for
`ast-grep`.
2025-05-15 19:12:04 +02:00
Ben Boeckel
3ac505f79d cmFindCommon: log search path variables
No pruning of variables which are not relevant is performed as it would
involve duplication of determining which paths to manage.
2025-05-15 12:24:58 +02:00
Ben Boeckel
e98381af21 cmFindBase: skip writing names and *_directories when empty
When the arrays are empty, the YAML ends up with `foo:` which is
equivalent to `foo: null`, not `foo: []`. Avoid writing the key when it
has no information to provide.
2025-05-13 14:43:08 +02:00
Ben Boeckel
fdccb8846c cmFindCommonDebugState: adopt event writing logic
This lays the groundwork for `find_package` also using the same
triggering logic.
2025-05-01 12:47:24 +02:00
Ben Boeckel
716dfd3b1e cmFindCommon: track debug state as an object
This also means that the `DebugState` instances do not need to ask if
debug mode is enabled: if they exist, it is enabled.
2025-04-29 20:10:43 +02:00
Ben Boeckel
c6d097135d cmFindBaseDebugState: factor out a base class
This will be used to share logic with `find_package` writing events.
2025-04-29 20:10:43 +02:00
Ben Boeckel
bd5cb1f8e6 cmFindCommon: use DebugModeEnabled to query for debug mode
This simplifies changing how debug mode is represented.
2025-04-29 20:10:43 +02:00
Ben Boeckel
76ea613f4c cmFindBaseDebugState: get the command name directly from the object 2025-04-29 20:10:43 +02:00
Ben Boeckel
a3f273b657 cmFindBase: Create find-v1 configure log events
Record `find_` command events in the configure log, except
`find_package` as it is far more complicated (and will have its own
event kind).

Note that testing only generates the events of interest, there is no
verification. Also note that testing that the "found" to "notfound"
transition causes an event is not testable because a truthy value in the
variable skips any kind of verification or other logic beyond
normalization.

Co-Authored-by: Ryan Krattiger <ryan.krattiger@kitware.com>
See: #24833
2025-04-28 13:55:36 +02:00
Ben Boeckel
58b5d41a4f cmFindBase: Track initial state with an enum
When logging a `WriteFindBaseEvent`, one of the triggers to log is the
change in the "found" status of a `find_` command. Track the difference
between "undefined", "found", and "tried before, but not found" so that
the transition can be detected reliably.

Co-Authored-by: Ryan Krattiger <ryan.krattiger@kitware.com>
2025-04-28 11:47:32 +02:00
Kitware Robot
1772622772 LICENSE: Replace references to Copyright.txt with LICENSE.rst
```
git grep -lz 'Copyright.txt or https://cmake.org/licensing ' |
  while IFS= read -r -d $'\0' f ; do
    sed -i '/Copyright.txt or https:\/\/cmake.org\/licensing / {
              s/Copyright.txt/LICENSE.rst/
            }' "$f" ; done
```
2025-03-03 10:43:35 -05:00
Martin Duffy
857a039d66 find_*: Add variable to default calls to REQUIRED
This adds a `CMAKE_FIND_REQUIRED` variable which causes `find_package`,
`find_path`, `find_file`, `find_library` and `find_program` to be
considered `REQUIRED` by default.

It also introduces an `OPTIONAL` keyword to those commands, allowing
them to ignore the value of this variable.

Issue: #26576
2025-02-27 10:51:07 -05:00
Robert Maynard
f5837f0ac9 cmFindBase: Don't pass vector::erase an out of bounds iterator
Fixes: #26606
2025-02-11 14:59:21 -05:00
Kitware Robot
0b96ae1f6a Revise C++ coding style using clang-format with "east const"
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`, now with "east const" enforcement.
Use `clang-format` version 18.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.

Issue: #26123
2025-01-23 13:09:50 -05:00
Alex Turbov
b48d5aeae7 find_*: Improve error message quoting consistency
Some error messages (Windows registry related) of the `find_xxx` and
`cmake_host_system_information` commands, reported keywords in quotes,
while most commands did not.
2024-11-27 08:30:15 -05:00
Alex Turbov
e2c9bb7f54 cmFindBase.cxx: Optimize cmStrCat() calls 2024-11-19 17:57:43 +04:00
Alex Turbov
16a1fa9e35 cmFindBase.cxx: Check DebugMode and exit early to reduce indentation 2024-11-19 17:57:38 +04:00
Brad King
9d44a77454 find_*: Explicitly normalize found paths as they exist on disk 2024-10-22 13:26:19 -04:00
Daniel Pfeifer
58c5f77837 clang-tidy: fix readability-redundant-* warnings 2024-10-11 15:37:21 +02:00
Vitaly Stakhovsky
58da4aa47d Source: Avoid comparing pointers to nullptr 2024-08-27 10:56:38 -04:00
Brad King
0a81110b84 find_(library|file|path): Drop PATH-derived search prefixes
Since commit ffc06c1239 (Teach find_(library|file|path) to get prefixes
from PATH, 2015-02-18, v3.3.0-rc1~430^2) we search in `<prefix>/include`
and `<prefix>/lib` directories for prefixes with `bin` directories in
the `PATH` environment variable.  The motivation was to search the
installation prefixes of MSYS and MinGW development environments
automatically.

This behavior can search undesired prefixes that happen to be in the
`PATH` for unrelated reasons.  It was reverted for non-Windows hosts
within a year by commit b30b32a493 (Drop find_(library|file|path)
prefixes from PATH on non-Windows, 2016-05-09, v3.6.0-rc1~82^2) but was
kept on Windows hosts to support its motivating use case.  However,
similar problems have since been observed on Windows.  For example,
commit 955d6245c1 (MSVC: Revert "Teach find_library to consider the
'libfoo.a' naming convention", 2022-11-28, v3.25.1~6^2) was primarily
due to undesired discovery of libraries in `PATH`-derived prefixes.

Since commit 5e5132e1b1 (MinGW: Search for packages in standard MSYSTEM
environment prefixes, 2023-09-11) we search MSYS and MinGW environments'
prefixes explicitly, so `PATH`-derived prefixes are no longer needed for
the original motivating use case.

Fixes: #24216
2023-09-14 15:13:50 -04:00
Brad King
241ee252ce IWYU: Update for Debian 12 CI job
`include-what-you-use` diagnostics, in practice, are specific to
the environment's compiler and standard library.  Update includes
to satisfy IWYU for our CI job under Debian 12.
2023-07-28 09:14:08 -04:00
Marc Chevrier
4fc322bab4 AddCacheEntry: Suppress raw pointer usage 2023-05-30 16:41:59 +02:00
Marc Chevrier
e08ba229ee CMake code rely on cmList class for CMake lists management (part. 1) 2023-04-24 10:41:10 +02:00
Vitaly Stakhovsky
b3edfcf46e cmValue: Use operator* explicitly to convert to std::string; avoid extra call 2023-01-15 23:39:02 -05:00
Brad King
b9371c0477 Merge topic 'CMAKE_FIND_USE_INSTALL_PREFIX-support-staging-prefix'
0fc10bb19b CMAKE_FIND_USE_INSTALL_PREFIX considers CMAKE_STAGING_PREFIX
43d31c5198 cmFindBase: Refactor CMAKE_FIND_USE_INSTALL_PREFIX handling

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !7623
2022-08-31 09:39:52 -04:00
Robert Maynard
0fc10bb19b CMAKE_FIND_USE_INSTALL_PREFIX considers CMAKE_STAGING_PREFIX
Fixes #23900
2022-08-30 17:52:40 -04:00
Robert Maynard
43d31c5198 cmFindBase: Refactor CMAKE_FIND_USE_INSTALL_PREFIX handling 2022-08-30 15:26:30 -04:00
Marc Chevrier
f3b5a7d6df find_(program,library,file,path): add validation function
Fixes: #23603
2022-06-14 16:17:46 -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
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
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
Marc Chevrier
cc56dc7468 Rename cmProp in cmValue 2021-09-21 17:14:04 +02:00
Marc Chevrier
f84193292c Use new AddCacheEntry signatures 2021-09-10 15:46:21 +02:00
Marc Chevrier
e5cd39ca80 cmProp: refactoring: transform alias in class
To handle safely the values used by CMake variables and properties,
introduce the class cmProp as a replacement from the simple pointer
to std::string instance.
2021-08-08 16:19:08 +02:00
Marc Chevrier
87b71eec62 find_*: Add support for option NO_CACHE
Request that find result is stored in a normal variable rather than a
cache entry.

Fixes: #20687
Issue: #20743
2021-06-02 14:55:00 -04:00
Marc Chevrier
d96eb55282 set(CACHE): do not remove normal variable
Fixes: #22038
2021-05-20 17:50:13 +02:00
Marc Chevrier
08db1341a6 find_*: ensure consistent behavior for cache variables
Fixes: #22121
2021-05-12 11:11:56 +02:00
Marc Chevrier
b1729200c3 find_*: refactor cache variable handling 2021-05-11 18:16:08 +02:00
Vitaly Stakhovsky
11425041f0 cmMakefile::GetDefinition: return cmProp 2020-09-02 07:27:32 -04:00
Vitaly Stakhovsky
b36d1bdd9d Single location for cmProp typedef 2020-06-01 08:54:20 -04:00
Vitaly Stakhovsky
a7f2ff16a4 cmState::GetCacheEntryProperty: return cmProp 2020-03-25 14:46:52 -04:00
Vitaly Stakhovsky
bd89133543 cmState::GetCacheEntryValue: return cmProp 2020-03-17 12:09:20 -04:00
Sylvain Joubert
dc00809596 find_*: Add support for REQUIRED keyword
In the same spirit as the REQUIRED keyword on find_package, this will
stop cmake execution with an error on a failed find_program, find_file,
find_path or find_library.
2020-03-06 16:40:26 +01:00
Sylvain Joubert
cc070e66cd cmFindBase: Use in-class member initialization 2020-03-06 16:07:18 +01:00
Kyle Edwards
61960fa466 Merge topic 'add_find_call_debugging'
f3c9396260 Help: Document CMAKE_FIND_DEBUG_MODE
204b8d9f4e find_*: Use debug logging infrastructure
a7ea20649d find_*: Add debug logging infrastructure

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3935
2019-12-20 12:59:50 -05:00
Robert Maynard
a7ea20649d find_*: Add debug logging infrastructure
Enable debug messages a new `--find-debug` command-line option or via
the `CMAKE_FIND_DEBUG_MODE` variable.

This work was started by Chris Wilson, continued by Ray Donnelly, and
then refactored by Robert Maynard to collect information into a single
message per find query.

Co-Author: Ray Donnelly <mingw.android@gmail.com>
Co-Author: Chris Wilson <chris+github@qwirx.com>
2019-12-19 08:09:49 -05:00