Commit Graph

369 Commits

Author SHA1 Message Date
Brad King
5e0b06fe84 Makefiles: Restore path consistency in the global dispatch makefile
Directory-level rules in `CMakeFiles/Makefile2` were previously
previously written by each directory's local generator using its own
decision for using relative or absolute paths.

Since commit d33b12d84b (Add support for build tree symlink inside
source tree, 2022-02-25, v3.24.0-rc1~583^2), each local generator
explicitly models the relationship between its source and build paths,
and uses this to determine when it is safe to use relative paths.
Because `add_subdirectory` supports arbitrary placement of the source
and build directories, different local generators may have different
relationships between their source and build paths.  This can cause
disagreement among rules written to `CMakeFiles/Makefile2`.

Restore consistency by always using the root local generator to write
rules to `CMakeFiles/Makefile2`.  Relative paths should always be
expressed w.r.t. the top-level build directory since that is the working
directory in which the `make` tool processing the file will run.

Fixes: #23814
2022-08-03 14:58:47 -04:00
Carsten Rudolph
193b8fca52 cmBuildOptions: Split build arguments into separate object. 2022-01-22 06:35:38 -05:00
Marc Chevrier
cc56dc7468 Rename cmProp in cmValue 2021-09-21 17:14:04 +02:00
NAKAMURA Takumi
7cb4ad7e39 cmGlobalCommonGenerator: Adopt GetEditCacheCommand
Move the implementation from the Makefile generator so it can be
later used by the Ninja generator too.
2021-06-29 11:07:14 -04:00
Brad King
d8d0f3ec37 Makefiles: Remove non-functioning relative path conversion
In CMake 3.6 and below, running

    cmake --build . --target "$(pwd)/SomeTarget"

with a Makefiles generator automatically converted the target
name and invoked `make SomeTarget`.  This made the build command
work even though

    make "$(pwd)/SomeTarget"

would fail.  This behavior was not implemented for any other generators,
and does not make sense because `cmake --build` is supposed to be a thin
wrapper around the native build tool.  It has also been broken since
commit 8d47a20f13 (cmOutputConverter: use new ConvertToRelativePath
signature internally, 2016-06-16, v3.7.0-rc1~90^2~1) because cmState's
relative path conversion logic is not initialized in `cmake --build`.

Remove the non-functioning code.
2021-05-17 10:01:57 -04:00
Brad King
15fa320071 cmLocalGenerator: Factor out relative path conversion helpers
Most calls to `MaybeConvertToRelativePath` use one of our common work
directories (e.g. top of the build tree) as the local path.  Add helpers
for each of the common cases to simplify and clarify call sites.
2021-05-13 12:47:25 -04:00
Brad King
ba7b939831 cmStateDirectory: Rename ConvertToRelPathIf{Not => }Contained
The "Not" in the method name is backward from its logic.
2021-05-12 15:53:37 -04:00
Josef Angstenberger
5950e54325
Source: Fix typos and spelling in comments 2021-05-07 17:00:18 +02:00
Oleksandr Koval
209daa20b2 Code style: add missed explicit 'this->'
CMake uses explicit 'this->' style. Using custom clang-tidy check we can
detect and fix places where 'this->' was missed.
2021-01-05 14:32:36 +02:00
Marc Chevrier
afd0f6785d Refactoring: Abstract Makefile line continuation format 2020-11-28 16:02:58 +01:00
Oliver Schneider
378c047ae3 Makefiles: Explicitly tell 'make' tool what Makefile name to use
CMake did not specify the filename of the Makefile generated by it.
Due to GNU make precedence rules this means that the presence of a
GNUmakefile or makefile would take precedence over the generated
Makefile.

This is only relevant for in-source builds and only whenever an
alternative makefile by the above mentioned names exists.

This patch adds the (seemingly universal) `-f` switch and the
(hardcoded) filename (it is now hardcoded separately in these two
files):

- cmLocalUnixMakefileGenerator3.cxx
- cmGlobalUnixMakefileGenerator3.cxx

Fixes: #21418
2020-11-16 11:34:53 -05:00
Fred Baksik
f4c7d44d82 Makefiles: Use -j option as "-jN" and not "-j N"
Fixes: #21090
2020-10-26 18:32:59 -04:00
vvs31415
d298ae7470 cmake::GetCacheDefinition: Return cmProp 2020-09-28 09:32:22 -07:00
Brad King
e7edba2baf Makefiles: Use IsInBuildSystem in global generator target type checks
Follow up from commit 422d9a0ab2 (Factor out generator checks for
filtering out interface libraries, 2020-07-20) with more uses of
`IsInBuildSystem`.
2020-08-03 10:04:22 -04:00
Brad King
422d9a0ab2 Factor out generator checks for filtering out interface libraries
Add a `cmGeneratorTarget::IsInBuildSystem` helper method to tell
generators whether a target should participate in the generated build
system.
2020-07-23 13:31:44 -04:00
Brad King
e3b5abd068 Merge topic 'fix-typos-identified-using-codespell'
207373802e Fix typos identified using codespell

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5040
2020-07-23 08:28:21 -04:00
Jean-Christophe Fillion-Robin
207373802e Fix typos identified using codespell
See https://github.com/codespell-project/codespell#readme

The following command was used:

```
codespell -q6 --skip="\
.git,\
*.json,\
./Copyright.txt,\
./Help/command/foreach.rst,\
./Help/prop_test/REQUIRED_FILES.rst,\
./Help/variable/CTEST_COVERAGE_COMMAND.rst,\
./Modules/CMakeCheckCompilerFlagCommonPatterns.cmake,\
./Modules/CMakeRCInformation.cmake,\
./Modules/Internal/CPack/NSIS.template.in,\
./Modules/FindMatlab.cmake,\
./Modules/MatlabTestsRedirect.cmake,\
./Modules/Platform/Windows-Clang.cmake,\
./Modules/Platform/Windows-Intel-Fortran.cmake,\
./Modules/Platform/Windows-MSVC.cmake,\
./Source/CMakeVersion.cmake,\
./Source/cmConvertMSBuildXMLToJSON.py,\
./Source/cmCreateTestSourceList.cxx,\
./Source/cmGlobalVisualStudio10Generator.cxx,\
./Source/cmExportBuildFileGenerator.cxx,\
./Source/cmExportInstallAndroidMKGenerator.cxx,\
./Source/cmExportInstallFileGenerator.cxx,\
./Source/cmExportSet.cxx,\
./Source/cmExportTryCompileFileGenerator.cxx,\
./Source/cmFindPackageCommand.cxx,\
./Source/cmInstallCommand.cxx,\
./Source/cmGeneratorExpressionLexer.cxx,\
./Source/cmLocalVisualStudio7Generator.cxx,\
./Source/cmOrderDirectories.cxx,\
./Source/cmTarget.cxx,\
./Source/kwsys/*,\
./Source/QtDialog/CMakeSetupDialog.ui,\
./Source/CPack/WiX/cmWIXRichTextFormatWriter.cxx,\
./Source/CTest/cmParseCoberturaCoverage.h,\
./Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in,\
./Tests/RunCMake/CPack/tests/DMG_SLA/English.license.rtf,\
./Tests/RunCMake/CPack/tests/DMG_SLA/German.license.txt,\
./Tests/RunCMake/CPack/tests/DMG_SLA/German.menu.txt,\
./Tests/RunCMake/GoogleTest/xml_output.cpp,\
./Tests/RunCMake/Make/TargetMessages*,\
./Utilities/*,\
" \
-L "\
dependees,\
endwhile,\
fo,\
filetest,\
helpfull,\
nd,\
objext,\
stoll,\
supercedes,\
superceded,\
vas,\
varn,\
"
```
2020-07-22 12:44:47 -04:00
Joerg Bornemann
2cdaf43d96 Allow generator expressions in the EXCLUDE_FROM_ALL target property
This allows for setting EXCLUDE_FROM_ALL, conditional on the build
configuration. However, only the Ninja Multi-Config generator supports
different property values per config. All other multi-config
generators will yield an error in that situation.

Fixes: #20923
2020-07-21 17:16:26 +02:00
Vitaly Stakhovsky
b36d1bdd9d Single location for cmProp typedef 2020-06-01 08:54:20 -04:00
Brad King
d74e651b78 Makefiles: Re-implement makefile target path escaping and quoting
Previously we used `cmSystemTools::ConvertToOutputPath` which internally
used KWSys methods

* SystemTools::ConvertToUnixOutputPath
* SystemTools::ConvertToWindowsOutputPath

These were written in very early days of CMake and have some
limitations:

* They do not encode all characters.  E.g. '#' is left out.
* They attempt to do some path cleanup and handle existing quotes.
  These days CMake has clean unquoted paths already.
* They attempted to encode paths both for makefile targets and
  for shell command lines.  The latter use has mostly been replaced.
* Choosing between the two methods depends on a global variable!
  Several code paths in CMake have to copy the global generator's
  member ForceUnixPaths variable over to the cmSystemTools global.

Re-implement the `ConvertToMakefilePath` method to drop use of those
methods.  Compute suitable makefile target path escaping and quoting
via local logic.  Add support for more characters like '#'.

Fixes: #20555
2020-04-15 08:34:49 -04:00
Brad King
031bfaa865 Makefiles: Factor out makefile target path escaping and quoting
Code paths that write makefile target paths use a combination of
`cmSystemTools::ConvertToOutputPath` and `cmMakeSafe`.  Some were
missing the latter.  Wrap these two steps up into a dedicated
`ConvertToMakefilePath` method provided on both the local and global
generators.
2020-04-15 08:34:48 -04:00
Brad King
af7de05853 Makefiles: Do not use '\#' escape sequence with Windows-style make tools
Since commit fbf7a92975 (Makefile: Handle '#' in COMPILE_OPTIONS,
2014-08-12, v3.1.0-rc1~174^2) we escape `#` as `\#` in `flags.make`
variable assignments so that they are not treated as a comment.
Windows-style make tools like NMake do not interpret backslashes
in that way.  Other means will be needed to handle `#` in contexts
where it is even possible.  The test suite is not covering this
for NMake anyway, and actually has a workaround in `Tests/TryCompile`
for the old behavior, which we can now update.
2020-04-15 08:34:18 -04:00
Brad King
d6119e2305 Merge topic 'cleanup-endls-1'
3fdd8db3aa Refactor: Avoid `std::endl` where it's not necessary (part 1)

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4513
2020-03-27 07:51:27 -04:00
Brad King
a6611577c3 Merge topic 'cmprop-getglobalprop'
c84cf42897 cmState::GetGlobalProperty: return cmProp

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4521
2020-03-27 07:50:28 -04:00
Alex Turbov
3fdd8db3aa Refactor: Avoid std::endl where it's not necessary (part 1)
The `std::endl` manupulator, except inserting `\n` character, also
performs `os.flush()`, which may leads to undesired effects (like
disk I/O in the middle of forming data strings). For the
`std::stringstream` it also has no meaning.
2020-03-26 11:36:57 +08:00
Vitaly Stakhovsky
c84cf42897 cmState::GetGlobalProperty: return cmProp 2020-03-25 09:10:46 -04:00
Brad King
12b39aef75 Remove redundant calls to CollapseFullPath
Remove calls where it is known the input is already a collapsed
full path.
2020-03-24 10:10:06 -04:00
Marc Chevrier
557cecdc3d Modernize memory management
Update internals of various classes
2020-02-27 11:11:30 +01:00
Hugh Sorby
e46e3442fd Makefiles: Re-run CMake if file configured in subdirectory is missing
Add files configured by all subdirectories to `CMAKE_MAKEFILE_PRODUCTS`
rather than just those from the top level.

Fixes: #19719
2020-02-14 08:50:15 -05:00
Robert Maynard
7c1470f146 Makefiles: Organize help output to group 'like' targets 2020-01-22 13:21:12 -05:00
Marc Chevrier
5444a8095d cmGlobalGenerator: modernize memrory managemenbt 2019-12-30 16:55:39 +01:00
Marc Chevrier
f7d12609f0 Refactoring: use append functions from cmext/algorithm 2019-12-17 10:44:02 +01:00
Marc Chevrier
36c8cae2e8 cmLocalGenerator: modernize memory management 2019-12-10 00:24:06 +01:00
Marc Chevrier
f93385283f cmLocalGenerator: modernize memory management 2019-11-11 16:41:13 +01:00
Brad King
7420843370 Makefiles: Fix EXCLUDE_FROM_ALL OFF on sub/sub/tgt in sub/all
Defer adding a test to a later commit after all generators have been
fixed.

Issue: #19753
Co-Author: Sebastian Holtermann <sebholt@xwmw.org>
2019-09-30 10:34:23 -04:00
Brad King
0733a94f64 Ninja,Makefile: Fix subdir "all" with nested EXCLUDE_FROM_ALL subdir
The "all" target defined for a subdirectory (e.g. `cd sub; make` or
`ninja sub/all`) should not include the "all" targets from nested
subdirectories (e.g. `sub/sub`) that are marked as `EXCLUDE_FROM_ALL`.
Fix this and add a test case.

Issue: #19753
Co-Author: Sebastian Holtermann <sebholt@xwmw.org>
2019-09-30 10:30:28 -04:00
Brad King
dce58afd30 Merge branch 'backport-3.15-fix-EXCLUDE_FROM_ALL-subdir-all'
Resolve conflicts with changes since the 3.15 series:

* Convert `cmSystemTools::IsOn` => `cmIsOn`.
* Move one "EXCLUDE_FROM_ALL" target property logic fix to
  its new location in `cmMakefile::AddNewUtilityTarget`.
2019-09-30 09:34:57 -04:00
Brad King
05d7ca14e9 Merge branch 'backport-3.14-fix-EXCLUDE_FROM_ALL-subdir-all' 2019-09-30 09:19:21 -04:00
Brad King
b3b1c7bf3a Restore "all" target in subdirectories marked EXCLUDE_FROM_ALL
The "all" target in each directory is supposed to have targets from that
directory even if the directory itself is marked `EXCLUDE_FROM_ALL` in
its parent.  This was broken by commit dc6888573d (Pass EXCLUDE_FROM_ALL
from directory to targets, 2019-01-15, v3.14.0-rc1~83^2) which made the
participation of a target in "all" independent of context.  Revert much
of the logic change from that commit to restore the old behavior.  Then
re-implement the behavior intended by the commit to keep its test
working.  Extend the test to cover the old behavior too.

Fixes: #19753
2019-09-30 09:18:20 -04:00
Brad King
156b56480a Makefiles: Revert "Make build root targets ... recursive"
Revert the main logic change from commit 827da1119e (Makefiles: Make
build root targets "all", "clean" and "preinstall" recursive,
2019-05-17, v3.15.0-rc1~96^2~2) for the "all" and "preinstall" targets.

The commit cleaned up the Makefile generator to use the same logic for
the "all" target in the top-level directory as for subdirectories.  It
exposed a long-existing bug that caused the "all" target in a
subdirectory to include the "all" targets from sub-subdirectories even
if they are marked `EXCLUDE_FROM_ALL`.  The `Tests/SubDir` test should
fail but the problem is currently covered up by another bug introduced
by commit dc6888573d (Pass EXCLUDE_FROM_ALL from directory to targets,
2019-01-15, v3.14.0-rc1~83^2) that causes the "all" targets in
`EXCLUDE_FROM_ALL` subdirectories to be empty.

Revert the top-level "all" and "preinstall" targets to the old approach
to prepare to fix the latter bug without exposing the long-existing bug
at the top-level.  Leave the "clean" target in the new approach because
it does not honor `EXCLUDE_FROM_ALL` anyway.

Issue: #19753
2019-09-27 14:15:00 -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
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
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
Brad King
5f7386dd19 Merge topic 'string-literal-append'
da26b3be89 avoid adding multiple consecutive string literals to std::string

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3698
2019-08-19 15:06:47 -04:00
Rolf Eike Beer
da26b3be89 avoid adding multiple consecutive string literals to std::string
While at it change some single character additions to be of type char.
2019-08-18 14:22:11 +02:00
Sebastian Holtermann
20e580be01 Source sweep: Use cmIsOn instead of cmSystemTools::IsOn
This replaces invocations of

- `cmSystemTools::IsInternallyOn` with `cmIsInternallyOn`
- `cmSystemTools::IsNOTFOUND` with `cmIsNOTFOUND`
- `cmSystemTools::IsOn` with `cmIsOn`
- `cmSystemTools::IsOff` with `cmIsOff`
2019-08-17 12:14:14 +02:00
Marc Chevrier
d9b2c7dae2 Introduce memory management helper: cm_memory.hxx 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
Sebastian Holtermann
006229278b Use cmAppend to append ranges to std::vector instances 2019-05-23 16:19:49 +02:00
Sebastian Holtermann
1ded3599d6 Makefiles: Process ADDTIONAL_CLEAN_FILES dir prop at directory level
In the "Unix Makefiles" generator, the `ADDTIONAL_CLEAN_FILES` directory
property was evaluated on a per target basis. This had two drawbacks:
- per directory clean files were repeated in every target clean script
- per directory clean files weren't removed in directories without targets
  (issue #8164)

This patch moves the `ADDTIONAL_CLEAN_FILES` directory property processing
from the target to the directory level clean target.

Fixes: #8164 "ADDITIONAL_CLEAN_FILES directory property not respected if no
              target present in directory"
2019-05-18 12:27:24 +02:00