498 Commits

Author SHA1 Message Date
Sebastian Holtermann
f71f7ce3f0 cmStringAlgorithms: Move string functions to the new cmStringAlgorithms.h
This adds the `cmStringAlgorithms.h` header and moves all string functions
from `cmAlgorithms.h` to `cmStringAlgorithms.h`.
2019-07-29 21:13:56 +02:00
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
ad2b3a32d1 Genex: Optimize build setting TARGET_PROPERTY evaluation
For each build setting property (such as `COMPILE_DEFINITIONS` or
`INCLUDE_DIRECTORIES`), the value of `$<TARGET_PROPERTY:target,prop>`
includes the values of the corresponding `INTERFACE_*` usage requirement
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 using the dedicated evaluation
method `cmGeneratorTarget::EvaluateInterfaceProperty`.

Issue: #18964, #18965
2019-07-23 06:50:31 -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
2682714a3f cmGeneratorTarget: Refactor usage requirement genex evaluation
Evaluate usage requirement generator expressions fully before entering
the processing loops.  This allows us to evaluate and collect all
entries up front and then have only one call to the loop over them.
This also allows `AddInterfaceEntries` to immediately evaluate the
generator expressions it synthesizes, which will enable later
optimization.
2019-07-19 13:38:30 -04:00
Brad King
3cbc15773f cmGeneratorTarget: Move static functions to anonymous namespace 2019-07-19 13:05:21 -04:00
Brad King
33494a507d cmGeneratorTarget: Order usage requirement processing logic consistently
Re-order logic in all `process*` methods so that they all evaluate
generator expressions at the beginning of their loops.
2019-07-19 09:58:12 -04:00
Brad King
c131e62f7b cmGeneratorTarget: Remove unnecessary copy to local variable 2019-07-19 09:58:12 -04:00
Brad King
fab72918c9 cmGeneratorTarget: Remove unused member of internal class 2019-07-19 09:58:12 -04:00
Brad King
2fa920c0cd AIX: Create import library for executables with exports
On AIX, plugins meant to be loaded into executables via `dlopen` must be
linked with access to a list of symbols exported from the executable in
order to use them (when not using runtime linking).  The AIX linker
supports specifying this list as an "import file" passed on the command
line either via the `-bI:...` option or (with a leading `#! .` line) as
a normal input file like any other library file.

The linker import file plays the same role on AIX as import libraries do
on Windows.  Teach CMake to enable its import library abstraction on AIX
for executables with the `ENABLE_EXPORTS` target property set.  Teach
our internal `ExportImportList` script to optionally generate a leading
`#! .` line at the top of the generated export/import list.  Update our
rule for linking an executable with exports to generate a public-facing
"import library" implemented as an AIX linker import file.

With this approach, our existing infrastructure for handling import
libraries on Windows will now work for AIX linker import files too:

* Plugins that link to their executable's symbols will be automatically
  linked using the import file on the command line.

* The executable's import file will be (optionally) installed and
  exported for use in linking externally-built plugins.

This will allow executables and their plugins to build even if we later
turn off runtime linking.

Issue: #19163
2019-07-16 14:15:13 -04:00
Brad King
9f5c2040bf AIX: Explicitly compute executable exports for both XL and GNU
On AIX, symbols in executables must be exported in order to be visible
to modules (plugins) they load via `dlopen`.  Prior to policy `CMP0065`,
CMake linked all executables with flags to export symbols, but the NEW
behavior for that policy is to do so only for executables that have the
`ENABLE_EXPORTS` target property set.  In both cases, CMake has always
used the AIX linker option `-bexpall` option to export symbols from
executables.

This has worked fairly well with the XL compiler, but with the GNU
compiler it works only for C ABI symbols.  The reason is that `-bexpall`
does not export symbols starting in `_` but the GNU C++ ABI mangles all
symbols with a leading `_`.  Therefore we have only supported C ABI
plugins with the GNU compiler on AIX.  Some projects have tried to work
around this by replacing `-bexpall` with `-bexpfull`, but the latter
often exports symbols that we do not want exported.

Avoid using `-bexpall` for executables by instead using by our own
internal `ExportImportList` script to compute symbol export lists from
the object files to be linked into an executable.  Pass the explicitly
computed export list to the AIX linker's `-bE:...` option.  We already
do this for shared object exports.

Issue: #19163
2019-07-15 13:27:16 -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
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
Kyle Edwards
d29ed8a114 BUILD_RPATH/INSTALL_RPATH: Add generator expression support
Fixes: #19423
2019-06-25 10:55:03 -04:00
Sebastian Holtermann
9e64e617eb cmPropertyMap: Rename GetPropertyList method to GetKeys 2019-06-08 12:25:35 +02: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
f6241db3e0 cmTarget: Move member OriginalLinkLibraries to impl 2019-03-23 21:45:09 +01:00
Marc Chevrier
6ae5fffd0f Optimize target properties processing at generation step
Avoid creating unnecessary `cmCompileGeneratorExpression` instances.
Use runtime polymorphism to avoid the full genex infrastructure when a
property value does not contain a genex.

Issue: #18965
2019-03-07 09:25:43 -05:00
Brad King
a4d99e4dec Merge topic 'cmrange-improvements'
b8031308f3 cmRange: Add unit tests
a8d51ef8b7 cmRange: Add functions filter and transform
da4773e8b8 cmRange: Add functions all_of, any_of, none_of
17a367e77f cmRange: Stylistic cleanup
9eb0e73f46 cmRange: Move to dedicated header file

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Artur Ryt <artur.ryt@gmail.com>
Merge-request: !2972
2019-02-25 08:03:01 -05:00
Brad King
c068236bb9 Merge topic 'link-options'
98a2d42301 PIE link options: No warning when policy CMP0083 is not set.

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2996
2019-02-25 07:51:01 -05:00
Regina Pfeifer
9eb0e73f46 cmRange: Move to dedicated header file 2019-02-21 08:24:25 -05:00
Marc Chevrier
98a2d42301 PIE link options: No warning when policy CMP0083 is not set.
Fixes: #18955
2019-02-20 14:30:57 -05: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
Artur Ryt
f3534386b5 Prefer front/back/data over dereferencing begin/rbegin iter
Changed for sequenced containers: vector, list, string and array
2019-02-06 10:43:16 -05:00
Brad King
8a7f93d000 Xcode: Fix object library builds with sanitizers enabled
Using `xcodebuild -enableAddressSanitizer YES ...` causes object files
to be placed in a different directory name.  Xcode provides a
placeholder for this that we can use in `OTHER_LDFLAGS` to reference
object files for linking the dependents of object libraries.  However,
CMake's features for installing and exporting object libraries depend on
knowing the real path with no placeholders.  For these cases, use the
default object directory.  Users will then have to choose between
sanitizers and the installation and export features, but both will work
individually.

Fixes: #16289
2019-01-30 10:28:40 -05:00
Brad King
40745ad35a Merge topic 'cmake-files-directory'
3e867ed400 cmake: inlined files dir constant and removed it from cmake.h

Acked-by: Kitware Robot <kwrobot@kitware.com>
Rejected-by: vvs31415 <vstakhovsky@fastmail.com>
Merge-request: !2655
2019-01-25 08:01:26 -05:00
Vitaly Stakhovsky
99337d345b cmSystemTools::Error(): new overload accepting std::string 2019-01-23 10:19:30 -05:00
Regina Pfeifer
5a0784ddea clang-tidy: Pass by value 2019-01-22 13:03:04 -05:00
Bruno Manganelli
3e867ed400 cmake: inlined files dir constant and removed it from cmake.h 2019-01-21 15:34:16 +00:00
Brad King
1fba410ecf Merge topic 'autogen_mocs_compilation_first'
1ed4d48dcf Autogen: Prepend instead of append `mocs_compilation.cpp` to the sources list
a42b700cc2 cmTarget,cmGeneratorTarget: Add optional `before` parameter to AddSource

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Peter Wu <peter@lekensteyn.nl>
Merge-request: !2815
2019-01-21 07:53:23 -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
ef61997b1b clang-tidy: Use emplace 2019-01-17 13:12:02 -05:00
Brad King
bd54cc774a Merge topic 'semi-warnings'
b056bc3425 Fix most clang -Wextra-semi-stmt warnings in C++ files

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2795
2019-01-16 09:52:45 -05: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
Sean McBride
b056bc3425 Fix most clang -Wextra-semi-stmt warnings in C++ files
Suppress one in code generated by flex.
2019-01-15 14:09:46 -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
Marc Chevrier
c4b4d8b3a6 POSITION_INDEPENDENT_CODE: Manage link flags for executables
Fixes: #14983, #16561
2018-11-11 17:34:09 +01:00
Marc Chevrier
023188ffb4 INTERFACE_POSITION_INDEPENDENT_CODE: add generator expressions support
Fixes: #16532
2018-11-08 14:58:57 +01:00
Cengizhan Pasaoglu
c67ab22cdc Using front() and back() instead of calculations 2018-11-06 21:43:33 +03: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