Commit Graph

142 Commits

Author SHA1 Message Date
AJIOB
83bbde5449 MSVC: Define _WINDLL consistently for shared libraries
Visual Studio defines this automatically for `.dll` targets.
For consistency, define it when compiling for the MSVC ABI
with other generators.  Add policy CMP0203 for compatibility.

Fixes: #27253
2025-09-29 18:26:44 -04:00
Brad King
cd46d8ec84 Merge branch 'backport-vs2026' into vs2026 2025-09-15 11:33:57 -04:00
Brad King
3392b371e2 VS: Add Visual Studio 18 2026 generator
Closes: #27213
2025-09-15 11:31:02 -04:00
Eduard Voronkin
888e9e1081 FASTBuild: fix CMake build with clang-cl
Fixes: #27175
2025-09-04 22:12:37 -07:00
Eduard Voronkin
01147454e7 FASTBuild: Add generator
Fixes: #15294
2025-08-26 14:29:01 -07:00
Brad King
e349b471d8 MSVC: Fix regression that links shared libraries with bogus -shared flag
Clear `CMAKE_SHARED_LIBRARY_CREATE_<LANG>_FLAGS` since no special
link flags are needed to create a DLL with MSVC toolchains.
Our shared library creation rules never referenced that placeholder,
so this variable was never used until commit 951e4d3f62 (Ninja,Makefile:
Move builtin linker flags to <LINK_FLAGS> placeholder, 2025-06-09,
v4.1.0-rc1~37^2~2) taught the generators to look it up directly.

This was not previously noticed because the `-shared` flag
is ignored unless the `-WX` flag enables an error on it.

Fixes: #27106
2025-08-01 12:37:55 -04:00
Brad King
67639002ad Ninja,Makefile: Drop now-unused placeholders from link rule variables
Previously we used separate placeholders for builtin linker flags:

* CMAKE_<LANG>_LINK_FLAGS for EXECUTABLEs
* CMAKE_SHARED_LIBRARY_CREATE_<LANG>_FLAGS for SHARED libraries
* CMAKE_SHARED_MODULE_CREATE_<LANG>_FLAGS for MODULE libraries

These are now always replaced by the empty string, so drop them
from our rule variables.
2025-06-10 14:43:15 -04:00
Brad King
92d6126450 MSVC: Move link -machine flag out of CMAKE_*_LINKER_FLAGS
The `CMAKE_{EXE,SHARED,MODULE,STATIC}_LINKER_FLAGS` variables are
not language-specific, so multiple languages' toolchains may disagree
about if/how to pass the flag through a compiler driver to the linker.
Furthermore, carrying the flag in public-facing variables allows projects
or users to change it even though it is required.  Add policy CMP0197
to remove the flag from the public-facing variables and generate it
automatically instead:

* For command-line generators, add the `-machine:` flag to the
  linker and archiver rule variables.

* For Visual Studio generators, we do not need to explicitly add the
  link `-machine:` flag.  MSBuild automatically adds it, and the new
  behavior actually removes a duplicate we generated previously.

Issue: #21934
2025-06-05 09:16:54 -04:00
Brad King
bb8baacbcc MSVC: Factor out link -machine flag name 2025-06-02 10:26:28 -04:00
Brad King
4c6c7f4d45 MSVC: Move link -subsystem flag handling near and -machine flag handling 2025-06-02 10:26:27 -04:00
Brad King
8b710d8264 Linker: Generate per-language module -DEF: flags on Windows
With IntelLLVM on Windows, we link using the compiler driver.
With MSVC on Windows, we invoke the linker directly.  If we
use both in a single build tree, for separate languages,
the value of `CMAKE_LINK_DEF_FILE_FLAG` conflicts.  Add a
per-language `CMAKE_<LANG>_LINK_DEF_FILE_FLAG` variable to
avoid the conflict.  Preserve the language-agnostic variable
for compatibility with projects that reference it.

Fixes: #26005
2025-05-28 13:48:26 -04:00
Kitware Robot
1772622772 LICENSE: Replace references to Copyright.txt with LICENSE.rst
```
git grep -lz 'Copyright.txt or https://cmake.org/licensing ' |
  while IFS= read -r -d $'\0' f ; do
    sed -i '/Copyright.txt or https:\/\/cmake.org\/licensing / {
              s/Copyright.txt/LICENSE.rst/
            }' "$f" ; done
```
2025-03-03 10:43:35 -05:00
Brad King
3e64c6a56e Merge topic 'msvc-runtime-checks'
2b2344b412 MSVC: Add abstraction for runtime checks
49dcd1ce5d Help: Fix MSVC_DEBUG_INFORMATION_FORMAT description of example
2f8e643d9d CMP0141: Fix documentation copied from CMP0091

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Alex <leha-bot@yandex.ru>
Merge-request: !10214
2025-01-30 08:48:01 -05:00
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
Marc Chevrier
3d2709c1ae Linker configuration: rely now on CMAKE_<LANG>_LINK_MODE variable.
CMake now provides the CMAKE_<LANG>_LINK_MODE variable which specify how
the link step is done. So, the CMAKE_<LANG>_USING_LINKER_MODE variable
is no longer needed.
2025-01-26 14:45:21 +01: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