Commit Graph

201 Commits

Author SHA1 Message Date
Alexis Murzeau 42db2ebc75 Ninja: Use binary dir for `$subdir/all` targets
The targets added by commit v3.6.0-rc1~240^2~2 (Ninja: Add `$subdir/all`
targets, 2016-03-11) use as `$subdir` the relative path from the top of
the source tree to the current source directory.  This is not correct
when using `add_subdirectory(test test_bin)`.  Instead we need to use
the relative path from the top of the binary tree to the current binary
directory as was done for related targets by commit v3.7.0-rc1~268^2
(Ninja: Add `$subdir/{test,install,package}` targets, 2016-08-05).
2016-10-24 09:49:23 -04: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
Brad King 9a77680eed Ninja: Conditionally allow Fortran based on ninja 'dyndep' support
Detect from the version of Ninja whether it supports the dynamically
discovered dependencies (dyndep) feature needed to support Fortran.
2016-09-22 13:53:09 -04:00
Brad King 0f331d7893 Ninja: Add internal tool to produce a ninja dyndep file for Fortran
Create an internal `cmake -E cmake_ninja_dyndep` tool to read the "ddi"
files generated by `cmake -E cmake_ninja_depends` from all sources in a
target and generate a ninja dyndep file that tells Ninja about Fortran
module dependencies within the target and on target dependencies.
2016-09-22 13:52:57 -04:00
Brad King d3e0b64b14 Ninja: Add internal tool to scan Fortran code for module dependencies
Create an internal `cmake -E cmake_ninja_depends` tool to scan an
already-preprocessed Fortran translation unit for modules that it
provides or requires.  Save the information in a "ddi" file with a
CMake-private format for intermediate dynamic dependency information.
This file may the be loaded by another tool to be added later.
2016-09-22 13:52:30 -04:00
Brad King 8eca59a175 Ninja: Add comment with Fortran dependency design documentation 2016-09-22 13:52:03 -04:00
Brad King a57d1bb712 Ninja: Add API to check for dyndep support
Kitware maintains a branch of Ninja with support for dynamically
discovered dependencies (dyndep) that has not yet been accepted
upstream.  Add an internal API to check whether the Ninja version in use
for the build supports this feature.
2016-09-22 13:52:03 -04:00
Brad King 0488ae63ea Ninja: Refactor ninja feature detection
Check for features as soon as we know the ninja version.  Save the
results so we do not have to re-compare versions every time.
2016-09-22 13:52:02 -04:00
Brad King f0a23aa3db Ninja: Refactor Fortran rejection logic
Delay rejection of Fortran until after we've determined the version of
the `ninja` tool to be used.  This will later allow us to enable Fortran
support based on the version of ninja.

While at it, make the rejection an immediate fatal error.  Also provide
a stack trace so readers know what code tried to enable Fortran.
2016-09-22 13:51:58 -04:00
Brad King 501f9c9367 cmGlobalNinjaGenerator: Add API to check for implicit outputs support
Ninja 1.7 introduced support for implicit outputs on build statements.
Add an internal API to check whether the Ninja version in use for the
build supports this feature.
2016-09-20 08:51:57 -04:00
Brad King 144a24dcdc cmGlobalNinjaGenerator: Teach WriteBuild about implicit outputs
Ninja 1.7 introduced support for implicit outputs on build statements.
Teach WriteBuild to generate the corresponding syntax.  Leave it up to
callers to decide whether implicit outputs are supported by the Ninja
version in use.  For now simply update all call sites to pass an empty
list of implicit outputs.
2016-09-20 08:51:57 -04:00
Stephen Kelly 34c6e995f9 Convert: Avoid HOME_OUTPUT enum when converting to relative paths 2016-09-19 21:36:13 +02:00
Stephen Kelly 0a98c74c1b Convert: Remove last uses of HOME enum value 2016-09-19 21:36:12 +02:00
Daniel Pfeifer efed6468ed fix a load of include-what-you-use violations 2016-09-03 08:04:56 -04:00
Brad King e3a4c2e02c Merge topic 'cleanup-Convert'
4332131d Convert: Make variables a bit more clear
5aca066c Convert: Remove UNCHANGED enum value
146bf926 Convert: Remove 'FULL' conversion
58ba87f8 Convert: Replace Convert(FULL) with equivalent
e80314d7 Ninja: Replace ternary with if()
563ac22a Convert: Replace trivial conversion with new method
08be47cf Convert: Replace UNCHANGED conversions with new API call
564d3a1d Convert: Extract ConvertToRelativePath from Convert()
95a659f1 Convert: Replace FULL conversions with equivalent
a8c7ccb1 VS: Replace FULL/UNCHANGED conversion with equivalent
5ad25ef4 Convert: Remove NONE conversion
ac463841 Convert: Replace uses of Convert(NONE)
998d9ee9 VS: Replace variable with an if()
ee49f006 Makefiles: Replace ternaries with if()s
51f7dcb0 Makefiles: Inline MakeLauncher into only caller
ba4ba7c3 Makefiles: Simplify MakeLauncher return value
...
2016-08-30 09:29:53 -04:00
Kulla Christoph 048d1adb4e add_custom_command: Add DEPFILE option for Ninja
Provide a way for custom commands to inform the ninja build tool about
their implicit dependencies.  For now simply make use of the option an
error on other generators.

Closes: #15479
2016-08-30 09:05:18 -04:00
Stephen Kelly 563ac22a16 Convert: Replace trivial conversion with new method 2016-08-27 15:26:37 +02:00
Daniel Pfeifer 7b6349da4d CMake: don't use else after return 2016-08-18 20:36:29 +02:00
Brad King 0278989405 Ninja: Add `$subdir/{test,install,package}` targets
With the Makefile generator one can use `cd $subdir; make install` to build and
install targets associated with a given subdirectory.  This is not possible to
do with the Ninja generator since there is only one `build.ninja` file at the
top of the build tree.  However, we can approximate it by allowing one to run
`ninja $subdir/install` at the top of the tree to build the targets in the
corresponding subdirectory and install them.

This also makes sense for `test`, `package`, and other GLOBAL_TARGET targets.
It was already done for `all` by commit v3.6.0-rc1~240^2~2 (Ninja: Add
`$subdir/all` targets, 2016-03-11).
2016-08-09 15:15:24 -04:00
Brad King a88c99f1bc Ninja: Simplify computation of GLOBAL_TARGET outputs
In cmGlobalNinjaGenerator::AppendTargetOutputs we previously
handled GLOBAL_TARGET outputs specially in order to avoid adding
directory components to the output.  However, this is not necessary
because cmNinjaTargetGenerator::New already filters out copies of
these targets that are not at the top level.  Instead we can simply
follow the same output computation code path as UTILITY targets.
2016-08-09 14:36:04 -04:00
Brad King e555480c60 Ninja: Fix response file format for GNU-like Clang on Windows
The `CMAKE_<LANG>_SIMULATE_ID` variables are not set to "GNU" for a
GNU-like Clang compiler on Windows.  They are only set to "MSVC" for a
MSVC-like Clang.  Revise our response file format selection accordingly.

Reported-by: Chaoren Lin <chaorenl@google.com>
2016-08-04 09:44:56 -04:00
Brad King 1296a0eada Ninja: Fix inter-target order-only dependencies of custom commands
Custom command dependencies are followed for each target's source files
and add their transitive closure to the corresponding target.  This
means that when a custom command in one target has a dependency on a
custom command in another target, both will appear in the dependent
target's sources.  For the Makefile, VS IDE, and Xcode generators this
is not a problem because each target gets its own independent build
system that is evaluated in target dependency order.  By the time the
dependent target is built the custom command that belongs to one of its
dependencies will already have been brought up to date.

For the Ninja generator we need to generate a monolithic build system
covering all targets so we can have only one copy of a custom command.
This means that we need to reconcile the target-level ordering
dependencies from its appearance in multiple targets to include only the
least-dependent common set.  This is done by computing the set
intersection of the dependencies of all the targets containing a custom
command.  However, we previously included only the direct dependencies
so any target-level dependency not directly added to all targets into
which a custom command propagates was discarded.

Fix this by computing the transitive closure of dependencies for each
target and then intersecting those sets.  That will get the common set
of dependencies.  Also add a test to cover a case in which the
incorrectly dropped target ordering dependencies would fail.
2016-07-20 13:12:24 -04:00
Daniel Pfeifer 1d6909a287 use CM_NULLPTR 2016-06-28 09:02:26 -04:00
Daniel Pfeifer eb79fa7260 Access std::ios_base with std::ios
Just because it is shorter.
2016-06-14 22:23:08 +02:00
Daniel Pfeifer a16bf141bc Add missing braces around statements.
Apply fixits of clang-tidy's readability-braces-around-statements
checker.
2016-06-10 18:36:24 +02:00
Daniel Pfeifer 7f6b8d3399 Simplify boolean expressions
Use clang-tidy's readability-simplify-boolean-expr checker.
After applying the fix-its, revise all changes *very* carefully.
Be aware of false positives and invalid changes.
2016-06-02 08:24:04 -04:00
Daniel Pfeifer 27ead96305 Remove unnecessary local copies.
Use clang-tidy's performance-unnecessary-copy-initialization checker.
After applying the fix-its (which turns the copies into const&), revise
the changes and see whether the copies can be removed entirely by using
the original instead.
2016-05-26 22:21:15 +02:00
Brad King 6052e4b3bf Merge topic 'improve-character-find-and-replace'
5784747d Improve string find: prefer character overloads.
5cec953e Use std::replace for replacing chars in strings.
2a1a2033 cmExtraEclipseCDT4Generator: use std::replace.
34bc6e1f cmCTestScriptHandler: don't call find repeatedly.
2016-05-25 09:34:29 -04:00
Daniel Pfeifer 25d1ef6424 Use enums defined in cmOutputConverter using their fully qualified name.
Mostly automated:

values=("RelativeRoot" "NONE" "FULL" "HOME" "START" "HOME_OUTPUT" "START_OUTPUT"
        "OutputFormat" "UNCHANGED" "MAKERULE" "SHELL" "WATCOMQUOTE" "RESPONSE"
        "FortranFormat" "FortranFormatNone" "FortranFormatFixed" "FortranFormatFree")
for i in "${values[@]}"; do git grep -l cmLocalGenerator::$i | xargs sed -i "s|cmLocalGenerator::$i|cmOutputConverter::$i|g"; done
2016-05-25 09:20:09 -04:00
Daniel Pfeifer 5cec953e6a Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.

Automate with:

git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:22:20 +02:00
Nicolas Despres 8a862a4d4b Ninja: Support embedding of CMake as subninja project
Add a `CMAKE_NINJA_OUTPUT_PATH_PREFIX` variable.  When it is set, CMake
generates a `build.ninja` file suitable for embedding into another ninja
project potentially generated by an alien generator.
2016-05-17 09:34:12 -04:00
Nicolas Despres 038e7716e5 Ninja: Pass all build paths through a central method
This gives us a central location to revise paths.
2016-05-17 09:34:11 -04:00
Nicolas Despres 0397c92a15 Ninja: Pre-compute "CMakeCache.txt" build target name 2016-05-17 09:34:08 -04:00
Nicolas Despres 3b3ecdfa48 Ninja: Pre-compute "all" build target name 2016-05-17 09:34:07 -04:00
Brad King 5ca72750c8 Ninja: Simplify generation of custom target logical path
In `AppendTargetOutputs` we generate a logical build target name for
each UTILITY command.  Simplify the logic to avoid testing the result
of `ConvertToNinjaPath`.
2016-05-17 09:34:06 -04: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 0ac18d40c8 Remove `//------...` horizontal separator comments
Modern editors provide plenty of ways to visually separate functions.
Drop the explicit comments that previously served this purpose.
Use the following command to automate the change:

    $ git ls-files -z -- \
        "*.c" "*.cc" "*.cpp" "*.cxx" "*.h" "*.hh" "*.hpp" "*.hxx" |
      egrep -z -v "^Source/cmCommandArgumentLexer\." |
      egrep -z -v "^Source/cmCommandArgumentParser(\.y|\.cxx|Tokens\.h)" |
      egrep -z -v "^Source/cmDependsJavaLexer\." |
      egrep -z -v "^Source/cmDependsJavaParser(\.y|\.cxx|Tokens\.h)" |
      egrep -z -v "^Source/cmExprLexer\." |
      egrep -z -v "^Source/cmExprParser(\.y|\.cxx|Tokens\.h)" |
      egrep -z -v "^Source/cmFortranLexer\." |
      egrep -z -v "^Source/cmFortranParser(\.y|\.cxx|Tokens\.h)" |
      egrep -z -v "^Source/cmListFileLexer\." |
      egrep -z -v "^Source/cm_sha2" |
      egrep -z -v "^Source/(kwsys|CursesDialog/form)/" |
      egrep -z -v "^Utilities/(KW|cm).*/" |
      xargs -0 sed -i '/^\(\/\/---*\|\/\*---*\*\/\)$/ {d;}'

This avoids modifying third-party sources and generated sources.
2016-05-09 09:41:43 -04:00
Brad King 64b5520346 Isolate formatted streaming blocks with clang-format off/on
The clang-format tool can do a good job formatting most code, but
well-organized streaming blocks are best left manually formatted.

Find blocks of the form

    os <<
      "...\n"
      "...\n"
      ;

using the command

    $ git ls-files -z -- Source |
      egrep -v -z '^Source/kwsys/' |
      xargs -0 pcregrep -M --color=always -B 1 -A 1 -n \
        '<<[^\n]*\n(^ *("[^\n]*("|<<|;)$|;)\n){2,}'

Find blocks of the form

    os << "...\n"
       << "...\n"
       << "...\n";

using the command

    $ git ls-files -z -- Source |
      egrep -v -z '^Source/kwsys/' |
      xargs -0 pcregrep -M --color=always -B 1 -A 1 -n \
        '<<[^\n]*\n(^ *<<[^\n]*(\\n"|<<|;)$\n){2,}'

Surround such blocks with the pair

    /* clang-format off */
    ...
    /* clang-format on */

in order to protect them from update by clang-format.  Use the C-style
`/*...*/` comments instead of C++-style `//...` comments in order to
prevent them from ever being swallowed by re-formatting of surrounding
comments.
2016-05-06 14:25:55 -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
Dmitry Ivanov f9644a2d1b cmGlobalNinjaGenerator: Clarify logic for forcing use of response files
Update the WriteBuild method to use a negative command line length limit
to specify that we should force use of response files.
2016-04-07 09:45:29 -04:00
Charles Huet ca575fe935 Ninja: Add `$subdir/all` targets
With the Makefile generator one can use `cd $subdir; make all` to build
all targets associated with a given subdirectory.  This is not possible
to do with the Ninja generator since there is only one `build.ninja`
file at the top of the build tree.  However, we can approximate it by
allowing one to run `ninja $subdir/all` at the top of the tree to build
the targets in the corresponding subdirectory.

Port logic from cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2 to
cmGlobalNinjaGenerator in order to produce equivalent directory-level
targets.
2016-03-18 10:59:01 -04:00
Brad King b42866a34a Drop Visual Studio 6 generator
This generator has been deprecated since CMake 3.3.  Remove it.
Update documentation, modules, and tests to drop content specific
to this generator.
2016-03-09 09:42:18 -05:00
Brad King 46fa958362 Ninja: Fix non-determinism in generated target dependency order (#15968)
We represent target dependency sets as `set<cmTargetDepend>` which
orders by a `cmGeneratorTarget const*` pointer value.  Therefore the
order of dependencies encountered in AppendTargetDepends is not
predictable.  Sort them by content to make the result deterministic.
2016-02-12 08:51:58 -05:00
Brad King 7d64a0598d Ninja: Add 'restat' parameter to custom command generation method
Pass 'true' from all call sites to preserve existing behavior.
2015-11-19 15:11:00 -05:00
Brad King 866c75dedd Ninja: Refactor generation of 'restat' on custom commands
Move generation of 'restat = 1' from the CUSTOM_COMMAND rule to every
build statement using it.  This will allow future selection of this
option on a per-custom-command basis.
2015-11-19 14:51:24 -05:00
Brad King a3c5ca960b cmGlobalNinjaGenerator: Save 'ninja' version very early
Keep it in a member variable for convenient reference.  Store the
value as soon as it is known.
2015-11-02 16:37:59 -05:00
Brad King ed67f40522 cmGlobalNinjaGenerator: Save path to 'ninja' tool very early
Keep it in a member variable for convenient reference.  Set the
value as soon as it is known.
2015-11-02 16:27:31 -05:00
Stephen Kelly 736c2042c6 cmGeneratorTarget: Add GetUtilities API 2015-10-27 07:44:20 +01:00
Stephen Kelly 80de856bb5 Ninja: Port to cmGeneratorTarget. 2015-10-24 09:19:53 +02:00