Commit Graph

1531 Commits

Author SHA1 Message Date
Brad King
1925477cb7 macOS: Do not incorrectly search for per-arch SDKs
Extend commit a9b41195d2 (Handle multi-arch sysroots on Apple platforms,
2019-07-26, v3.17.0-rc1~287^2) to recognize versioned macOS SDK names.

Fixes: #27340
2025-10-29 14:50:51 -04:00
Brad King
b39e361175 Merge topic 'xcode-macos-deployment-target' into release-4.2
de53a46a91 Help: Add 4.1 release note for restored Xcode default deployment target
85ba6f5d1b Merge branch 'backport-4.0-xcode-macos-deployment-target'
884260ced6 Help: Add 4.0 release note for restored Xcode default deployment target
1a37c83c7e Xcode: Restore default CMAKE_OSX_DEPLOYMENT_TARGET to run on host
e927408047 Apple: Initialize deployment target after SDK

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11361
2025-10-27 09:26:15 -04:00
Brad King
85ba6f5d1b Merge branch 'backport-4.0-xcode-macos-deployment-target' 2025-10-26 11:19:58 -04:00
Brad King
1a37c83c7e Xcode: Restore default CMAKE_OSX_DEPLOYMENT_TARGET to run on host
Xcode by default targets the SDK's macOS version rather than the host's
macOS version.  In commit 7b19531291 (macOS: Do not pass any
SDK/-isysroot to compilers by default, 2024-11-06, v4.0.0-rc1~511^2) we
reverted commit 24aafbde11 (Xcode: Adjust deployment target SDK version
to host version, 2015-10-11, v3.4.0-rc2~6^2), but it is still needed for
Xcode.  Restore the behavior so binaries run on the host by default.

Fixes: #27309
2025-10-26 11:19:19 -04:00
Brad King
e927408047 Apple: Initialize deployment target after SDK 2025-10-26 11:16:45 -04:00
Eduard Voronkin
4135175337 FASTBuild: support CUDA language
Fixes: #27318
2025-10-25 08:58:38 -04:00
Brad King
61d0bdf6b7 macOS: Avoid relying on sw_vers when cross-compiling from another OS
We have a few code paths needed only to support builds hosted on
macOS 10.4.  Update the conditions to work when cross-compiling
to macOS from another platform.

This backports commit eb8facd396 (macOS: Avoid relying on sw_vers
when cross-compiling from another OS, 2025-04-28, v4.1.0-rc1~260^2)
to CMake 4.0.

Fixes: #26814
2025-10-22 17:26:36 -04:00
Brad King
d9d65ab54f macOS: Remove outdated condition for CMAKE_OSX_DEPLOYMENT_TARGET
Revert commit 2853326e7a (BUG: Only set CMAKE_OSX_DEPLOYMENT_TARGET on
Mac OSX 10.4 or later, 2009-01-27, v2.8.0~1169).  AFAIK no one is using
macOS versions older than 10.4 anymore.

This backports commit 476b2a386f (macOS: Remove outdated condition
for CMAKE_OSX_DEPLOYMENT_TARGET, 2025-04-28, v4.1.0-rc1~260^2~1)
to CMake 4.0.
2025-10-22 17:26:31 -04:00
Tristan Daifuku
69e2f3f8ea Linker: Tolerate CMAKE_EXECUTE_PROCESS_COMMAND_ERROR_IS_FATAL set to ANY
Tolerate expected failures of linkers invoked via `execute_process`.
2025-10-20 11:58:46 -04:00
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
d361bf365e Emscripten: Drop hard-coded -sMAIN_MODULE and -sSIDE_MODULE flags
These flags are only needed for builds involving shared libraries,
and can cause undesirable behavior when they are not needed.
They also have variants with values like `=2`.  For now, just require
projects to add the flags when needed so they have full control.
In the future we may be able to add an abstraction to control them,
and automatically enable them when linking to shared libraries
or creating them.

Fixes: #27232
Issue: #27240
2025-09-19 09:54:02 -04:00
Brad King
707f14d434 Emscripten: Restore support for indirect use of emsdk toolchain file
Extend commit 644ad91e6a (Emscripten: Restore support for emsdk
toolchain file and platform module, 2025-09-17) to support using a
third-party `CMAKE_TOOLCHAIN_FILE` that includes the emsdk-provided
toolchain file.

Issue: #27232
2025-09-19 09:21:33 -04:00
Brad King
792f6989e9 Merge topic 'android-ndk-custom-toolchain'
9266d4817d Android: Allow custom compilers with NDK

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11199
2025-09-18 08:49:55 -04:00
Brad King
f2b2bac85d Emscripten: Detect and identify linker invoked by the compiler driver 2025-09-17 20:03:48 -04:00
Brad King
7f3f6d1ec6 Emscripten: Allow overriding -sMAIN_MODULE and -sSIDE_MODULE linker flags
Place the flag early on executable link lines so that projects can
override it, e.g., with `-sMAIN_MODULE=2` or `-sMAIN_MODULE=0` via
`target_link_options`.

The `-sSIDE_MODULE` flag already appears early enough on shared library
link lines.

Issue: #27232
2025-09-17 19:54:40 -04:00
Brad King
526c6ff6d2 Emscripten: Drop -sMAIN_MODULE and -sSIDE_MODULE with emsdk toolchain file
Emscripten provides a combined toolchain file and platform module that
predates CMake upstream support.  It disables support for shared libs.
Fix commit 96d9b94a98 (Emscripten: Add platform modules, 2025-05-16) to
avoid linking with `-sMAIN_MODULE` or `-sSIDE_MODULE` flags, meant to
support shared libraries, when using the emsdk toolchain file.

Fixes: #27232
2025-09-17 19:53:22 -04:00
Brad King
644ad91e6a Emscripten: Restore support for emsdk toolchain file and platform module
Emscripten provides a combined toolchain file and platform module that
predates CMake upstream support.  Since commit 96d9b94a98 (Emscripten:
Add platform modules, 2025-05-16), our `Platform/Emscripten` module is
included instead, suppressing existing behavior for users that set
`CMAKE_TOOLCHAIN_FILE` to the emsdk-provided toolchain file.  Restore
the previous behavior by teaching our module to defer to the original
module in that case.

Issue: #27232
2025-09-17 19:45:44 -04:00
Brad King
9cbeb922dd Emscripten: Enable de-duplication of libraries for CMP0156 with LLD
LLD automatically resolves newly encountered symbols using object files
previously encountered.  Also, the Emscripten compiler driver invokes
the LLD linker with `--whole-archive ... --no-whole-archive` around all
the libraries.  Therefore we should not repeat any.

Issue: #27232
Suggested-by: Marc Chevrier <marc.chevrier@gmail.com>
2025-09-17 19:44:13 -04:00
Brad King
f22d2904e2 Emscripten: Drop unused placeholder from link rule variables
Update commit 96d9b94a98 (Emscripten: Add platform modules, 2025-05-16)
to account for commit 67639002ad (Ninja,Makefile: Drop now-unused
placeholders from link rule variables, 2025-06-09, v4.1.0-rc1~37^2~1).
2025-09-17 19:44:13 -04:00
Brad King
f4da11a5da Emscripten: Select emcc and em++ compilers by default
This was missed by commit 96d9b94a98 (Emscripten: Add platform modules,
2025-05-16).
2025-09-17 19:44:13 -04:00
Brad King
9266d4817d Android: Allow custom compilers with NDK
If the user or toolchain file has already set `CMAKE_{C,CXX}_COMPILER`,
do not override it with the NDK-provided toolchain.

Fixes: #27162
2025-09-17 10:44:47 -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
Brad King
f70a8f890b Merge topic 'aix-clang-compiler-target'
c482a8833a AIX: Fix shared library linking with CMAKE_<LANG>_COMPILER_TARGET

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11113
2025-09-02 10:54:21 -04:00
David Tenty
c482a8833a AIX: Fix shared library linking with CMAKE_<LANG>_COMPILER_TARGET
With Clang, `CMAKE_C_COMPILER_TARGET` adds a `--target=` flag as part of
the `<CMAKE_C_COMPILER>` placeholder, causing the flag to be passed to
our `ExportImportList` script.  Tolerate it.

Fixes: #27167
2025-09-01 14:42:46 -04:00
Eduard Voronkin
01147454e7 FASTBuild: Add generator
Fixes: #15294
2025-08-26 14:29:01 -07:00
Brad King
91b94a392b Merge topic 'link-flags'
e349b471d8 MSVC: Fix regression that links shared libraries with bogus -shared flag

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Michael Grossfeld <michael.grossfeld@amd.com>
Merge-request: !10998
2025-08-02 06:26:20 -04: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
7c3e0d380f Merge topic 'clang-msvc-sysroot'
e06235e568 Clang: Implement CMAKE_SYSROOT for GNU-like front-end targeting MSVC ABI

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10962
2025-07-23 09:27:43 -04:00
Brad King
e06235e568 Clang: Implement CMAKE_SYSROOT for GNU-like front-end targeting MSVC ABI
Fixes: #26084
2025-07-21 15:21:35 -04:00
Peter Kokot
0622cb343e AIX: Drop unnecessary -l from CMAKE_DL_LIBS
The `-lld` linker flag was added from the previous command-line script
that have all values in `CMAKE_DL_LIBS` prepended with `-l`.

On AIX, the `dlopen()` is otherwise in C library (default). But it seems
that also `libld` library was once needed on some versions to have
dynamic loading working.

Sync `CMAKE_DL_LIBS` value style with all other current usages.
2025-07-21 11:34:03 -04:00
Brad King
d4306378b9 Merge topic 'freebsd_linker_variables'
7ae11ea4e7 Platform: Add compiler platform modules for BSDs

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !10919
2025-07-15 10:54:13 -04:00
Undefine
7ae11ea4e7 Platform: Add compiler platform modules for BSDs
These set variables required for CMAKE_LINKER_TYPE to work

Fixes: #27037
2025-07-12 21:36:42 +02:00
Brad King
5cb9891d64 Merge topic 'windows-kernel-mode-driver'
2f5dce1b40 cmExperimental: remove the flag for Windows Kernel Mode Driver support

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10937
2025-07-10 10:30:26 -04:00
Brad King
2f5dce1b40 cmExperimental: remove the flag for Windows Kernel Mode Driver support
Enable setting `CMAKE_SYSTEM_NAME` to `WindowsKernelModeDriver` without
an experimental gate.
2025-07-09 09:54:45 -04:00
Quinn Powell
96d9b94a98 Emscripten: Add platform modules
Issue: #18423
2025-06-17 15:07:45 -04:00
Brad King
feba34c68a Merge topic 'link-flags'
d592558b8b cmLocalGenerator: Drop no-op link flag placeholder infrastructure
67639002ad Ninja,Makefile: Drop now-unused placeholders from link rule variables
951e4d3f62 Ninja,Makefile: Move builtin linker flags to <LINK_FLAGS> placeholder
6b618c6079 cmLocalGenerator: Clarify MODULE link flags placeholder population
c52a654aa1 cmLocalGenerator: Improve formatting of rule placeholder variable list
37cf9941ed UseEcos: Add missing placeholder in rules to link executables
fa61be5bc4 Embarcadero,OpenWatcom: Clear unused flags for creating shared libraries
124e40947c CMakeCommonLanguageInclude: Do not unset MODULE library flags when empty
...

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10869
2025-06-11 10:28:07 -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
929c66c068 Merge topic 'update_nvhpc_visibility_and_pie_flags'
ea6b29a367 NVHPC: Add support for 25.07 no-pie option
8ef90ffc52 NVHPC: Add support for COMPILE_OPTIONS_VISIBILITY

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10867
2025-06-10 09:57:03 -04:00
Brad King
fa61be5bc4 Embarcadero,OpenWatcom: Clear unused flags for creating shared libraries
Clear `CMAKE_SHARED_LIBRARY_CREATE_<LANG>_FLAGS` since no special
link flags are needed to create a DLL with these toolchains.
Our shared library creation rules do not reference the placeholder,
so this variable was never used.  However, we may soon teach the
generators to look it up directly.
2025-06-10 08:53:47 -04:00
Brad King
7b4c87edae ADSP: Do not pass executable link flags when creating a static library
This was done by mistake in commit d090159318 (ENH: add support for the
ADSP toolchains for Blackfin, Shark and TigerShark DSPs, patch from
Raphael Cotty, 2007-07-12, v2.6.0~1446), and preserved in the
generalization by commit e9eabb0dcd (ADSP: Configure compiler in
compiler module, 2022-03-24, v3.24.0-rc1~331^2~1).  Fix both places.
2025-06-09 16:08:33 -04:00
Robert Maynard
ea6b29a367 NVHPC: Add support for 25.07 no-pie option 2025-06-09 14:36:07 -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
f1a80a5581 CUDA: Drop unused link rule variable setting on Windows 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
Brad King
67f86c7db8 Merge topic 'clang-macos-sdk'
bf1bb62e74 macOS: Restore support for LLVM/Clang without explicit CMAKE_OSX_SYSROOT

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10734
2025-05-03 10:02:18 -04:00
Brad King
bf1bb62e74 macOS: Restore support for LLVM/Clang without explicit CMAKE_OSX_SYSROOT
In commit 7b19531291 (macOS: Do not pass any SDK/-isysroot to compilers
by default, 2024-11-06, v4.0.0-rc1~511^2) we broke support for using
upstream LLVM/Clang to build for macOS because the compiler has no
default sysroot.  Handle empty `CMAKE_OSX_SYSROOT` with LLVM/Clang by
falling back to the macOS SDK reported by `xcrun --show-sdk-path` .

Fixes: #26863
2025-05-02 13:49:40 -04:00