256 Commits

Author SHA1 Message Date
Brad King
1d3841b600 Genex: Memoize usage requirement TARGET_PROPERTY existence
For each usage requirement (such as `INTERFACE_COMPILE_DEFINITIONS` or
`INTERFACE_INCLUDE_DIRECTORIES`), the value of the generator expression
`$<TARGET_PROPERTY:target,prop>` includes the values of the same
property from the transitive closure of link libraries of the target.

In cases that a target's transitive closure of dependencies does not
depend on the target being linked (the "head" target), we can memoize
whether or not a usage requirement property exists at all for that
target.  When a usage requirement does not exist for a target, we
can skip evaluating it for every consuming target.

Fixes: #18964, #18965
2019-07-23 10:44:19 -04:00
Brad King
11fa818ecd Genex: Optimize usage requirement TARGET_PROPERTY recursion
In large projects the generation process spends a lot of time evaluating
usage requirements through transitive interface properties on targets.
This can be seen in a contrived example with deep dependencies:

    set(prev "")
    foreach(i RANGE 1 500)
      add_library(a${i} a.c)
      target_compile_definitions(a${i} PUBLIC A${i})
      target_link_libraries(a${i} PUBLIC ${prev})
      set(prev a${i})
    endforeach()

For each usage requirement (such as `INTERFACE_COMPILE_DEFINITIONS` or
`INTERFACE_INCLUDE_DIRECTORIES`), the value of the generator expression
`$<TARGET_PROPERTY:target,prop>` includes the values of the same
property from the transitive closure of link libraries of the target.

Previously we computed this by constructing a generator expression
string like `$<TARGET_PROPERTY:lib,INTERFACE_COMPILE_DEFINITIONS>` and
recursively evaluating it with the generator expression engine.  Avoid
the string construction and parsing by creating and using a dedicated
evaluation method `cmGeneratorTarget::EvaluateInterfaceProperty` that
looks up the properties directly.

Issue: #18964, #18965
2019-07-23 06:46:34 -04:00
Brad King
79f5ef19fe De-duplicate checks for whether a platform uses Windows DLLs 2019-07-12 17:35:49 -04:00
Brad King
22d3eb5d5e Refactor checks for whether a target has an import library
Use `HasImportLibrary` for such checks.
2019-07-12 17:29:40 -04:00
Kyle Edwards
d29ed8a114 BUILD_RPATH/INSTALL_RPATH: Add generator expression support
Fixes: #19423
2019-06-25 10:55:03 -04:00
Marc Chevrier
1f4c9aa7d2 Refactor: introduce method cmGeneratorTarget::GetFilePostfix 2019-05-02 10:06:04 +02:00
Marc Chevrier
f65763fe9b Refactor: Add new methods to retrieve prefix and suffix 2019-04-10 18:37:03 +02:00
Marc Chevrier
1889ed923e Genex: Add capability to retrieve base name for various target artifacts
This new capability is required to solve efficiently issue #18771
2019-04-08 07:49:08 -04:00
Sebastian Holtermann
735c6f39d9 Fix invalid ///! doxygen comment line starts
In various places `///!` was used to start a comment line.  This is not valid
Doygen syntax.  This patch replaces `///!` comment starts with `//!`.
2019-03-31 11:27:12 +02:00
Saleem Abdulrasool
fc8b90af2c Create and use cmGeneratorTarget::Names
Rather than taking a number of out parameters for the various names,
create a structure that is reused for both `GetLibraryNames` and
`GetExecutableNames`.  Replace uses according to the new interface.
2019-02-11 10:44:24 -08:00
Regina Pfeifer
b05b778a2d clang-tidy: Use = delete 2019-01-29 14:09:21 -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
Sebastian Holtermann
a42b700cc2 cmTarget,cmGeneratorTarget: Add optional before parameter to AddSource
The new optional `before` parameter in `cmTarget::AddSource` and
`cmGeneratorTarget::AddSource` allows to prepend a source file
to the sources list instead of appending it.
2019-01-18 13:47:23 +01:00
Regina Pfeifer
b2aa3aedea clang-tidy: Use default member initialization 2018-12-15 10:52:37 +01:00
Marc Chevrier
c4b4d8b3a6 POSITION_INDEPENDENT_CODE: Manage link flags for executables
Fixes: #14983, #16561
2018-11-11 17:34:09 +01:00
Brad King
d955b4f753 Merge topic 'fix-custom-target-with-csharp'
9040df31e2 Merge branch 'backport-fix-custom-target-with-csharp'
1acd1c2b50 CSharp: Fix regression in VS project type selection for custom target
a56edad6d6 CSharp: Fix regression in VS project type selection for custom target

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2549
2018-11-01 07:36:39 -04:00
Brad King
a56edad6d6 CSharp: Fix regression in VS project type selection for custom target
A target created by `add_custom_target` should always be a `.vcxproj`
file even if it has `.cs` sources involved in custom commands and such.
The latter case was broken by refactoring in commit v3.12.0-rc1~160^2~7
(remove TargetIsCSharpOnly() and use methods from cmGeneratorTarget,
2018-03-19).  The reason is that the `HasLanguage` method added by
commit v3.12.0-rc1~239^2~6 (cmGeneratorTarget: add HasLanguage() as
wrapper for GetLanguages(), 2018-03-19) does not check the target type
and so is not a suitable check for deciding the project file extension.

The `HasLanguage` method was an attempt at an abstraction that turns
out not to work very well.  Replace it with a dedicated `IsCSharpOnly`
method that considers the target type, sources, and non-transitive
`LINKER_LANGUAGE`.

Fixes: #18515
2018-10-31 09:13:19 -04:00
Brad King
753ab3c978 Add generator APIs to get build settings with backtraces
In cmGeneratorTarget and cmLocalGenerator we offer several APIs to get
build settings like include directories, compile definitions, source
files, etc.  Add corresponding APIs that include backtrace information.
2018-10-18 08:26:27 -04:00
Brad King
a6e02f881d add_dependencies: Track backtraces internally
Record backtraces for "utility" dependencies created by
`add_dependencies` calls.
2018-10-18 08:10:55 -04:00
Brad King
a093b1a4f3 cmLinkItem: Add backtrace
Carry a backtrace on every link item, not just link implementation
items.  For now the non-impl items will still have empty backtraces at
runtime, but this will allow us to introduce values over time.
2018-10-18 08:07:46 -04:00
Vitaly Stakhovsky
b8bb6ba653 cmGeneratorTarget::GetExportMacro: return const std::string* 2018-10-16 11:12:19 -04:00
Brad King
9fc3024f62 Merge topic 'fix-csharp-target-type'
375b420fdf CSharp: Fix regression in VS project type selection
8b21aa0af0 VS: Fix CSharp flag selection when linking to a static C++ library

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2427
2018-10-03 08:04:35 -04:00
Brad King
375b420fdf CSharp: Fix regression in VS project type selection
A that target contains only `.cs` sources should be generated as a
`.csproj` project even if it links to non-CSharp static libraries.
The latter case was broken by refactoring in commit v3.12.0-rc1~160^2~7
(remove TargetIsCSharpOnly() and use methods from cmGeneratorTarget,
2018-03-19).  The reason is that the `HasLanguage` method added by
commit v3.12.0-rc1~239^2~6 (cmGeneratorTarget: add HasLanguage() as
wrapper for GetLanguages(), 2018-03-19) enforces its "exclusive" check
on the combined set of source file languages and the link language.
To restore the original `TargetIsCSharpOnly` semantics, update
`HasLanguage` to enforce exclusiveness only on the list of sources.

Fixes: #18239
2018-10-02 14:58:11 -04:00
Marc Chevrier
a71caab46b LINK_DIRECTORIES: Add new properties and commands
These new capabilities enable to manage link directories

Two new properties:
* target properties: LINK_DIRECTORIES and INTERFACE_LINK_DIRECTORIES

One new command
* target_link_directories(): to populate target properties

Fixes: #17215
2018-09-25 23:59:58 +10:00
Brad King
18441a6269 cmGeneratorTarget: Factor target name resolution out of link item resolution 2018-09-12 12:46:51 -04:00
Brad King
fc7e4d1ed8 cmLinkItem: Convert to a "sum type" over a string and target pointer
Avoid exposing the item name implicitly as std::string.  When the item
is a target, avoid storing a second copy of its name.

Most link item construction is paired with calls to `FindTargetToLink`
to get the possible target pointer.  Rename these methods to
`ResolveLinkItem` and refactor them to construct the entire item.
2018-09-07 08:57:51 -04:00
Marc Chevrier
974de0e199 static library: add property STATIC_LIBRARY_OPTIONS
issue: #18251
2018-08-15 15:20:18 +02:00
Sebastian Holtermann
86b332c25d Return std::string from cmGeneratorTarget::ImportedGetLocation 2018-07-11 16:58:48 +02:00
Brad King
4330f10186 Merge topic 'safe_property'
42cc0644d5 Autogen: Use default and remove custom GetSafeProperty functions
127094f2f0 Add GetSafeProperty method to cmTarget, cmGeneratorTarget and cmSourceFile

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2185
2018-07-03 10:56:31 -04:00
Sebastian Holtermann
127094f2f0 Add GetSafeProperty method to cmTarget, cmGeneratorTarget and cmSourceFile 2018-07-02 12:39:54 +02:00
Marc Chevrier
cc9f88af53 LINK_DEPENDS: add support for property INTERFACE_LINK_DEPENDS
Fixes: #17997
2018-06-27 18:38:36 +02:00
Marc Chevrier
c1f5a44b28 LINK_OPTIONS: Add new family of properties
This family enable to manage link flags

Three new properties:
* directory property: LINK_OPTIONS
* target properties: LINK_OPTIONS and INTERFACE_LINK_OPTIONS

Two new commands
* add_link_options(): to populate directory property
* target_link_options(): to populate target properties

Fixes: #16543
2018-06-06 17:22:39 +02:00
Kitware Robot
d7204e649e Revise C++ coding style using clang-format-6.0
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`.  Use `clang-format` version 6.0.

* 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.
2018-06-01 09:53:42 -04:00
Michael Stürmer
fb433ff283 cmGeneratorTarget: Make import library checks config-aware 2018-04-05 06:36:49 +02:00
Michael Stürmer
4c1f33961f cmGeneratorTarget: add GetManagedType() and CheckManagedType() methods 2018-04-05 06:36:48 +02:00
Michael Stürmer
6c517a9f8d cmGeneratorTarget: add HasLanguage() as wrapper for GetLanguages() 2018-04-05 06:35:01 +02:00
Brad King
2deb9b7f34 Genex: Fix COMPILE_LANGUAGE in SYSTEM include directories
When evaluating `INTERFACE_SYSTEM_INCLUDE_DIRECTORIES`, or evaluating
`INTERFACE_INCLUDE_DIRECTORIES` on an imported target, thread the
compile language through to the generator expression evaluator so
that it can support `$<COMPILE_LANGUAGE:...>`.

Fixes: #17811
2018-03-12 11:45:01 -04:00
Daniel Pfeifer
2b4c32c95f clang-format: format all code as Cpp11 2017-08-30 11:07:05 -04:00
Daniel Pfeifer
ca2233e31f IWYU: Mark cmConfigure.h with pragma: keep
Also remove `#include "cmConfigure.h"` from most source files.
2017-08-26 07:41:04 +02:00
Daniel Pfeifer
5962db4389 Use C++11 nullptr 2017-08-24 23:39:47 +02:00
Sebastian Holtermann
952fc65d14 Autogen: Clear sources meta data cache
Adds cmGeneratorTarget::clearSourcesCache() which clears the cache
of precomputed sources lists and object names. The cache gets
recomputed on demand.

Clearing the cache is necessary in case an OBJECT library
gets a source added after a target (ORIGIN) that includes it
computed it's external sources cache.
This may happen in AUTOMOC when ORIGIN is processed before the
OBJECT library which gets a mocs_compilation.cpp file added.

Closes #17152
Closes #17139
Closes #17085
Closes #15967
2017-08-10 18:33:02 +02:00
Brad King
d89e10cd58 Diagnose object library self-reference
The code

    add_library(A OBJECT a.c)
    target_sources(A PRIVATE $<TARGET_OBJECTS:A>)

used to crash CMake via infinite recursion while evaluating the
generator expression.  Then the change in commit v3.9.0-rc1~266^2~1
(cmGeneratorTarget: Replace source classifier implementation,
2017-04-07) avoided the infinite recursion because GetKindedSources now
creates a map entry and initializes it once.  If it is called again on
the same target during that initialization, the partially computed
results are returned.  This is still wrong but does not crash.
Detect and diagnose this case instead.

Co-Author: Ben Boeckel <ben.boeckel@kitware.com>
Fixes: #16578
2017-07-14 14:05:22 -04:00
Brad King
ba247ccaba IPO: Consider support for each language separately
We only define `INTERPROCEDURAL_OPTIMIZATION` behavior for C, CXX, and
Fortran languages.  Do not try to enable support for other languages.
Furthermore, each language builds with a different compiler, so check
for support by CMake and the compiler for each language independently.

Fixes: #16944
2017-06-14 10:36:57 -04:00
Brad King
b115bc49ff Features: Refactor <LANG>_STANDARD update
In order to support generator expressions in target COMPILE_FEATURES
we apply them at generate time.  Move this step to the beginning of
generation instead of doing it on demand while collecting flags.
This avoids repeating the process unnecessarily, and will then allow
`cmLocalGenerator::AddCompilerRequirementFlag` to be used any time
during generation.
2017-05-01 10:33:05 -04:00
Daniel Pfeifer
d6f0006c0b Use CM_DISABLE_COPY 2017-04-24 22:03:06 +02:00
Daniel Pfeifer
e6c606c7ba cmGeneratorTarget::SourceFileFlags: remove custom copy ctor 2017-04-22 00:48:19 +02:00
Brad King
1d8f0f9181 Merge topic 'enable_ptx_compilation'
23691d78 CUDA: Allow sources to be compiled to .ptx files

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !725
2017-04-21 08:57:59 -04:00
Robert Maynard
23691d789e CUDA: Allow sources to be compiled to .ptx files
When the target property `CUDA_PTX_COMPILATION` is enabled CUDA OBJECT
libraries will generate ptx files instead of object files.
2017-04-20 13:25:38 -04:00
Gregor Jasny
cf320f7cd7 Replace boolean implib parameters with enum
Named enumeration values are much clearer at call sites and add more
type safety.
2017-04-20 10:22:33 -04:00