Commit Graph

128 Commits

Author SHA1 Message Date
AJIOB
2b2344b412 MSVC: Add abstraction for runtime checks
Replace our hard-coded default for `/RTC1` with a first-class
abstraction to select runtime checks from an enumeration of logical
names.  Add a `MSVC_RUNTIME_CHECKS` target property and corresponding
`CMAKE_MSVC_RUNTIME_CHECKS` variable.

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

Fixes: #26614
2025-01-29 13:07:41 -05:00
Rüdiger Ihle
09a47c7972 MSVC: Restore support for non-incremental linking with v100 toolset and older
Since commit 0b552eb877 (MSVC: Embed manifests directly for
non-incremental vs_link_exe links, 2023-02-20, v3.27.0-rc1~438^2) we use
`/MANIFEST:EMBED`, but that is not supported by older MSVC linkers.
Restore use of the standalone manifest tool.

Update `Tests/MSManifest` to recognize `dpiAwareness` in the manifest
content as written by MSVC v100 tooling.

Fixes: #26179
2024-09-03 10:58:28 -04:00
Marc Chevrier
1e35163ae8 WHOLE_ARCHIVE link feature: rely now on linker configuration
Fixes: #26019
2024-07-22 16:58:51 +02:00
Marc Chevrier
c1c4cf9545 Linker configuration: introduce a new architecture
A new set of files are dedicated to linker configuration.
This set of files enable a fine-tuned configuration based of the linker
type as identified during compiler detection.

Fixes: #25360
2024-07-20 19:05:54 +02:00
moyo1997
b2a2865205 MSVC: Remove outdated preprocessor flags for targeting ARM64EC
Remove `/DAMD64` and `/DARM64EC` flags added by commit 4ea3a88625 (MSVC:
Add support for targeting ARM64EC, 2020-12-30, v3.20.0-rc1~121^2) that
are not longer expected.
2024-07-09 14:21:21 -04:00
Marc Chevrier
576567f028 Link feature attributes: stabilization
* enhance OVERRIDE handling
* Update wording
2024-06-21 11:18:20 +02:00
Marc Chevrier
5617c34c31 Libraries processing: update configuration wording 2024-06-21 11:18:12 +02:00
Marc Chevrier
6e5e7968c3 GenEx $<LINK_LIBRARY>: Add the support of properties attached to features
Fixes: #24504, #25954
2024-05-15 10:02:36 +02:00
Brad King
3f5cd0389f IntelLLVM: Fix link flags with Visual Studio generators
The link flag wrapping added by commit 5d5a712303 (IntelLLVM: Pass
linker flags to the compiler when used as linker, 2022-05-27,
v3.25.0-rc1~344^2~4) is not needed with Visual Studio generators because
MSBuild invokes the linker directly.  Furthermore, that commit omitted
wrapping of the per-config linker flags.

Revise the logic to add the link flag wrapping more precisely.

Fixes: #25533
2024-04-02 12:54:01 -04:00
Marc Chevrier
7b99c42e57 Link step: Enable to configure deduplication of libraries
Some platforms, Apple or Windows for instance, do not require to duplicate
static libraries to resolve mutual dependencies. Moreover, Xcode version 15
emits a warning if a library is duplicated.
On Windows, enable a better control of libraries order.

Fixes: #20722, #25297
2023-11-09 19:20:40 +01:00
Marc Chevrier
96a953b1ed Add options to specify linker tool
Offer the capability, through variable `CMAKE_LINKER_TYPE`, as well as
the target property `LINKER_TYPE` to specify which linker must be used.

The implementation of this capability is specified by variables specific
to the language and linker type: `CMAKE_<LANG>_USING_LINKER_<TYPE>`.
Some definitions are provided as part of `CMake`.

For example, to select the `LLVM` linker rather than the standard one,
the type `LLD` should be specified through the variable `CMAKE_LINKER_TYPE`.
And, on `Apple`, `Linux` and some environments on `Windows`, the variable
`CMAKE_<LANG>_USING_LINKER_LLD` has value `-fuse-ld=lld`. And for `Windows`
environments  based on `MSVC`, where the linker is used directly, the tool
`lld-link.exe` will be used rather than `link.exe`.

Fixes: #19174, #24254, #24990
2023-10-13 11:52:35 +02:00
Kyle Edwards
b01f5eb079 Windows: Add experimental WindowsKernelModeDriver platform 2023-07-17 16:54:10 -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
Brad King
7d73e88d3a MSVC: Revert "Default to -ZI instead of /Zi for x86 and x64"
Revert commit 5fcadc481e (MSVC: Default to -ZI instead of /Zi for x86
and x64, 2022-05-24).  The `-ZI` flag is incompatible with the `-GL`
flag used for IPO, and so is not an unconditionally better default.
Revert the change pending future design of a first-class setting for
MSVC debug info format that can be automatically reconciled with IPO
settings.

That commit introduced policy CMP0138, but we already have later policy
numbers used too.  Leave placeholder text to avoid policy renumbering.

Issue: #23607, #10189
2022-06-09 12:24:33 -04:00
Glen Chung
5fcadc481e MSVC: Default to -ZI instead of /Zi for x86 and x64
Add a policy for compatibility.

For more information, see [1].

[1] https://docs.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format?view=msvc-170

Fixes: #10189
2022-05-26 09:06:01 -04:00
Marc Chevrier
dabe56de58 genex-LINK_LIBRARY: Add feature WHOLE_ARCHIVE 2022-03-17 23:07:59 +01:00
Brad King
7b1099a52f Merge topic 'cmcldeps-cross'
d49e168e1b Ninja: Do not use cmcldeps for RC on non-Windows hosts

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Dmitry Mikushin <dmitry@kernelgen.org>
Merge-request: !6843
2022-01-07 09:43:39 -05:00
Martin Storsjö
d49e168e1b Ninja: Do not use cmcldeps for RC on non-Windows hosts
The `cmcldeps` executable is only built on Windows.  If running MSVC on
a different OS (with various compatibility wrapping), don't try to use
`cmcldeps`, as the executable doesn't exist.

Fixes: #21760
2022-01-06 15:42:45 -05:00
moyo1997
26f52508f2 MSVC: update arm64ec default flags and lib
Update the support added by commit 4ea3a88625 (MSVC: Add support for
targeting ARM64EC, 2020-12-30, v3.20.0-rc1~121^2).

Add `softintrin.lib` to `CMAKE_C_STANDARD_LIBRARIES_INIT`.

Remove `/D_ARM64EC_WORKAROUND` from the flags as it was only ever needed
in preview versions of VS.

Issue: #21724
2022-01-06 15:31:32 -05:00
Brad King
f01ea7e391 MSVC: Fix MSVC_TOOLSET_VERSION for VS 2022 v143 toolset
This was forgotten in commit 0c7f918fb1 (VS: Update Visual Studio 17
2022 generator for Preview 2, 2021-07-14, v3.21.1~29^2) when the toolset
was first renumbered to `v143`.

Fixes: #22585
2021-09-02 13:47:42 -04:00
Raul Tambre
56c759b000 Per-language Win32/Console flags
Allows using different compilers with different flags for different languages.
For example Clang with GNU-like commandline for CXX and MSVC as host compiler
for CUDA.

Should help with #21914.
2021-03-17 17:51:56 +02:00
Moyo Okeremi 😊
4ea3a88625 MSVC: Add support for targeting ARM64EC 2021-01-20 16:43:35 -08:00
Marc Chevrier
f8d8faff8d Ninja Generators: Homogenize configuration with Makefiles
* Use same configuration variables to configure dependencies
* Abstract Ninja deps format from compiler one
2020-12-01 15:50:01 +01:00
Marc Chevrier
2c71d051fa Makefiles Generators: use compiler for dependencies generation
Each source compilation generates a dependencies file. These dependencies
files are consolidated in one file per target. This consolidation is done
as part of command 'cmake -E cmake_depends` launched before evaluation of
makefile dependency graph.

The consolidation uses the same approach as `CMake` dependencies management.

Fixes: #21321
2020-11-29 15:25:42 +01:00
Brad King
c00a6d3967 MSVC: Do not add /GR to CMAKE_CXX_FLAGS by default
The `/GR` flag has been on by default since MSVC cl 14.0 from VS 2005.
Remove it from the default flags to make it easier for projects to pass
`/GR-` themselves to turn it off.

Projects may be using string processing to replace `/GR` with another
flag, so we cannot simply drop it.  Add a policy to drop it in a
compatible way.

Fixes: #21428
2020-11-13 11:46:23 -05:00
Brad King
6114c8e994 MSVC: Factor out initialization of /GR flag 2020-11-13 10:50:25 -05:00
Thomas Bernard
cf83758b24 Clang: Implement CMAKE_${LANG}_COMPILER_TARGET for all variants on windows
Fixes: #21097
2020-09-11 09:05:03 -04:00
Brad King
7b083d59c2 clang-cl: Restore rules to create preprocessed and assembly output
In commit d993ebd4ca (clang-cl: Add '--' before source file, 2020-07-28)
we accidentally replaced these rules with those to compile an object
file.
2020-08-19 10:53:48 -04:00
Thomas Bernard
d993ebd4ca clang-cl: Add '--' before source file
On Linux and macOS, absolute paths start with `/` which may be
interpreted by clang-cl as an option.  To avoid this, we separate the
source file path from preceding options with `--` to tell `clang-cl` it
is not an option.
2020-08-07 11:48:48 -04:00
Thomas Bernard
270e0d9c4d Detect the correct target architecture for clang compilers.
During compiler identification, if CMAKE_{C,CXX}_COMPILER_TARGET is
defined, the corresponding clang target flag is used to guaranty proper
target architecture detection.
2020-07-28 19:48:47 +02:00
Brad King
cd89ebdda2 Merge topic 'pch-msvc-pragma'
6c2514dabe MSVC: Use 'pragma system_header' in PCH only on cl 19.13 and above

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4736
2020-05-12 06:52:40 -04:00
Brad King
6c2514dabe MSVC: Use 'pragma system_header' in PCH only on cl 19.13 and above
VS 2017 15.6 introduced support for this pragma.  Older MSVC versions
warn that it is unknown.

Fixes: #20692
2020-05-11 13:31:15 -04:00
Francisco Facioni
55196a1440 MSVC: Use 'lib' instead of 'link /lib' to create static libraries
`link.exe /lib` is an undocumented flag and it just calls `lib.exe`.
Also `link.exe` doesn't parse the `/lib` option correctly when in a
response file.
2020-03-03 08:31:13 -05:00
shibayan
ea882b4aa9 MSVC: Fixed missing import library for Windows 10 ARM64 (Desktop)
Add the same import library as x86/x64 by default for Windows 10 ARM64 (Desktop, not UWP).

Fixes: #20077
2019-12-11 02:40:46 +09:00
Cristian Adam
729d997f10 Precompile Headers: Add REUSE_FROM signature
Add the ability to share precompiled headers artifacts between
targets.

Fixes: #19659
2019-09-17 11:58:38 +02:00
Cristian Adam
b8626261e9 Precompile headers: Add methods to generate PCH sources
Co-Author: Daniel Pfeifer <daniel@pfeifer-mail.de>
2019-08-28 11:47:40 -04:00
Marc-André Moreau
fd28e24947 Windows-MSVC.cmake: fix disabling of CMAKE_NINJA_CMCLDEPS_RC 2019-05-30 13:11:34 -04:00
Kitware Robot
932dcce1e6 Modules: Consistently use 2 space indentation 2019-05-14 15:26:46 -04:00
Brad King
1baf122cd4 MSVC: Do not add /W3 to CMAKE_<LANG>_FLAGS by default
We do not add default warning flags on other compilers, and having
a warning flag in the default flags makes it hard for projects to
customize the warning level.  They need to use string processing
to remove `/W3` from `CMAKE_{C,CXX}_FLAGS`.  Therefore we should
drop it.

However, projects may be using string processing to replace `/W3`
with another flag, so we cannot simply drop it.  Add a policy to
drop it in a compatible way.

Fixes: #18317
2019-04-19 12:56:49 -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
5c1ead795d Merge topic 'vs2019-redist'
33ee779330 IRSL: Fix discovery of VS 2019 v142 toolset redistributables
d8cf8380fb MSVC: Fix MSVC_TOOLSET_VERSION for VS 2019 v142 toolset

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3186
2019-04-04 11:43:18 -04:00
Brad King
d8cf8380fb MSVC: Fix MSVC_TOOLSET_VERSION for VS 2019 v142 toolset
This was forgotten in commit 626c51f47b (VS: Update for Visual Studio
2019 Preview 2, 2019-01-24, v3.14.0-rc1~74^2) when the toolset was
first renumbered to `v142`.

Issue: #19125
2019-04-03 12:27:29 -04:00
Zsolt Parragi
e53a968ed5 MSVC: Use -D instead of /D in RC_FLAGS
llvm-rc can't handle definitions given with /D and without a space.
2019-03-01 14:11:01 +01:00
Mateusz Zych
bd9bfc6449 MSVC: Respect CMAKE_RC_COMPILER and CMAKE_MT in vs_link_{dll,exe}
CMake commands vs_link_dll and vs_link_exe, performing linking on MSVC,
are responsible for calling resource compiler and manifest tool.

Before this commit, both of these tools were called directly, with the
expectation that they are available in the `PATH`. This has been fixed
by respecting CMake variables `CMAKE_RC_COMPILER` and `CMAKE_MT`
defining paths to these tools.

Fixes: #17804
2018-10-29 13:40:47 -04:00
Brad King
02f566a559 MSVC: Factor out enable_language(RC) call into helper macro
This will be useful to call from elsewhere later.
2018-10-29 13:40:47 -04:00
Arkady Shapkin
304f493e57 MSVC: Add MSVC_TOOLSET_VERSION variable
Provide the MSVC toolset version number based on the compiler version.

Fixes: #16923
2018-04-04 13:21:09 -04:00
xoviat
a18147e933 MSVC,Clang,Flang: Add IPO support
Fixes: #17692
2018-02-23 10:27:57 -05:00
Brad King
3bc21a70b5 MSVC: Fix MSVC_VERSION when mixing MSVC C/C++ with Intel Fortran
When using a real MSVC compiler for `C` or `CXX`, use the version of
that compiler for `MSVC_VERSION`.  This is preferred over the MSVC
version that a non-MSVC compiler "simulates".

Fixes: #17468
2017-11-15 14:58:44 -05:00
Brad King
7315a46c83 Merge topic 'MsvcArm64'
bc7c94fe MSVC: Add support for ARM64 architecture

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1215
2017-09-13 08:37:02 -04:00
Minmin Gong
bc7c94fe13 MSVC: Add support for ARM64 architecture
Visual Studio 15.4 adds support for this architecture.

Fixes: #17213
2017-09-12 09:54:29 -04:00