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

160 Commits

Author SHA1 Message Date
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
e456dae669 cmConditionEvaluator: Remove extra copy of execution context
The execution context passed to the constructor always matches the top
of the backtrace, so the former can be removed in favor of using only
the latter.
2020-09-28 09:49:08 -04:00
Brad King
dc49abcb89 if,while: Clarify condition backtrace construction
Evaluation of the `elseif`, `else`, and `while` commands takes place
during function blocker evaluation before any actual command execution
takes place.  Therefore they do not have an entry in the backtrace
stack.  Each of their implementations needs to construct an extra
backtrace entry to use in error messages and such.  Each of them used a
slightly different approach due to evolution over time.  Clean up their
construction of the extra backtrace entry and use a named variable to
contain it for clarity.
2020-09-28 09:49:08 -04:00
Brad King
68af831505 cmMakefile: Inline GetExecutionContext at call sites
The method only had one line, and its implementation is more clear
at the call sites than the method name.
2020-09-28 09:49:07 -04:00
Marc Chevrier
8d4a9ee398 Refactoring: rename "cm_static_string_view.hxx" as <cmext/string_view> 2020-04-30 09:53:27 +02: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
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
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
Regina Pfeifer
5558070d52 cmExecutionStatus: Remove function Clear 2019-08-06 10:05:27 +02: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
Regina Pfeifer
28f2d12a05 cmCommand: De-virtualize function InvokeInitialPass 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
Brad King
71fbebd1dc IWYU: Fix handling of <memory> standard header
An old workaround for `std::allocator_traits<>::value_type` lints from
IWYU on `std::vector<>` usage breaks IWYU's handling of `<memory>`.
Convert the workaround to use the same approach we already use for a
workaround of `std::__decay_and_strip<>::::__type` lints.  Then update
the `<memory>` inclusions to follow the now-correct IWYU lints.
2019-07-10 11:48:56 -04: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
Regina Pfeifer
5731ec30f0 clang-tidy: fix warnings from version 7
Fix some warnings that are new since clang-tidy version 4, and update
`.clang-tidy` to suppress the rest.
2018-11-20 10:36:08 -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
Matthias Maennich
f0489856e3 Retire std::auto_ptr and its macro CM_AUTO_PTR
Signed-off-by: Matthias Maennich <matthias@maennich.net>
2017-09-26 00:07:19 +02: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
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
Gregor Jasny
edac95b955 cmIfCommand: Reject duplicate else() and misplaced elseif()
Closes: #14335
2017-03-22 08:42:35 -04:00
Daniel Pfeifer
e81c323da9 Include necessary headers in commands 2016-10-26 09:02:44 +02:00
Daniel Pfeifer
608afd4f62 Separate compilation for commands included in cmBootstrapCommands2 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
Brad King
b5ec5b0901 Avoid using KWSys auto_ptr by adopting it ourselves
Replace use of cmsys::auto_ptr with a CM_AUTO_PTR macro that maps to
our own implementation adopted from the KWSys auto_ptr implementation.
Later we may be able to map CM_AUTO_PTR to std::auto_ptr on compilers
that do not warn about it.

Automate the client site conversions:

    git grep -l auto_ptr -- Source/ | grep -v Source/kwsys/ | xargs sed -i \
      's|cmsys::auto_ptr|CM_AUTO_PTR|;s|cmsys/auto_ptr.hxx|cm_auto_ptr.hxx|'
2016-06-29 09:47:58 -04:00
Stephen Kelly
5bbcf758a1 cmIfCommand: Don't rely on NestedError logic to issue messages 2016-06-13 20:20:44 +02:00
Kitware Robot
d9fd2f5402 Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update
all our C++ code to a new style defined by `.clang-format`.
Use `clang-format` version 3.8.

* 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.
2016-05-16 16:05:19 -04:00
Brad King
e1c7747253 Format include directive blocks and ordering with clang-format
Sort include directives within each block (separated by a blank line) in
lexicographic order (except to prioritize `sys/types.h` first).  First
run `clang-format` with the config file:

    ---
    SortIncludes: false
    ...

Commit the result temporarily.  Then run `clang-format` again with:

    ---
    SortIncludes: true
    IncludeCategories:
      - Regex:    'sys/types.h'
        Priority: -1
    ...

Commit the result temporarily.  Start a new branch and cherry-pick the
second commit.  Manually resolve conflicts to preserve indentation of
re-ordered includes.  This cleans up the include ordering without
changing any other style.

Use the following command to run `clang-format`:

    $ git ls-files -z -- \
        '*.c' '*.cc' '*.cpp' '*.cxx' '*.h' '*.hh' '*.hpp' '*.hxx' |
      egrep -z -v '(Lexer|Parser|ParserHelper)\.' |
      egrep -z -v '^Source/cm_sha2' |
      egrep -z -v '^Source/(kwsys|CursesDialog/form)/' |
      egrep -z -v '^Utilities/(KW|cm).*/' |
      egrep -z -v '^Tests/Module/GenerateExportHeader' |
      egrep -z -v '^Tests/RunCMake/CommandLine/cmake_depends/test_UTF-16LE.h' |
      xargs -0 clang-format -i

This selects source files that do not come from a third-party.

Inspired-by: Daniel Pfeifer <daniel@pfeifer-mail.de>
2016-04-29 13:58:54 -04:00
Brad King
180538c706 Source: Stabilize include order
Each source file has a logical first include file.  Include it in an
isolated block so that tools that sort includes do not move them.
2016-04-29 13:58:31 -04:00
Brad King
7503deb2c5 cmIfCommand: Simplify execution context construction 2016-04-15 08:29:42 -04:00
Brad King
2379b3ae31 cmConditionEvaluator: Remove GetConditionContext method
All it does is call cmListFileContext::FromCommandContext, so move this
to the call sites.
2016-03-29 10:10:20 -04:00
Brad King
e2d4bfef3f Merge topic 'fix-CMP0054-elseif-warning'
d6a03b47 cmIfCommand: Issue CMP0054 warning with appropriate context. (#15802)
2015-10-21 09:16:49 -04:00
Stephen Kelly
d6a03b475e cmIfCommand: Issue CMP0054 warning with appropriate context. (#15802)
Commit v3.4.0-rc1~494^2~4 (cmMakefile: Add API for elseif to create
backtrace., 2015-05-29) removed the use of cmMakefileCall to push/pop
execution context in favor of a new way to create backtraces.

However, a call to cmMakefile::GetExecutionContext is still invoked to
issue a contextual CMP0054 warning through cmConditionEvaluator.  As
the elseif is not part of the call stack, this resulted in trying to
access an empty vector.

Avoid the attempt at getting execution context when evaluating elseif by
constructing a context and backtrace on behalf of the cmConditionEvaluator
in all cases.
2015-10-20 23:40:12 +02:00
Stephen Kelly
09466690f0 Add cmOutputConverter include where needed. 2015-10-05 20:58:06 +02:00
Stephen Kelly
59e21ffa13 Port static calls from cmLocalGenerator to cmOutputConverter. 2015-06-06 09:15:58 +02:00
Stephen Kelly
b68f2ea8ae cmMakefile: Add API for elseif to create backtrace. 2015-06-03 01:03:58 +02:00
Stephen Kelly
9486769866 Don't use a cmLocalGenerator instance to call static methods. 2015-05-14 20:30:09 +02:00
Rolf Eike Beer
51f8de8102 if(): avoid one needless string compare for all if() statements
If it's known that it is an "if" it can't be an "elseif".
2015-02-22 13:48:30 +01:00
Stephen Kelly
fd7b371293 Replace foo.size() pattern with !foo.empty(). 2015-01-18 14:25:24 +01:00
Stephen Kelly
930bd47816 Replace 'foo.size() == 0' pattern with foo.empty(). 2015-01-18 14:25:24 +01:00
Gregor Jasny
0de867dde2 continue: Add a new CMake language command for loop continuation (#14013)
Inspired-by: Doug Barbieri
Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
2014-12-01 09:50:49 -05:00
Nils Gladitz
188a1f236e If: Introduce policy CMP0054 - don't dereference quoted variables in if() 2014-09-11 21:23:17 +02:00
Nils Gladitz
b900c1ccaa If: Extract cmConditionEvaluator from if() implementation 2014-09-11 21:17:09 +02:00
Ben Boeckel
f718b30a95 ClearMatches: Only clear matches which were actually set
ClearMatches was clearing many variables which were never set in the
first place. Instead, store how many matches were made last time and
only clear those. It is moved to the cmMakefile class since it is a
common utility used by multiple commands.
2014-04-29 16:00:05 -04:00