1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-06-12 00:40:45 +08:00

271 Commits

Author SHA1 Message Date
Matthew Woehlke
aac542f2f1 try_run: Remove PROJECT support
Remove PROJECT support from try_run; it was never tested, has never been
documented, and it's unclear how it should even work (since CMake
wouldn't know what executable to run).
2022-09-21 15:38:06 -04:00
Matthew Woehlke
30a234d275 try_compile: Improve error message consistency
Tweak some error messages from try_compile (and try_run) to be more
consistent with each other.
2022-09-16 15:29:35 -04:00
Matthew Woehlke
56ae40cc59 try_compile: Add PROJECT keyword-dispatched signature
Introduce a new signature for the project flavor of try_compile (and
try_run) which removes the `bindir` argument and adds a required PROJECT
tag. This is similar to the SOURCES flavor added by commit aa9220d3
(try_compile: Add keyword-dispatched signature, 2022-09-02).
2022-09-14 16:35:50 -04:00
Brad King
c3e68020d6 Merge topic 'MsvcDebugInformationFormatAbstraction'
a858466aac MSVC: Add test for debug information format
0e96a20478 MSVC: Add abstraction for debug information format
d4c8111da4 Clang/Windows: Clarify name of internal runtime library flags variables

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7606
2022-09-14 09:21:27 -04:00
Glen Chung
0e96a20478 MSVC: Add abstraction for debug information format
Replace our hard-coded default for `/Zi` with a first-class abstraction
to select the debug information format an enumeration of logical
names.  We've long hesitated to do this because the idea of "debug
information format" 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 flag 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 CMP0141 to
provide compatibility.

Fixes: #10189
2022-09-14 09:12:47 -04:00
Robert Maynard
0c141b0393 try_compile: Record output location instead of reverse computing it
Fixes #23887, #23942, #20163, #18288
2022-09-07 15:08:41 -04:00
Matthew Woehlke
aa9220d3a0 try_compile: Add keyword-dispatched signature
Introduce a new signature for try_compile (and try_run) which removes
the `bindir` argument and requires the SOURCES tag. This will eventually
allow us to add other ways of providing sources, but also allows us to
change the behavior without breaking compatibility.

The old signature uses a special, but non-unique temporary location
inside the specified `bindir`, which conventionally is just the
project's build directory. The new signature unconditionally uses the a
unique temporary directory which is unconditionally within the project's
build directory (which is no longer separately specified). This ensures
that successive runs do not overwrite previous runs, will simplify
debugging, and should also, eventually, allow us to execute multiple
trials in parallel.
2022-09-05 13:19:59 -04:00
Matthew Woehlke
b976b844d2 try_compile: Don't accept try_run arguments
Modify cmCoreTryCompile to only recognize try_run arguments when
actually parsing try_run. (The old behavior was to recognize try_run
arguments for try_compile also and then complain.)

This has a small chance that a try_run keyword will be consumed as part
of a multi-valued keyword argument. However, this behavior is more
consistent with other commands, as we don't normally treat keywords as
universally reserved. Also, the code is noticeably simplified.
2022-08-17 15:44:35 -04:00
Matthew Woehlke
24c83bb35b try_compile: Fix quotes in reporting of unknown arguments
In commit 6b427d8da9 (cmCoreTryCompile: Port to cmArgumentParser,
2022-08-01) we inadvertently dropped a matching quote during refactoring
of reporting unknown arguments given to try_compile/try_run.  Add the
missing quote to match the old behavior and not have an imbalanced quote
in the warning.
2022-08-17 15:44:29 -04:00
Brad King
6b427d8da9 cmCoreTryCompile: Port to cmArgumentParser 2022-08-02 12:54:56 -04:00
Brad King
067ba3a2bd cmCoreTryCompile: Move target type selection logic to try_compile
This is specific to `try_compile` since `try_run` always needs an
executable.  Move the logic out of the common code path.
2022-08-02 08:04:21 -04:00
Brad King
781e1b191a cmCoreTryCompile: Simplify TryCompileCode return type
The return value is only used as a boolean, so use `bool`.
2022-08-02 08:04:20 -04:00
Brad King
7a5b1b6010 cmCoreTryCompile: Select source-file signature project/target names earlier 2022-07-26 15:09:48 -04:00
Brad King
8b0ee799e4 cmCoreTryCompile: Compute src-file signature build directory earlier 2022-07-26 15:09:48 -04:00
Brad King
7ba3a3290f try_compile: Refactor positional arg parsing 2022-07-26 14:44:42 -04:00
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