Commit Graph

903 Commits

Author SHA1 Message Date
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
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
Daniel Scharrer
d88b38d05d Normalize paths when checking for implicit include dirs
GCC replaces implicit include directories with user-supplied ones if
they point to the same directory, even if the path strings differ.
2019-06-22 23:09:17 +02:00
Saleem Abdulrasool
a982916304 Support per-language library link flags
This changes the behaviour of the generators to use a per-language
library search path flag.  This is needed for multi-language projects
with different compilers (e.g. cl + gfortran).  Since the adjusted
variable has been part of the user settings, we control this based on a
policy.

Fixes: #19307
2019-06-06 15:28:43 -07:00
Brad King
9ba901eb3c Merge topic 'swift-linker-flags'
7456739e24 Swift: avoid `CMAKE_{EXE,SHARED}_LINKER_FLAGS`

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3406
2019-06-04 08:33:14 -04:00
Saleem Abdulrasool
7456739e24 Swift: avoid CMAKE_{EXE,SHARED}_LINKER_FLAGS
Avoid the use of `CMAKE_{EXE,SHARED}_LINKER_FLAGS` when linking with the
Swift language.  This required hoisting the executable flags of
`CMAKE_CREATE_WIN32_EXE`, `CMAKE_CREATE_CONSOLE_EXE`, and
`CMAKE_EXE_EXPORTS_*_FLAG` earlier to avoid a second clause which checks
the language.  This allows for mixed-language Swift projects to properly
link on Windows.

Fixes #19298
2019-06-03 09:59:39 -04:00
Robert Maynard
619416f8a3 The error message for VISIBILITY_PRESET now documents valid options.
Rather than just state the value for VISIBILITY_PRESET was invalid,
we additionally list the accepted values.
2019-06-03 09:56:03 -04:00
Brad King
0d025f75c1 Merge topic 'implicit-includes-CPATH'
2d0b0e2b9d Do not exclude include directories made implicit by CPATH

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3395
2019-05-31 09:03:28 -04:00
Brad King
2d0b0e2b9d Do not exclude include directories made implicit by CPATH
Entries of the `CPATH` environment variable are implicitly searched as
include directories by some C/C++ compilers.  Since commit 5990ecb741
(Compute implicit include directories from compiler output, 2018-12-07,
v3.14.0-rc1~108^2) these entries are detected by CMake and included in
the `CMAKE_{C,CXX}_IMPLICIT_INCLUDE_DIRECTORIES` variables.

However, we should not exclude them from explicit specification via `-I`
or particularly `-isystem` because they are meant as user-specified
include directories that can be re-ordered without breaking compiler
builtin headers.  In particular, we need explicit requests via
`include_directories` with the `SYSTEM` option to result in `-isystem`
so that third-party headers do not produce warnings.

Co-Author: Ben Boeckel <ben.boeckel@kitware.com>
Fixes: #19291
2019-05-30 09:24:59 -04:00
Sebastian Holtermann
006229278b Use cmAppend to append ranges to std::vector instances 2019-05-23 16:19:49 +02:00
Luca Cappa
2a9ff9703e MSVC: Add support for /JMC (Just My Code) 2019-05-14 13:27:18 -04:00
Brad King
fb3370b6a1 MSVC: Add abstraction for runtime library selection
Replace our hard-coded defaults for `/MD` and `/MDd` with a first-class
abstraction to select the runtime library from an enumeration of logical
names.  We've long hesitated to do this because the idea of "runtime
library selection" touches on related concepts on several platforms.
Avoid that scope creep by simply defining an abstraction that applies
only when targeting the MSVC ABI on Windows.

Removing the old default flags requires a policy because existing
projects may rely on string processing to edit them and choose a runtime
library under the old behavior.  Add policy CMP0091 to provide
compatibility.

Fixes: #19108
2019-04-17 11:00:44 -04:00
Brad King
7795b3f2bf Merge topic 'modernize-raw-string-literal'
30bb14c657 Modernize: Enable modernize-raw-string-literal in clang-tidy

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3184
2019-04-04 11:30:54 -04:00
Brad King
8ca1b26286 cmLocalGenerator: Factor IPO logic out of AddLanguageFlags
The IPO flag logic was added to `AddLanguageFlags` based on my advice.
However, this method should really only be about `CMAKE_<LANG>_FLAGS*`
variables.  Move the IPO logic out to its call sites.
2019-04-02 14:23:32 -04:00
Artur Ryt
30bb14c657 Modernize: Enable modernize-raw-string-literal in clang-tidy 2019-04-02 19:59:54 +02:00
Artur Ryt
2d66567dca Modernize: Prefer .substr in place of .c_str() + int
A lot of temporary/local strings were created out of C-strings
substr can utilize current string size, so in theory be a little
more efficient.
2019-03-30 16:15:05 +01:00
Brad King
5674018cc6 Merge topic 'implicit-includes-autogen'
a8b7cbb787 Autogen: Do not treat hard-coded -I/usr/include exclusion as implicit include

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3159
2019-03-29 09:11:04 -04:00
Sebastian Holtermann
a8b7cbb787 Autogen: Do not treat hard-coded -I/usr/include exclusion as implicit include
The `cmLocalGenerator::GetIncludeDirectoriesImplicit` method is called
by `cmQtAutoGenInitializer` to get the compiler's list of implicit
include directories.  Since commit 557b2d6e65 (Fix regression in
-I/usr/include exclusion logic, 2019-02-13, v3.14.0-rc2~6^2~2) the
method hard-codes exclusion of `/usr/include` for historical reasons.
However, it should not be reported as a real implicit include directory
unless the compiler really has it.

Refactor the logic to distinguish the hard-coded exclusion of
`/usr/include` from the real list of implicit include directories.

Fixes: #19100
2019-03-28 14:07:24 -04:00
Brad King
94970cd042 Merge topic 'error-consolidate'
9dd255548d cmSystemTools::Error: consolidate parameters into single std::string

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2995
2019-02-25 08:02:07 -05:00
Brad King
0476d16589 Merge topic 'systools-stdstring3'
4e315e9449 cmSystemTools: More functions accept `std::string` params

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2999
2019-02-25 07:59:59 -05:00
Brad King
283b8c2ae6 Merge topic 'fix-implicit-includes-fortran'
3dc81a48ff Fortran: Do not suppress explicit use of implicit include directories

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Michael Hirsch, Ph.D. <michael@scivision.co>
Merge-request: !2994
2019-02-25 07:48:35 -05:00
Vitaly Stakhovsky
4e315e9449 cmSystemTools: More functions accept std::string params 2019-02-20 14:53:39 -05:00
Vitaly Stakhovsky
9dd255548d cmSystemTools::Error: consolidate parameters into single std::string 2019-02-20 11:18:11 -05:00
Brad King
c2f6da3399 Merge topic 'configurefile-stdstring'
0281f9a4ca cmMakefile::ConfigureFile: Accept `std::string` parameters

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2982
2019-02-20 09:03:48 -05:00
Brad King
3dc81a48ff Fortran: Do not suppress explicit use of implicit include directories
Since commit 2e91627dea (ParseImplicitIncludeInfo: add Fortran implicit
include handling, 2019-01-25, v3.14.0-rc1~73^2) we actually populate
`CMAKE_Fortran_IMPLICIT_INCLUDE_DIRECTORIES` for the first time.  This
value may be useful to project code to pass to other tooling that wants
to preprocess the way Fortran does, so we should compute the value.
However, compilers like `gfortran` do not actually search their own
implicit include directories for `.mod` files.  The directories must be
passed via `-I` in order for `.mod` files in them to be found.

Since Fortran has no standard library header files that we need to avoid
overriding, it is safe to *not* filter out implicit include directories
from those passed explicitly via `-I` options.  Skip this filtering so
that include directories specified by project code to find `.mod` files
will be searched by the compiler even if they happen to be implicitly
searched by the preprocessor.

Fixes: #18914
2019-02-20 08:13:57 -05:00
Brad King
2bff8513f2 Merge topic 'modernize-for-loops-c-arrays'
706b93fa55 Modernize: C-arrays and loops over them

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2951
2019-02-19 07:56:41 -05:00
Brad King
2dd2079152 Merge topic 'fix-legacy-implicit-includes'
890bae524c Do not explicitly report "standard" include directories as implicit
5c171ca898 Restore unconditional use of "standard" include directories
9502276f82 Prefix implicit include directories with sysroot on construction

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2981
2019-02-19 07:54:57 -05:00
Vitaly Stakhovsky
0281f9a4ca cmMakefile::ConfigureFile: Accept std::string parameters 2019-02-18 20:48:19 -05:00
Brad King
890bae524c Do not explicitly report "standard" include directories as implicit
In commit 1293ed8507 (ParseImplicitIncludeInfo: keep implicit incl.
consistent when rerunning cmake, 2019-01-30, v3.14.0-rc1~26^2) we did
not account for `CMAKE_<LANG>_STANDARD_INCLUDE_DIRECTORIES`.  This
variable lets platform modules or toolchain files specify directories
that are to be explicitly passed as standard include directories.  These
include directories are used by the test project from which we extract
implicit include directories so they appear in the parsed results
whether or not the compiler really considers them implicit.  Exclude
these entries from the computed implicit include directories since they
are not actually implied by the compiler when we invoke it with
"standard" include directories passed explicitly.

Instead teach the build system generators to treat the "standard"
directories as implicit for purposes of excluding them from appearing
earlier in the compiler command line due to `include_directories` and
`target_include_directories` calls.

Issue: #18936, #18944
2019-02-18 17:12:14 -05:00
Brad King
5c171ca898 Restore unconditional use of "standard" include directories
`CMAKE_<LANG>_STANDARD_INCLUDE_DIRECTORIES` is meant to unconditionally
add explicitly specified include directories to compile lines.  In
commit 5f34bdc7f9 (cmLocalGenerator: Refactor
`GetIncludeDirectoriesImplicit` method, 2019-01-25, v3.14.0-rc1~65^2~1)
a condition was accidentally added to exclude implicit include
directories.  Drop that condition.

Fixes: #18936
2019-02-18 17:10:07 -05:00
Brad King
9502276f82 Prefix implicit include directories with sysroot on construction
Since commit 7cd65c97fa (Add CMAKE_SYSROOT variable to set --sysroot
when cross compiling., 2013-04-13, v3.0.0-rc1~342^2) we have prefixed
the value of `CMAKE_SYSROOT` to implicit include directories.  This was
done because we hard-coded `/usr/include` as an implicit include
directory without accounting for the sysroot.  Instead we should prefix
the hard-coded paths when they are constructed.  Update the
`Platform/UnixPaths` module to do this as `Platform/Darwin` already
does.

Since commit 5990ecb741 (Compute implicit include directories from
compiler output, 2018-12-07, v3.14.0-rc1~108^2) the values of the
`CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES` variables are computed from
a real compiler invocation so they already account for the sysroot
prefix.  In commit 6fc3382944 (Update logic for sysroot in detected
implicit include directories, 2019-02-13, v3.14.0-rc2~6^2) we attempted
to apply the prefix conditionally, but that is incorrect because the
compiler's real implicit include directories are not all under the
sysroot.  Instead assume that all implicit include directories in
`CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES` already have the sysroot
prefix if needed.  Code that constructs the value must be responsible
for that because it is the only place that knows.
2019-02-18 17:09:26 -05:00
Artur Ryt
706b93fa55 Modernize: C-arrays and loops over them
It replaces C arrays with deduced std::initializer_lists
or std::array what makes enables for-loop over them.
2019-02-15 23:40:30 +01:00
Brad King
50ba2f019b Merge topic 'fix-legacy-implicit-includes'
6fc3382944 Update logic for sysroot in detected implicit include directories
2ad14ef4ea cmAlgorithms: Add cmHasPrefix to match existing cmHasSuffix
557b2d6e65 Fix regression in -I/usr/include exclusion logic
017598a444 macOS: Fix addition of <sdk>/usr/include to default implicit include dirs

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2957
2019-02-14 10:14:47 -05:00
Brad King
6fc3382944 Update logic for sysroot in detected implicit include directories
Since commit 5990ecb741 (Compute implicit include directories from
compiler output, 2018-12-07, v3.14.0-rc1~108^2) the values of the
`CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES` variables are computed from
a real compiler invocation.  In this case the paths under the sysroot
should already have the sysroot prefix so we should no longer have to
add the sysroot prefix.  However, it is also possible for project code
to add its own paths to `CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES`
without the sysroot prefix and expect the historical addition of the
sysroot prefix to be preserved.

Try to account for both cases by conditionally adding the sysroot prefix
on implicit include directories that do not already have it.
2019-02-13 10:03:56 -05:00
Brad King
557b2d6e65 Fix regression in -I/usr/include exclusion logic
The change in commit 15ad830062 (Refactor exclusion of -I/usr/include to
avoid per-language values, 2019-01-21, v3.14.0-rc1~108^2~4) caused the
exclusion to apply to Fortran, but it was only meant for C, CXX, and
CUDA.  The purpose of the change was to prepare for the value of
`CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES` to be computed from the
actual compiler instead of hard-coded.  We need to preserve exclusion of
`-I/usr/include` if the compiler has any implicit include directory that
looks intended to replace it, e.g. `<sdk>/usr/include` on macOS.

Fixes: #18914
2019-02-13 09:52:20 -05:00
Brad King
4b37b4f1bb Merge topic 'modernize-for-loops'
01b2d6ab74 Modernize: Use ranged for-loops when possible
15bdbec017 cmAlgorithms: Make cmRange advance/retreat safe for rvalues

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Daniel Pfeifer <daniel@pfeifer-mail.de>
Merge-request: !2901
2019-02-11 08:08:22 -05:00
Artur Ryt
01b2d6ab74 Modernize: Use ranged for-loops when possible
Replaced most manual `const_iterator`-based loops and some
reverse-iterator loops with range loops.

Fixes: #18858
2019-02-07 22:39:05 +01:00
Vitaly Stakhovsky
00ba28ffd0 cmMakefile::GetRequiredDefinition: return const std::string& 2019-02-07 07:35:16 -05:00
Brad King
60c06620a6 Merge topic 'cmoutputconverter-simplify'
b6a957c969 cmOutputConverter: move ConvertToRelativePath to cmStateDirectory.

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2831
2019-01-29 09:18:42 -05:00
Brad King
90ac5e6384 Merge topic 'message-stdstring'
186d9b083d cmSystemTools::Message: Add overload accepting std::string

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2869
2019-01-29 09:17:51 -05:00
Vitaly Stakhovsky
186d9b083d cmSystemTools::Message: Add overload accepting std::string 2019-01-28 09:35:51 -05:00
Sebastian Holtermann
5f34bdc7f9 cmLocalGenerator: Refactor GetIncludeDirectoriesImplicit method
Use a dedicated `std::set` for implicit include directories instead
of (ab)using the emitted variable.  This in combination with lambdas
makes it easier to comprehend which paths are emitted.

For the implicit include directories we used to omit the
`CMAKE_SYSROOT_COMPILE`/`CMAKE_SYSROOT` prefix.  This has been changed and
the implicit paths are returned prefixed.  Implicit include directory returning
is only ever used by QtAutoGen which requires prefixed paths.  QtAutoGen passes
the (implicit) include paths to the `moc` which isn't aware of
`CMAKE_SYSROOT_COMPILE`/`CMAKE_SYSROOT`.
2019-01-28 08:41:28 -05:00
Sebastian Holtermann
f16dfdf71f cmLocalGenerator: Simplify GetIncludeDirectories
This patch strips the `stripImplicitDirs` and `appendAllImplicitDirs`
parameters from the `cmLocalGenerator::GetIncludeDirectories` method and makes
it a wrapper into the new `cmLocalGenerator::GetIncludeDirectoriesImplicit`
method.  `cmLocalGenerator::GetIncludeDirectoriesImplicit` is the renamed old
implementation of `cmLocalGenerator::GetIncludeDirectories` and still
accepts `stripImplicitDirs` and `appendAllImplicitDirs`.

The motivation is that there's only *one* case where
`cmLocalGenerator::GetIncludeDirectories` is called with the
`stripImplicitDirs` parameter being `false` (QtAutoGen), but many other places
where it is called using the `true` default value.

QtAutoGen is modified to use `cmLocalGenerator::GetIncludeDirectoriesImplicit`
directly.  In two use cases of `cmLocalGenerator::GetIncludeDirectories`
the manually set `true` value for `stripImplicitDirs` is removed.
2019-01-28 08:41:28 -05:00
Bruno Manganelli
b6a957c969 cmOutputConverter: move ConvertToRelativePath to cmStateDirectory. 2019-01-27 15:48:57 +00:00
Vitaly Stakhovsky
99337d345b cmSystemTools::Error(): new overload accepting std::string 2019-01-23 10:19:30 -05:00
Brad King
e898f48bbc Merge topic 'getmodulesfile-string'
2993fc347a cmMakefile: GetModulesFile() accepts std::string param

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2838
2019-01-23 08:16:15 -05:00
Brad King
fa5bf870df Merge topic 'implicit-includes'
5990ecb741 Compute implicit include directories from compiler output
d751d2d2ed CMakeDetermineCompilerABI: set locale to C for try_compile()
c765ae495a CMakeDetermineCompilerABI: pass verbose flag during compilation
8c5221fb1f try_compile: Preserve special characters in COMPILE_DEFINITIONS
15ad830062 Refactor exclusion of -I/usr/include to avoid per-language values

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2716
2019-01-22 11:37:49 -05:00
Vitaly Stakhovsky
2993fc347a cmMakefile: GetModulesFile() accepts std::string param 2019-01-21 12:56:51 -05:00
Brad King
15ad830062 Refactor exclusion of -I/usr/include to avoid per-language values
Add a `CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES` to contain the
hard-coded list of paths to be excluded from `-I` arguments so that the
values remain excluded even if the per-language
`CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES` variants change.

This is needed to preserve our historical exclusion of `-I/usr/include`
even when it is not a real implicit include directory.  A policy may be
needed to remove it later.
2019-01-21 11:14:07 -05:00
Regina Pfeifer
ef61997b1b clang-tidy: Use emplace 2019-01-17 13:12:02 -05:00