1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-05-11 23:57:42 +08:00

92 Commits

Author SHA1 Message Date
Alex Turbov
d34971f455 Refactor: Eliminate redundant std::to_string as arg of cmStrCat
Plus optimize some other string operations in the modified files.
2025-01-26 04:03:38 +04:00
Alex Turbov
bc8621d999
Fix: A lot of typos in code found by typos
Yet another great code spellchecker: https://github.com/crate-ci/typos/

(Will be added later as a `pre-commit` hook)
2025-01-12 18:49:34 +04:00
Brad King
86698eea85 cmake_language: Fix EXIT inside control flow blocks
These were missed in commit 1bb1769235 (cmake_language: Add EXIT
subcommand, 2024-01-05, v3.29.0-rc1~112^2).

Fixes: #25674
2024-02-14 08:51:48 -05:00
Marc Chevrier
45f17e5a85 cmList: Add container conversion to string 2023-06-22 15:44:17 +02:00
Marc Chevrier
838a5fae23 return(): Propagate variables to result scope
Fixes: #23871
2022-09-03 23:10:01 +02:00
Kyle Edwards
8aee7fdb32 cmState: Prohibit override of flow control commands 2020-10-22 17:04:31 -04:00
Oleksandr Koval
e614528ad1 cmListFileCache: Make cmListFileFunction a shared pointer
Passing cmListFileFunction everywhere by-value involves big overhead.
Now cmListFileFunction stores std::shared_ptr to the underlying data.
2020-10-01 14:28:03 +03:00
Brad King
727ed0c403 cmMakefile: Simplify ExpandArguments signature
The only call sites that pass the explicit file name argument are in
function blocker `ArgumentsMatch` methods for `function` and `macro`.
We already ensure that they are balanced within a file scope, and the
RAII helpers `BuildsystemFileScope` and `ListFileScope` ensure that the
backtrace and execution list file stacks unwind to the matching level.
Therefore we can assume that the file name where we are checking for
matching arguments matches starting file name where those arguments
first appeared, and do not need to pass it explicitly.
2020-09-28 09:49:08 -04:00
Marc Chevrier
8d4a9ee398 Refactoring: rename "cm_static_string_view.hxx" as <cmext/string_view> 2020-04-30 09:53:27 +02:00
Marc Chevrier
f7d12609f0 Refactoring: use append functions from cmext/algorithm 2019-12-17 10:44:02 +01:00
Alex Turbov
90e3e2a777 cmFunctionCommand: Introduce CMAKE_CURRENT_FUNCTION* variables
`CMAKE_CURRENT_FUNCTION`
  Can be used for diagnostic or debugging messages like the
  `__PRETTY_FUNCTION__` macro of GCC.

`CMAKE_CURRENT_FUNCTION_LIST_DIR`
  Eliminates the necessity of the additional "global"
  variables inside a module used to access additional "resource"
  files from functions defined in the module.

...
2019-12-10 16:43:27 +02:00
Alex Turbov
dd54290dab Refactor: Modernize function command 2019-12-07 19:25:44 +02:00
Marc Chevrier
c688b401d3 cmstd: Modernize CMake system headers
Provide a standardized way to handle the C++ "standard" headers
customized to be used with current CMake C++ standard constraints.
Offer under directory `cm` headers which can be used as direct
replacements of the standard ones.  For example:

    #include <cm/string_view>

can be used safely for CMake development in place of the `<string_view>`
standard header.

Fixes: #19491
2019-09-20 10:01:37 -04:00
Regina Pfeifer
d25a5a7ec9 clang-tidy: modernize-use-auto
Set the MinTypeNameLength option to an impossibly high value in order
to limit the diagnostics to iterators.  Leave new expressions and cast
expressions for later.
2019-09-10 22:21:41 +02:00
Sebastian Holtermann
3b2b02825d Source sweep: Replace std::ostringstream when used with a single append
This replaces `std::ostringstream`, when it is written to only once.
If the single written argument was numeric, `std::to_string` is used instead.
Otherwise, the single written argument is used directly instead of the
`std::ostringstream::str()` invocation.
2019-08-23 18:52:33 +02: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
Gabor Bencze
9bbe95a0e7 cmCommand refactor: cmFunctionCommand 2019-08-20 14:42:19 -04:00
Regina Pfeifer
41364824ad cmFunctionBlocker: Recycle functions 2019-07-31 13:22:42 -04:00
Regina Pfeifer
6491270e0d cmFunctionBlocker: Move check for matching args 2019-07-31 00:03:17 +02:00
Regina Pfeifer
af24e4ef6e cmFunctionBlocker: Move common logic to base 2019-07-31 00:03:17 +02:00
Regina Pfeifer
ef38ff22f7 cm*FunctionBlocker: Extract function Replay 2019-07-31 00:03:17 +02:00
Regina Pfeifer
c76500949d cm*FunctionBlocker: Move to source file 2019-07-30 17:21:50 +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
Regina Pfeifer
de77d355ac cmState: Add scripted commands by value 2019-07-21 09:25:32 +02:00
Daniel Pfeifer
1eebc29563 cmCommand: deprecate functions GetMakefile and SetError
Replace the members for the Makefile and the Error with a
cmExecutionStatus.  Re-implement GetMakefile and SetError based on that.

Both functions should be called directly on the cmExecutionStatus that is
passed to InitialPass.  This will help us make all Commands immutable and
remove the need for cloning.
2019-07-21 09:25:32 +02:00
Sebastian Holtermann
3bed969dac cmMakefile: Modernize AddFunctionBlocker method to accept a std::unique_ptr 2019-07-17 14:58:27 +02:00
Marc Chevrier
1591f138f1 modernize: manage cmCommand instances using unique_ptr. 2019-07-14 15:37:30 +02:00
Sebastian Holtermann
006229278b Use cmAppend to append ranges to std::vector instances 2019-05-23 16:19:49 +02:00
Regina Pfeifer
9eb0e73f46 cmRange: Move to dedicated header file 2019-02-21 08:24:25 -05:00
Regina Pfeifer
094f01d0f0 cleanup: Prefer compiler provided special member functions 2019-01-25 06:45:00 -05:00
Regina Pfeifer
55671b41d2 clang-tidy: Use = default
Suppress some cases in `Source/cmGeneratorExpressionNode.cxx` and
`Source/cmUVHandlePtr.h` where a few older compilers require a
user-defined default constructor (with `{}`).
2019-01-25 06:44:32 -05:00
Florian Jacomme
b1a05d6c76 Revise implementation of case-insensitive command names
Store both the as-written and lower-case command names and use
the latter to avoid case-insensitive string comparisons.

With this I obtain 2-6% speed increase (on Windows) for the configure
step with no significant changes in memory usage.  A case-insensitive
comparison is a lot slower than just calling `==` because the operator
will use things like memcmp, so prefer the latter.

The `cmSystemTools::LowerCase` function allocates a new string each time
it is called, so before this change we were allocating in:

* cmMakefile::Configure two times for each function
  (to look for `cmake_minimum_required` and `project`)
* cmMakefile::ExecuteCommand twice by function by calling
  cmState::GetCommand and copying the name

Now we are only allocating once by function instead of four.
2018-05-22 10:56:24 -04:00
Brad King
0b33aee48b Use C++11 override instead of CM_OVERRIDE
We now require C++11 support including `override`.  Drop use of
the old compatibility macro.  Convert references as follows:

    git grep -l CM_OVERRIDE -- '*.h' '*.hxx' '*.cxx' |
      xargs sed -i 's/CM_OVERRIDE/override/g'
2017-09-15 10:06:41 -04:00
Pavel Solodovnikov
7d5095796a Meta: modernize old-fashioned loops to range-based for.
Changes done via `clang-tidy` with some manual fine-tuning
for the variable naming and `auto` type deduction
where appropriate.
2017-09-12 16:22:47 +03:00
Daniel Pfeifer
a1218f59d9 cmCommand: remove unused methods from interface and all implementations 2017-05-11 19:49:06 +02:00
Daniel Pfeifer
a44dab461f cmState: introduce method for adding scripted commands 2017-05-11 19:49:06 +02:00
Brad King
99b1ff714b Merge topic 'dead-code-removal'
fdd341eb cmFindCommon: remove unused function SetMakefile
67a8d907 cmExecutionStatus: Remove arguments from setters
0c519c70 bootstrap: Remove leftovers from cmBootstrapCommands

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !821
2017-05-11 09:54:19 -04:00
Daniel Pfeifer
67a8d907ad cmExecutionStatus: Remove arguments from setters
The setters are only used to set boolean values.  The values are never
reset individually.
2017-05-09 23:49:14 +02:00
Daniel Pfeifer
44c0b2b75a cmCommand: remove IsScriptable 2017-05-08 22:58:01 +02:00
Daniel Pfeifer
2e620f0b38 Fix several include-what-you-use findings 2016-11-08 09:42:04 -05:00
Daniel Pfeifer
e81c323da9 Include necessary headers in commands 2016-10-26 09:02:44 +02:00
Brad King
c1b96fddf8 Merge topic 'remove-cmobject-uses'
2214011f Make cmCPackGenerator not inherit from cmObject
7f9a8d53 Make cmCPackGeneratorFactory not inherit from cmObject
fb0b087c Make cmCTestGenericHandler not inherit from cmObject
2169b0fa Make cmCPackLog not inherit from cmObject
9855ebf1 Make cmCommand not inherit from cmObject
2016-10-24 10:16:43 -04:00
Daniel Pfeifer
9855ebf11a Make cmCommand not inherit from cmObject 2016-10-23 00:45:08 +02:00
Daniel Pfeifer
64f9c282f3 Separate compilation for commands included in cmBootstrapCommands1 2016-10-21 18:14:51 +02: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
516f8edb2e Avoid else after return 2016-09-16 22:45:24 +02:00
Daniel Pfeifer
73f648f167 use empty method to check for emptyness 2016-09-15 23:59:29 +02:00
Brad King
f1ad71d7f8 cmMakefile: Restore nested error logic use of cmExecutionStatus
Since commit 14a8d61f (cmMakefile: Port nested error logic away from
cmExecutionStatus) we fail to continue processing function and macro
bodies after non-fatal errors.  A non-fatal error should not stop
foreach loops, macro bodies, nested bodies, or the outer script.
Add a test covering these cases, and revert the change to fix them.

Also revert commit 2af853de (cmMakefile: Simplify IssueMessage
implementation) because the assertion it added (which was removed by the
above commit and is restored by reverting it) is incorrect.  We do have
code paths that call cmMakefile::IssueMessage with an empty execution
stack, such as in CheckForUnusedVariables's LogUnused call.
2016-09-06 16:20:39 -04:00
Stephen Kelly
14a8d61fd4 cmMakefile: Port nested error logic away from cmExecutionStatus
It is no longer needed.
2016-08-25 09:47:26 -04:00