Commit Graph

106 Commits

Author SHA1 Message Date
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
Brad King
292048874f CMP0048: Remove support for OLD behavior 2025-01-19 09:41:03 -05:00
Craig Scott
e5a9ccbcc8 project: Always set <PROJECT-NAME>_* as normal variables
Re-introduce the behavior originally introduced in CMake 3.30.3 by
commit c1ece78d11 (project: non cache <project> prefix variables are
also created, 2024-08-27, v3.30.3~2^2), but this time with a policy for
compatibility.

Issue: #25714
Issue: #26243
2024-10-08 10:07:11 -04:00
Craig Scott
fa07ddfebf project: Only check non-cache vars when setting project vars
The change in commit 86ad7cc886 (project: Only define non-cache vars if
already defined, 2024-09-15, v3.30.4~2^2) was meant to only check for
non-cache variables when deciding whether to set non-cache project
variables for the current call.  However, it erroneously checked for any
variable, including cache variables.  This gives the intended result on
the first run, but on subsequent runs a cache variable will exist that
did not on the first run, leading to different behavior between the two
runs.  Fix the logic to only check for a pre-existing non-cache
variable, as was originally intended.

Fixes: #26355
2024-10-07 10:24:37 -04:00
Craig Scott
86ad7cc886 project: Only define non-cache vars if already defined
In c1ece78d11 (project: non cache <project> prefix variables are
also created, 2024-08-27), we started explicitly setting the non-cache
variable for <projectName>_SOURCE_DIR, <projectName>_BINARY_DIR,
and <projectName>_IS_TOP_LEVEL in addition to setting them as
cache variables. This changed the behavior when a project name
was used more than once, and the second project call happens in
the same scope or a child scope of the first. Previously, the first
project call would set cache variables, and the second project call
would not overwrite those cache variables. With the change in
c1ece78d11, after the second project call the non-cache variables
would mask the cache variables and the project code would see
a different value to what it did before.

Setting the non-cache variable was added to handle the case where
a call to FetchContent_MakeAvailable() would set some non-cache
variables, and it just so happened those matched the same cache
variables that the project() command would set in the project being
fetched. The fetched project would then see a different set of
project-specific variables compared to when it was built standalone.

This commit here narrows the change from c1ece78d11 such that
the non-cache variable is only set by project() if there was already
a non-cache variable set. This still fixes the motivating problem
c1ece78d11 was intended to solve, but it avoids changing the variable
values seen by a project that re-uses the same project name in related scopes.

Issue: #26243, #25714
Fixes: #26281
2024-09-20 10:33:25 -04:00
Robert Maynard
c1ece78d11 project: non cache <project> prefix variables are also created
Fixes #26243, #25714
2024-08-27 12:37:07 -04:00
Cristian Le
b37b912e8f CMAKE_PROJECT_INCLUDE: Allow to run module files
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
2023-10-18 18:01:05 +02:00
Cristian Le
704acca96b CMAKE_PROJECT_INCLUDE: Add support for including multiple files
Fixes: #25341
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
2023-10-18 13:39:55 +02: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
friendlyanon
59573bf5b9 project: Warn at top-level if cmake_minimum_required wasn't called
The top-level project() call will now issue an AUTHOR_WARNING if it
wasn't called after cmake_minimum_required().

Fixes: #24071
2022-11-11 22:49:36 +01: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
Ben Boeckel
6ff03d463f clang-tidy: address google-readability-casting lints
At least those involving `static_cast`.
2022-05-24 09:09:43 -04: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
Marc Chevrier
16208ac113 CMP0126: Add control for warnings
Fixes: #22353
2021-06-29 13:36:28 +02:00
friendlyanon
96a7040107 project: Define variables indicating whether project is top level
Define `PROJECT_IS_TOP_LEVEL` and `<PROJECT-NAME>_IS_TOP_LEVEL`.  The
latter is a STATIC cache entry just like other `<PROJECT-NAME>_*`
variables so that it is globally scoped.

Issue: #20310
Fixes: #21961
2021-03-26 09:35:34 -04:00
Asit Dhal
3c324689a7 include: refactor call sites of cmMakefile::ReadDependentFile
Fixes: #16773
2020-10-21 11:20:37 +02:00
Vitaly Stakhovsky
11425041f0 cmMakefile::GetDefinition: return cmProp 2020-09-02 07:27:32 -04:00
Vitaly Stakhovsky
f37c14e930 Source: use cmNonempty() 2020-07-28 08:31:31 -04:00
Vitaly Stakhovsky
36a5b3d1d1 cmMakefile::AddCacheDefinition: Add overload that accepts std::string value 2020-03-11 09:40:43 -04:00
Craig Scott
cdcc173e23 Merge topic 'project-version-buffer-overflow'
82cdb26c93 project: Fix potential buffer write-past-end for version components
15a0b0d046 Help: math() expressions must be representable as signed 64-bit

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3948
2019-10-28 06:50:22 -04:00
Craig Scott
82cdb26c93 project: Fix potential buffer write-past-end for version components
This fixes two errors: not accounting for the trailing null and a
misunderstanding of what std::numeric_limits::digits10 means.
2019-10-26 17:50:24 +11:00
Deniz Bahadir
f7acc1266c project: Add variable CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE
Follow up commit 0761186949 (project: Add variable
CMAKE_PROJECT_INCLUDE_BEFORE, 2019-03-28, v3.15.0-rc1~294^2) with a
project-specific variant.  This variable will be used similar to the
already existing `CMAKE_PROJECT_INCLUDE_BEFORE` and
`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE` variables.

Fixes: #19854
2019-10-18 14:44:24 -04:00
Kitware Robot
ed98209ddc Revise include order using clang-format-6.0
Run the `clang-format.bash` script to update our C and C++ code to a new
include order `.clang-format`.  Use `clang-format` version 6.0.
2019-10-01 12:26:36 -04:00
Regina Pfeifer
77aa75b8dc cmProjectCommand: Port away from cmCommand 2019-09-21 05:13:30 +02:00
Asit Dhal
9dba84cfa5 Refactor: Use cmStrCat to construct error strings
Replace string construction using std::stringstream with cmStrCat and
cmWrap.
2019-09-18 14:18:46 -04:00
Brad King
de0a2354fc IWYU: Add missing cstddef includes for size_t and nullptr_t
The IWYU tool we use for CI now diagnoses these.
2019-09-03 11:46:52 -04:00
Sebastian Holtermann
9b334397f5 Source sweep: Use cmStrCat for string concatenation
This patch is generated by a python script that uses regular expressions to
search for string concatenation patterns of the kind

```
std::string str = <ARG0>;
str += <ARG1>;
str += <ARG2>;
...
```

and replaces them with a single `cmStrCat` call

```
std::string str = cmStrCat(<ARG0>, <ARG1>, <ARG2>, ...);
```

If any `<ARGX>` is itself a concatenated string of the kind

```
a + b + c + ...;
```

then `<ARGX>` is split into multiple arguments for the `cmStrCat` call.

If there's a sequence of literals in the `<ARGX>`, then all literals in the
sequence are concatenated and merged into a single literal argument for
the `cmStrCat` call.

Single character strings are converted to single char arguments for
the `cmStrCat` call.

`std::to_string(...)` wrappings are removed from `cmStrCat` arguments,
because it supports numeric types as well as string types.

`arg.substr(x)` arguments to `cmStrCat` are replaced with
`cm::string_view(arg).substr(x)`
2019-08-22 16:38:10 +02:00
Sebastian Holtermann
f71f7ce3f0 cmStringAlgorithms: Move string functions to the new cmStringAlgorithms.h
This adds the `cmStringAlgorithms.h` header and moves all string functions
from `cmAlgorithms.h` to `cmStringAlgorithms.h`.
2019-07-29 21:13:56 +02:00
Sebastian Holtermann
e91bfe440c cmMakefile: Let AddDefinition accept a value as cm::string_view
This changes `cmMakefile::AddDefinition` to take a `cm::string_view` as value
argument instead of a `const char *`.

Benefits are:
- `std::string` can be passed to `cmMakefile::AddDefinition` directly without
  the `c_str()` plus string length recomputation fallback.
- Lengths of literals passed to `cmMakefile::AddDefinition` can be computed at
  compile time.

In various sources uses of `cmMakefile::AddDefinition` are adapted to avoid
`std::string::c_str` calls and the `std::string` is passed directly.
Uses of `cmMakefile::AddDefinition`, where a `nullptr` `const char*` might
be passed to `cmMakefile::AddDefinition` are extended with `nullptr` checks.
2019-07-24 11:11:25 +02:00
Alex Turbov
0ba5891ead project: Keep leading 0 in PROJECT_VERSION components
Introduce CMake policy `CMP0096` to make `project()` keep leading zeros
in version components.  As a side effect, it now allows really long
version numbers.

Fixes: #19421
Co-Author: Brad King <brad.king@kitware.com>
2019-07-16 07:48:40 -04:00
Alex Turbov
b1f387a7ea Refactor: Use raw string literals instead of escaping 2019-07-15 08:17:36 -04:00
Alex Turbov
41b85968d8 Refactor: Use initializer lists instead of push_back series 2019-07-15 08:17:36 -04:00
Alex Turbov
45e85dd2b2 Refactor: Add some const to vars 2019-07-15 08:17:36 -04:00
Alex Turbov
90f91e4d21 Refactor: Replace a "magic" number w/ a named constant 2019-07-15 08:17:36 -04:00
Alex Turbov
638383c38f Refactor: Eliminate one-time-used variables 2019-07-15 08:17:36 -04:00
Alex Turbov
9b6a53292f Refactor: Eliminate sep from the loop 2019-07-15 08:17:34 -04:00
Brad King
0dfb056cd3 Merge topic 'pr.projectbefore'
0761186949 project: Add variable CMAKE_PROJECT_INCLUDE_BEFORE

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3175
2019-04-04 11:32:41 -04:00
Artur Ryt
30bb14c657 Modernize: Enable modernize-raw-string-literal in clang-tidy 2019-04-02 19:59:54 +02:00
Ruslan Baratov
0761186949 project: Add variable CMAKE_PROJECT_INCLUDE_BEFORE 2019-04-01 20:30:19 +03:00
Ruslan Baratov
dda0190458 project: Add variable CMAKE_PROJECT_INCLUDE 2019-03-27 22:39:02 +03:00
Regina Pfeifer
ef61997b1b clang-tidy: Use emplace 2019-01-17 13:12:02 -05:00
Bruno Manganelli
cc2a5261f8 Factor out enum MessageType into dedicated header
Reduce the number of files relying on `cmake.h`.
2019-01-16 08:16:31 -05:00
Craig Scott
f8a086a86b project(): Ensure DESCRIPTION and HOMEPAGE_URL variables are set
If a project() call does not have DESCRIPTION or HOMEPAGE_URL
options, it must still set the relevant variables or else those variables will
inherit values from an earlier project() call. That is inconsistent with how
VERSION is handled and is likely to be unexpected. The docs were also
ambiguous about what should happen in such cases.
2018-10-08 08:28:17 +11:00
Vitaly Stakhovsky
c8fd23ec6f cmMakefile: return directories as const std::string& 2018-08-27 14:07:43 -04:00
Brad King
6646771b0f project: Do not issue CMP0048 warnings on injected call
Fixes: #18202
2018-07-24 13:14:10 -04:00
Alex Turbov
af1c48871c CPack: Use project version as default for CPACK_PACKAGE_VERSION
* Introduce `CMAKE_PROJECT_VERSION` and the corresponsing components:
  `CMAKE_PROJECT_VERSION_MAJOR`, `CMAKE_PROJECT_VERSION_MINOR`,
  `CMAKE_PROJECT_VERSION_PATCH` and `CMAKE_PROJECT_VERSION_TWEAK`.

* `CPack` module use `CMAKE_PROJECT_VERSION_MAJOR`,
  `CMAKE_PROJECT_VERSION_MINOR` and `CMAKE_PROJECT_VERSION_PATCH`
  to initialize corresponsing CPack variables.
2018-05-03 08:26:03 +10:00
Alex Turbov
73f9b2974c project: Add HOMEPAGE_URL named parameter
This sets variables like PROJECT_HOMEPAGE_URL, which can be
used as default values for various things (packaging modules,
doxygen defaults, etc.). Some packaging modules have been
updated to do this as part of this commit.

Co-Author: Craig Scott <craig.scott@crascit.com>
2018-03-17 08:25:48 +11:00
Craig Scott
fd28c382b4 project: Add <PROJECT-NAME>_DESCRIPTION
For consistency with the VERSION keyword, also define the
<PROJECT-NAME>_DESCRIPTION variable.
2018-03-17 08:25:48 +11:00
Alex Turbov
587bad7ba2 project: warn on metadata arguments missing values
Warn if `DESCRIPTION` or `VERSION` is given without a following value.
2018-03-07 09:35:59 -05:00