Commit Graph

206 Commits

Author SHA1 Message Date
Brad King
31ee3cd49d try_compile: Fail earlier when bindir is not an absolute path
If the bindir is not an absolute path, other errors occur later.
Fail early with a clear error in this case.
2022-07-26 14:41:28 -04:00
Brad King
6940a67d47 Merge topic 'try_compile-cross-app-bundles'
81549baff4 try_compile: Fix COPY_FILE with app-bundles on non-macOS hosts

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !7377
2022-06-17 11:31:38 -04:00
Heiko Lewin
81549baff4 try_compile: Fix COPY_FILE with app-bundles on non-macOS hosts
Cross compiling from eg linux to apple-platforms requires handling of
.app-Bundles.

Fixes: #23597
2022-06-16 14:29:16 -04:00
Brad King
086030caf0 Merge topic 'cuda_use_response_files'
6377a43814 CUDA: Support response files with nvcc

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !7358
2022-06-15 09:55:26 -04:00
Robert Maynard
6377a43814 CUDA: Support response files with nvcc 2022-06-13 14:56:58 -04:00
FeRD (Frank Dana)
98a10290a8 cmSystemTools: Fix 'ErrorOccurred' spelling
Rename the booleans 's_ErrorOccured' and 's_FatalErrorOccured' to
's_ErrorOccurred' and 's_FatalErrorOccurred', respectively.

Rename the getters and setters to 'Get[Fatal]ErrorOccurred' and
'Set[Fatal]ErrorOccurred', and fix all uses across the codebase.
2022-06-13 09:05:24 -04:00
Ben Boeckel
a5f8cbe8b1 clang-tidy: address modernize-use-default-member-init lints 2022-05-24 09:09:43 -04:00
Brad King
a6562ff579 try_compile: Add option to skip passing platform variables
Add a `CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES` variable to tell
`try_compile` not to pass platform variables to the test project.

Issue: #23219
2022-05-16 10:47:21 -04:00
Brad King
4843a37676 try_compile: Propagate platform variables in project-mode too
Add policy CMP0137 to propagate both our builtin variables and those
listed by `CMAKE_TRY_COMPILE_PLATFORM_VARIABLES` to `try_compile`
whole-project builds.

Inspired-by: Alexander Neumann <Alexander.Neumann@hamburg.de>
Fixes: #23219
2022-05-16 10:39:42 -04:00
Cameron Cawley
33da5824ac OpenWatcom: Allow specifying the runtime library
Add a `CMAKE_WATCOM_RUNTIME_LIBRARY` variable to control the
runtime library selection.  Add policy CMP0136 to switch to
in place of the old hard-coded default flags.

Fixes: #23178
2022-05-06 10:40:58 -04:00
Brad King
40f380fcb0 cmCoreTryCompile: Replace vector push_back with emplace_back 2022-05-05 11:23:40 -04:00
Brad King
c6b0657f5b cmCoreTryCompile: Move platform variable forwarding to dedicated block
Prepare to enable the behavior under more conditions.

Issue: #23219
2022-05-05 11:23:12 -04:00
Craig Scott
a10fc754a6 CheckSourceCompiles: Avoid linker warning with -fembed-bitcode
When the Apple linker sees -headerpad_max_install_names and
bitcode is enabled with a flag like -fembed-bitcode, it issues a warning
and ignores the -headerpad_max_install_names flag. This causes
unrelated compiler and linker flag checks to fail for valid flags.
In f745e0497e (CheckCompilerFlags: Catch linker warning about ignored
flags, 2022-01-03), we started detecting linker warnings, which caused
a regression for projects that were setting -fembed-bitcode in their
CMAKE_CXX_FLAGS or similar. Prevent that regression by removing
the -headerpad_max_install_names linker flag when we know it will
warn and be ignored anyway.

Fixes: #23390
Issue: #23408
2022-04-09 21:51:09 +10:00
Sean McBride
5ba6e8ac59 Source: Replace most calls to sprintf with snprintf 2021-10-25 18:23:13 -04:00
Sean McBride
37859e3244 Source: Fix clang -Wimplicit-fallthrough warnings 2021-09-28 10:53:54 -04:00
Marc Chevrier
cc56dc7468 Rename cmProp in cmValue 2021-09-21 17:14:04 +02:00
Marc Chevrier
79362cf117 cmProp: cm::string_view cast operator must be explicit
To avoid ambiguity on std::string assigment between the following two
cmProp cast operators:
* operator const std::string&() const noexcept
* operator cm::string_view() const noexcept
2021-09-14 17:42:02 +02:00
Marc Chevrier
e5cd39ca80 cmProp: refactoring: transform alias in class
To handle safely the values used by CMake variables and properties,
introduce the class cmProp as a replacement from the simple pointer
to std::string instance.
2021-08-08 16:19:08 +02:00
Brad King
144be54dd3 try_compile: Propagate CMP0126 to the generated test project
Set policy CMP0126 to the value used in the calling project.
It may affect toolchain file behavior.
2021-07-20 09:47:02 -04:00
Robert Maynard
b50bfc8913 HIP: Add language to CMake 2021-06-07 19:25:33 +00:00
Lingkai Dong
c4941b7e66 ARMClang: Do not automatically add cpu/arch compile or link options
The compile options `--march=<arch>` and `--mcpu=<cpu>` and the
link option `--cpu=<cpu>` are automatically added by CMake based
on `CMAKE_SYSTEM_PROCESSOR` or `CMAKE_SYSTEM_ARCH`. But this is not
sufficient, because armclang also supports enabling or disabling
features using `+<feature>`:

    -mcpu=<name>[+[no]<feature>+...]

For example:

    -mcpu=cortex-a57+nocrypto+nofp+nosimd+crc

(Reference: https://developer.arm.com/documentation/dui0774/k/Compiler-Command-line-Options/-mcpu?lang=en)

The problem is, even if a project adds a flag with features it needs,
CMake still adds flags, resulting in code that is compiled with wrong
CPU features and unable to run.

Add policy `CMP0123` to not automatically add compile or link options,
and let projects set them instead.

Co-Author: Brad King <brad.king@kitware.com>
Fixes: #21173
2021-04-27 14:03:15 -04:00
Brad King
c2d2772f15 try_compile: Improve error message when a file cannot be removed 2021-04-15 12:40:37 -04:00
Robert Maynard
c9a50f3556 ISPC: Generated Headers suffix configurable with a better default
The target property `ISPC_HEADER_SUFFIX` and associated global
variable now can control the suffix used when generating the
C/C++ interoperability ISPC headers.

In addition the default suffix is now "_ispc.h" which matches the
common convention that the ISPC compiler team uses and recommends.
2020-12-14 13:13:09 -05:00
Robert Maynard
a020787a9b ISPC: Support generation for multiple instruction sets 2020-09-04 08:37:07 -04:00
Vitaly Stakhovsky
11425041f0 cmMakefile::GetDefinition: return cmProp 2020-09-02 07:27:32 -04:00
Robert Maynard
34cc6acc81 Add ISPC compiler support to CMake 2020-08-28 11:21:31 -04:00
Vitaly Stakhovsky
f37c14e930 Source: use cmNonempty() 2020-07-28 08:31:31 -04:00
Vitaly Stakhovsky
eaad8072ee cmNonempty: Convenience inlines to check for non-empty string 2020-07-14 15:18:59 -04:00
Brad King
81399d5438 Merge topic 'refactor_language_mapping_logic'
c4e890946a try_compile: consistently add language properties
0e16da8233 cmCoreTryCompile use anonymous namespace instead of static

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4895
2020-06-23 08:13:16 -04:00
Robert Maynard
c4e890946a try_compile: consistently add language properties
It was very easy to forgot to add all the possible language
properties that try_compile might need. Refactored the code
to make it harder to skip flags.

This changes adds the missing language properties for
the CUDA, Fortran, OBJC, OBJCXX, and Swift languages:

- CMAKE_<LANG>_COMPILER_EXTERNAL_TOOLCHAIN
- CMAKE_<LANG>_COMPILER_TARGET
- CMAKE_<LANG>_LINK_NO_PIE_SUPPORTED
- CMAKE_<LANG>_PIE_SUPPORTED
2020-06-22 08:37:44 -04:00
Brad King
43e8db481b Merge topic 'try_compile-nfs'
a9a258c302 try_compile: Do not try to remove '.nfs*' files

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Robert Maynard <robert.maynard@kitware.com>
Acked-by: Axel Huebl <axel.huebl@plasma.ninja>
Merge-request: !4913
2020-06-19 08:14:05 -04:00
Robert Maynard
0e16da8233 cmCoreTryCompile use anonymous namespace instead of static 2020-06-18 14:44:02 -04:00
Brad King
a9a258c302 try_compile: Do not try to remove '.nfs*' files
These files are part of the NFS implementation and should not be
removed.  They will automatically disappear when NFS is done with them.

Fixes: #20844
2020-06-17 15:15:02 -04:00
Robert Maynard
574f71efba try_compile: Refactor language standard level parsing
cmCoreTryCompile had significant code duplication around handling
languages that offer standard levels. This refactoring reduces
the complexity and makes it easier to add new languages in the
future.
2020-06-17 06:30:39 -04:00
Brad King
5bf9a290e7 CUDA: Fix CUDA_ARCHITECTURES policy CMP0104 check in try_compile
Since commit e98588aaba (CUDA: Add CUDA_ARCHITECTURES target property,
2020-03-12), `CMAKE_CUDA_ARCHITECTURES` is both initialized and required
by policy CMP0104's `NEW` behavior.  Inside a `try_compile` project we
use `cmake_minimum_required(VERSION ...)` with the current running
version of CMake.  Now that our version number is 3.18, `CMP0104` gets
set to `NEW` in the `try_compile`.  If the outer projects does not set
the policy then `CMAKE_CUDA_ARCHITECTURES` is not available and the
`try_compile` fails to generate.

Teach `try_compile` to check the outer project's policy status and
set policy CMP0104 to `OLD` if needed to match.

Fixes: #20794
2020-06-05 10:09:33 -04:00
Brad King
d8eee80e30 Merge branch 'backport-cuda-default-runtime' into cuda-default-runtime 2020-05-22 06:50:19 -04:00
Robert Maynard
1086e930dc CUDA: Propagate CMAKE_CUDA_RUNTIME_LIBRARY state to try_compile 2020-05-20 14:36:55 -04:00
Marc Chevrier
8d4a9ee398 Refactoring: rename "cm_static_string_view.hxx" as <cmext/string_view> 2020-04-30 09:53:27 +02:00
Raul Tambre
e98588aaba CUDA: Add CUDA_ARCHITECTURES target property
Simplifies CUDA target architecture handling.

Required for Clang support as Clang doesn't automatically select a supported architecture.
We detect a supported architecture during compiler identification and set CMAKE_CUDA_ARCHITECTURES to it.

Introduces CMP0104 for backwards compatibility with manually setting code generation flags with NVCC.

Implements #17963.
2020-04-15 17:55:41 +03:00
Raul Tambre
87e98bf8be CUDA: Forward CMAKE_CUDA_COMPILER_TARGET in try_compile()
Required for crosscompile support with Clang.
2020-04-07 09:33:26 -04:00
Vitaly Stakhovsky
ef408dd232 cmState::GetTargetTypeName: return type is *cmProp 2020-03-19 08:55:03 -04:00
Johnny Jazeix
a024d614ca cmCoreTryCompile::CleanupFiles now removes symlinks instead of their contents.
Fixes: #17522
2019-12-26 17:39:36 +01:00
Tor Arne Vestbø
a9b41195d2 Handle multi-arch sysroots on Apple platforms 2019-12-13 16:35:38 +01:00
Cristian Adam
7447aa4b34 ObjC: Add try_compile support
Fixes: #19920
2019-11-09 11:25:32 +01:00
Saleem Abdulrasool
466ad466b4 try_compile: support Swift for cross-compilation
Ensure that we preserve the `CMAKE_Swift_COMPILER_TARGET` variable to
use cross-compilation for testing the Swift compiler if appropriate.
2019-10-15 13:25:14 -04:00
Kitware Robot
ed98209ddc Revise include order using clang-format-6.0
Run the `clang-format.bash` script to update our C and C++ code to a new
include order `.clang-format`.  Use `clang-format` version 6.0.
2019-10-01 12:26:36 -04:00
Regina Pfeifer
f30523d090 clang-tidy: modernize-deprecated-headers 2019-09-16 10:11:13 -04:00
Sebastian Holtermann
aaf59120bf Source sweep: Replace cmExpandList with the shorter cmExpandedList
This replaces the code pattern
```
std::vector<std::string> args;
cmExpandList(valueStr, args, ...)
```
with
```
std::vector<std::string> args = cmExpandedList(valueStr, ...)
```
2019-08-23 17:07:49 +02:00
Sebastian Holtermann
9b334397f5 Source sweep: Use cmStrCat for string concatenation
This patch is generated by a python script that uses regular expressions to
search for string concatenation patterns of the kind

```
std::string str = <ARG0>;
str += <ARG1>;
str += <ARG2>;
...
```

and replaces them with a single `cmStrCat` call

```
std::string str = cmStrCat(<ARG0>, <ARG1>, <ARG2>, ...);
```

If any `<ARGX>` is itself a concatenated string of the kind

```
a + b + c + ...;
```

then `<ARGX>` is split into multiple arguments for the `cmStrCat` call.

If there's a sequence of literals in the `<ARGX>`, then all literals in the
sequence are concatenated and merged into a single literal argument for
the `cmStrCat` call.

Single character strings are converted to single char arguments for
the `cmStrCat` call.

`std::to_string(...)` wrappings are removed from `cmStrCat` arguments,
because it supports numeric types as well as string types.

`arg.substr(x)` arguments to `cmStrCat` are replaced with
`cm::string_view(arg).substr(x)`
2019-08-22 16:38:10 +02:00
Rolf Eike Beer
da26b3be89 avoid adding multiple consecutive string literals to std::string
While at it change some single character additions to be of type char.
2019-08-18 14:22:11 +02:00