Commit Graph

79 Commits

Author SHA1 Message Date
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
Daniel Pfeifer 1d6909a287 use CM_NULLPTR 2016-06-28 09:02:26 -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 87f44b7525 Fix export of STATIC library PRIVATE non-target dependencies
In commit v3.5.0-rc1~43^2 (Fix export of STATIC library PRIVATE
dependencies with CMP0022 NEW, 2016-01-15) we taught
target_link_libraries to generate `$<LINK_ONLY:$<TARGET_NAME:dep>>` in
INTERFACE_LINK_LIBRARIES instead of `$<LINK_ONLY:dep>` so that `dep` can
be recognized as a target name and updated during export.  However, this
approach does not work when `dep` is just a plain library name and not a
target because `$<TARGET_NAME:...>` requires the name of a reachable
target.

Since we do not know during target_link_libraries whether the name will
correspond to a reachable target or not, we cannot inject the
`$<TARGET_NAME:...>` expression.  Revert this change and solve the
original problem instead by teaching the export logic to recognize and
update target names directly in `$<LINK_ONLY:...>` expressions.

Reported-by: Ben Boeckel <ben.boeckel@kitware.com>
2016-02-17 14:01:11 -05:00
Brad King aea1b03617 Fix export of STATIC library PRIVATE dependencies with CMP0022 NEW
The target_link_libraries command records the PRIVATE dependencies of a
STATIC library in INTERFACE_LINK_LIBRARIES as "$<LINK_ONLY:dep>".  This
hides the target name from export namespacing logic inside a generator
expression.  When user-written generator expressions reference a target
name they must put it inside a "$<TARGET_NAME:dep>" expression to allow
the export logic to rename the target.  In the case that the private
dependency is not already a generator expression, target_link_libraries
must use "$<LINK_ONLY:$<TARGET_NAME:dep>>" to allow the export logic to
rename the target.

Reported-by: Tamás Kenéz <tamas.kenez@gmail.com>
2016-01-15 10:18:53 -05:00
Stephen Kelly eac15298a8 cmState: Move TargetType enum from cmTarget.
Mostly automated:

 values=( "EXECUTABLE" "STATIC_LIBRARY" "SHARED_LIBRARY" "MODULE_LIBRARY" "OBJECT_LIBRARY" "UTILITY" "GLOBAL_TARGET" "INTERFACE_LIBRARY" "UNKNOWN_LIBRARY" "TargetType")
 for i in "${values[@]}"; do     git grep -l cmTarget::$i | xargs sed -i "s|cmTarget::$i|cmState::$i|g"; done
2015-10-15 00:41:39 +02:00
Stephen Kelly 482b3811e4 cmTarget: Move link type enum out.
Remove a reason for generate time code to depend on the cmTarget header/type.
2015-10-15 00:41:22 +02:00
Brad King 30c2e1dd16 cmTarget: Fix diagnostic of target_link_libraries in wrong directory (#15626)
Since commit v3.3.0-rc1~62^2~5 (cmTarget: Store only cmListFileContext
for CMP0023 handling, 2015-05-18) a call to target_link_libraries on a
target that was defined in another (non-ancestor) directory crashes
because no execution context is left active.  Fix this by getting the
execution context from the actual cmMakefile where the current
target_link_libraries call takes place.  Test this by verifying that
such calls correctly produce an error diagnostic instead of crashing.
2015-06-25 09:14:26 -04:00
Stephen Kelly de21168612 Port to static cmPolicies API. 2015-05-04 22:32:20 +02:00
Stephen Kelly ade20b433b cmake: Remove DebugConfigs member.
It adds needless complexity to global property handling.
2015-04-12 20:08:47 +02:00
Stephen Kelly 931e055d8c Port all cmOStringStream to std::ostringstream.
All compilers hosting CMake support the std class.
2015-01-11 17:06:03 +01:00
Stephen Kelly ff710539ab Remove default labels from fully covered switch statements.
Allow compilers to warn when new enum values are added, making
switches no-longer fully-covered.
2014-04-03 21:53:13 +02:00
Brad King f70b2253f6 Merge topic 'fix_policy_diagnostics'
77b581c2 Policies: omit warnings about unset policies when they are actually set to NEW
2014-04-01 11:06:17 -04:00
Nils Gladitz 77b581c2f0 Policies: omit warnings about unset policies when they are actually set to NEW 2014-03-31 09:45:10 -04:00
Stephen Kelly 21c573f682 Remove some c_str() calls.
Use the clang RemoveCStrCalls tool to automatically migrate the
code. This was only run on linux, so does not have any positive or
negative effect on other platforms.
2014-03-11 15:03:50 +01:00
Ben Boeckel 466abd846f cmTargetLinkLibrariesCommand: Use a string argument 2014-03-08 13:05:34 -05:00
Ben Boeckel 8d60da0cb5 cmTarget: Remove the project argument to FindTarget
All callers passed 0 in, so just remove the branch.
2014-03-08 13:05:34 -05:00
Rolf Eike Beer c768e398f9 cmMakefile: make some methods take const std::string& instead of const char*
Most callers already have a std::string, on which they called c_str() to pass it
into these methods, which internally converted it back to std::string. Pass a
std::string directly to these methods now, avoiding all these conversions.
Those methods that only pass in a const char* will get the conversion to
std::string now only once.
2014-01-16 09:28:29 -05:00
Stephen Kelly 596b2a8c08 Disallow linking to utility targets (#13902). 2013-11-07 11:06:40 +01:00
Brad King 25b7f87eca Merge branch 'policy-CMP0022-fixes' into policy-CMP0022-fixes-for-master
Resolve conflict in Source/cmTarget.cxx by integrating the changes to
the internal copy constructor from both sides.  Also resolve a logical
conflict by dropping the special case for INTERFACE_LIBRARY targets.
Since cmTarget::SetMakefile already forces CMP0022 to NEW for such
targets we need no special handling.

Resolve conflict in Source/cmTargetLinkLibrariesCommand.h by dropping
the documentation change.  We will make the same change in the new
location of the same documentation in a separate commit.

Resolve conflicts in

 Tests/RunCMake/CMP0022/CMP0022-WARN-empty-old-stderr.txt
 Tests/RunCMake/CMP0022/RunCMakeTest.cmake

by taking the side from the 'policy-CMP0022-fixes' branch.
2013-11-03 09:20:47 -05:00
Brad King ef10b87cc1 CMP0022: Plain target_link_libraries must populate link interface
The CMP0022 NEW behavior is that the INTERFACE_LINK_LIBRARIES property
exactly defines the link interface.  The plain target_link_libraries
signature says linking is transitive by default, so it should populate
the property.

Teach the target_link_libraries plain signature to populate the
INTERFACE_LINK_LIBRARIES regardless of the CMP0022 setting.  Refactor
the cmTarget::ComputeLinkInterface checks that warn when the policy is
not set to compare the new property to either the explicitly set old
link interface properties or the link implementation fallback for all
linkable target types, not just static libraries.

This fixes a regression in 2.8.12.0 that caused target_link_libraries to
not implement transitive linking in the plain signature once the policy
CMP0022 is set to NEW.
2013-11-02 12:55:17 -04:00
Brad King 4064d6f216 target_link_libraries: Revert accidental change
In commit c4373b33 (cmTarget: Make GetProperty() const, 2013-10-29)
we accidentally changed the cmTargetLinkLibrariesCommand.cxx logic
in a way that looks like a local experiment leftover that went
unnoticed due to the size of the other changes in the commit.
Revert it.
2013-11-02 07:11:51 -04:00
Stephen Kelly c4373b33b2 cmTarget: Make GetProperty() const.
This has follow-on effects for other methods and classes. Further
work on making the use of const cmTarget pointers common can be
done, particularly with a view to generate-time methods.
2013-10-31 14:52:11 +01:00
Brad King 1b21ac405f Merge topic 'fix-tll-static-private'
239b0c6 Don't add invalid content to static lib INTERFACE_LINK_LIBRARIES.
2013-10-26 10:28:02 -04:00
Stephen Kelly 239b0c6b0e Don't add invalid content to static lib INTERFACE_LINK_LIBRARIES.
Only valid target names or generator expressions may appear in
the target field of a LINK_ONLY expression.

Other content like link flags should still be added to that property
(wrapped in config-specific generator expressions), but not wrapped
in LINK_ONLY. Otherwise undue warnings would be issued for the
policy CMP0022.

The LINK_ONLY expression only has an effect for actual target
names anyway, so there is no logical deficit.
2013-10-26 10:10:20 -04:00
Stephen Kelly dede273193 target_link_libraries: Allow repeated use of LINK_{PRIVATE,PUBLIC} keywords.
This has not been allowed since they were introduced in
commit 91438222 (target_link_libraries: Add LINK_(PUBLIC|PRIVATE)
options, 2011-10-07), but allowing this form makes it more compatible
with the newer PUBLIC and PRIVATE keywords.
2013-10-17 17:37:20 +02:00
Stephen Kelly fe732264e9 Add the INTERFACE_LIBRARY target type.
This target type only contains INTERFACE_* properties, so it can be
used as a structural node. The target-specific commands enforce
that they may only be used with the INTERFACE keyword when used
with INTERFACE_LIBRARY targets. The old-style target properties
matching LINK_INTERFACE_LIBRARIES_<CONFIG> are always ignored for
this target type.

The name of the INTERFACE_LIBRARY must match a validity generator
expression. The validity is similar to that of an ALIAS target,
but with the additional restriction that it may not contain
double colons. Double colons will carry the meaning of IMPORTED
or ALIAS targets in CMake 2.8.13.

An ALIAS target may be created for an INTERFACE library.

At this point it can not be exported and does not appear in the
buildsystem and project files are not created for them. That may
be added as a feature in a later commit.

The generators need some changes to handle the INTERFACE_LIBRARY
targets returned by cmComputeLinkInterface::GetItems. The Ninja
generator does not use that API, so it doesn't require changes
related to that.
2013-10-07 19:56:31 -04:00
Stephen Kelly 370bf55415 Add the ALIAS target concept for libraries and executables.
* The ALIAS name must match a validity regex.
* Executables and libraries may be aliased.
* An ALIAS acts immutable. It can not be used as the lhs
  of target_link_libraries or other commands.
* An ALIAS can be used with add_custom_command, add_custom_target,
  and add_test in the same way regular targets can.
* The target of an ALIAS can be retrieved with the ALIASED_TARGET
  target property.
* An ALIAS does not appear in the generated buildsystem. It
  is kept separate from cmMakefile::Targets for that reason.
* A target may have multiple aliases.
* An ALIAS target may not itself have an alias.
* An IMPORTED target may not have an alias.
* An ALIAS may not be exported or imported.
2013-08-02 15:21:00 +02:00
Stephen Kelly b655865bbf target_link_libraries: Add PUBLIC/PRIVATE/INTERFACE keyword signature
Add a new signature to help populate INTERFACE_LINK_LIBRARIES and
LINK_LIBRARIES cleanly in a single call.  Add policy CMP0023 to control
whether the keyword signatures can be mixed with uses of the plain
signatures on the same target.
2013-07-24 11:52:44 -04:00
Stephen Kelly 3e30d9ed67 TLL: Don't populate old link interface if CMP0022 is NEW.
Always populate the INTERFACE_LINK_LIBRARIES for interface
entries. Don't populate the old interface properties
matching (IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?
if CMP0022 is NEW.

Because the INTERFACE_LINK_LIBRARIES property is now populated by
the target_link_libraries when operating on a static library,
make an equivalent change which populates the property with
the same value when the old link_libraries() command is used. This
silences the policy warning in that case.
2013-07-08 22:39:58 +02:00
Stephen Kelly b8259c3d69 Centralize maintenance of usage requirement include directories
Maintain a target's internal list of usage requirement include
directories whenever the LINK_LIBRARIES property is set by either
target_link_libraries or set_property.
2013-05-06 09:54:11 -04:00
Stephen Kelly e1f908015f Don't populate INTERFACE includes and defines properties in tll.
This is a partial revert of commit 77cecb77 (Add includes and compile
definitions with target_link_libraries., 2012-11-05).

As the interface includes and defines are now determined by the link
closure, there is no need to populate the corresponding properties
explicitly.
2013-02-13 15:12:31 +01:00
Stephen Kelly a1c4905f72 Use the link information as a source of compile definitions and includes.
After evaluating the INTERFACE_INCLUDE_DIRECTORIES, of a target in a
generator expression, also read the INTERFACE_INCLUDE_DIRECTORIES of
its link interface dependencies.

That means that code such as this will result in the 'user' target
using /bar/include and /foo/include:

 add_library(foo ...)
 target_include_directories(foo INTERFACE /foo/include)
 add_library(bar ...)
 target_include_directories(bar INTERFACE /bar/include)
 target_link_libraries(bar LINK_PUBLIC foo)

 add_executable(user ...)
 target_include_directories(user PRIVATE
    $<TARGET_PROPERTY:bar,INTERFACE_INCLUDE_DIRECTORIES>)

Also process the interface include directories from direct link
dependencies for in-build targets.

The situation is similar for the INTERFACE_COMPILE_DEFINITIONS. The
include directories related code is currently more complex because
we also need to store a backtrace at configure-time for the purpose
of debugging includes. The compile definitions related code will use
the same pattern in the future.

This is not a change in behavior, as existing code has the same effect,
but that existing code will be removed in follow-up commits.
2013-02-13 15:12:30 +01:00
Stephen Kelly 7c0ec75cfa De-duplicate validation of genex target names. 2013-02-07 16:21:08 +01:00
Stephen Kelly 92e98dd909 Deduplicate the isGeneratorExpression method.
This API seems like the most appropriate.
2013-02-07 16:21:08 +01:00
Stephen Kelly 77cecb778f Add includes and compile definitions with target_link_libraries.
This establishes that linking is used to propagate usage-requirements
between targets in CMake code. The use of the target_link_libraries
command as the API for this is chosen because introducing a new command
would introduce confusion due to multiple commands which differ only in
a subtle way.
2013-01-31 17:34:20 +01:00
Stephen Kelly 48a4cf2182 Revert "Allow target_link_libraries with IMPORTED targets."
This reverts commit 9cfe4f1b76.

It turns out that correctly adding the content to
the IMPORTED_LINK_INTERFACE_LIBARIES_<CONFIG> of an upstream target
from the buildsystem of a downstream project is not simple.

If upstream had added the INTERFACE content, the config-specific
properties would  be determined by the DEBUG_CONFIGURATIONS of
upstream.

As downstream, we don't have any information about what
the DEBUG_CONFIGURATIONS of upstream were, so we can't determine
which configuration-specific properties to populate. The best we can do
is add it to all of them or add it to the ones downstream considers to
be DEBUG_CONFIGURATIONS, neither of which is a good solution.

So, removing the porcelain API for that is the best approach. A human
can still determine which properties to populate and use
the set_property API to populate the desired properies.

Another solution to this would be for upstream targets to publish
what they consider DEBUG_CONFIGURATIONS, but that can be added in
a future release.
2013-01-21 12:19:39 +01:00
Stephen Kelly 9cfe4f1b76 Allow target_link_libraries with IMPORTED targets.
This makes it possible to use:

 target_link_libraries(foo LINK_INTERFACE_LIBRARIES bar)

where foo is an IMPORTED target. Other tll() signatures are not
allowed.
2013-01-08 18:58:18 +01:00
Stephen Kelly 50b1ea5bed Fix minor typos.
nothe -> note
than -> that
duplicat -> duplicate
directory -> directly
Wipe wipe -> Wipe
2012-09-29 18:44:10 +02:00
Brad King b87d7a60a0 Add OBJECT_LIBRARY target type
This library type can compile sources to object files but does not link
or archive them.  It will be useful to reference from executable and
normal library targets for direct inclusion of object files in them.

Diagnose and reject the following as errors:

* An OBJECT library may not be referenced in target_link_libraries.

* An OBJECT library may contain only compiling sources and supporting
  headers and custom commands.  Other source types that are not normally
  ignored are not allowed.

* An OBJECT library may not have PRE_BUILD, PRE_LINK, or POST_BUILD
  commands.

* An OBJECT library may not be installed, exported, or imported.

Some of these cases may be supported in the future but are not for now.

Teach the VS generator that OBJECT_LIBRARY targets are "linkable" just
like STATIC_LIBRARY targets for the LinkLibraryDependencies behavior.
2012-03-13 14:37:32 -04:00
Brad King b1f12f8042 target_link_libraries: Simplify argument processing state tests
Remove extra parens in test for not handling LINK_INTERFACE_LIBRARIES.
Remove redundant test for equality with ProcessingPrivateInterface
subsumed by test for inequality with ProcessingPublicInterface.
2011-11-22 17:21:36 -05:00
Stephen Kelly 914382224d target_link_libraries: Add LINK_(PUBLIC|PRIVATE) options
Makes it possible to specify the link dependencies and link
interfaces in one command without repetition.
2011-11-22 16:52:35 -05:00
Alex Neundorf 6acc71c09d New CMP0016 for deciding whether an unknown target in TLL() is an error.
When set to OLD, target_link_libraries() silently accepts if it is called
with only one argument and this one argument is not a target.
When set to NEW, this is an error. By default it is a warning now.

Alex
2010-08-28 16:06:45 +02:00
Alex Neundorf 6aef6d84d7 Just warn in case of a bad target as only argument for t_l_l()
As discussed on cmake-devel, if target_link_libraries() is called with
only one argument, and this one argument is not a valid target, just
print a warning but don't fail, since otherwise probably some existing
code somewhere might stop building.

Alex
2010-08-26 21:54:43 +02:00
Alex Neundorf c786635149 Make target_link_libraries() complain if bad target name is used
target_link_libraries() did not complain if there was only one argument,
and this one (first) argument wasn't a valid target name, e.g.

add_executable(hello main.cpp)
target_link_libraries(-static-intel)

Here the target "hello" was forgotten in the tll() call, but cmake didn't
complain. With this commit it does.

Alex
2010-08-26 21:02:40 +02:00
Alex Neundorf 43f96eaf93 Remove trailing whitespace
Alex
2010-08-26 21:01:58 +02:00
Brad King 96afb12087 Convert CMake to OSI-approved BSD License
This converts the CMake license to a pure 3-clause OSI-approved BSD
License.  We drop the previous license clause requiring modified
versions to be plainly marked.  We also update the CMake copyright to
cover the full development time range.
2009-09-28 11:43:28 -04:00