Commit Graph

1396 Commits

Author SHA1 Message Date
Cristiano Carvalheiro
a46491d0d3 cmLocalGenerator: Improve performance of source group lookups
Introduce an index from source file to source group in
`cmLocalGenerator` to make lookups significantly more efficient
during the source group generation, which could be particularly
slow when dealing with thousands of source files.
Falls back to the recursive lookup when the source file is not present
on the index, which is more likely to happen when dealing with
regex-based sources.

Fixes: #27359
2025-11-26 20:32:19 +00:00
Cristiano Carvalheiro
caf6e782e1 cmSourceGroup: Move FindSourceGroup out of cmMakefile 2025-11-26 18:16:05 +00:00
HannaWAR
2628c52e04 source_group: add genex support
Fixes: #19813
2025-11-24 21:08:46 +03:00
Brad King
8832f78dd6 IWYU: Update for Debian 13 CI job
`include-what-you-use` diagnostics, in practice, are specific to
the environment's compiler and standard library.  Update includes
to satisfy IWYU for our CI job under Debian 13.  Some patterns:

* Types named in virtual `override` signatures no longer require
  includes since the overridden signature already names them.

* A function argument's type needs to be included even if its constructor
  is called only by implicit conversion.  For example, constructing a
  `std::function` from a lambda now requires `<functional>`.

* Some prior mysterious `<type_traits>` inclusions are no longer required.
2025-11-12 14:54:35 -05:00
AJIOB
6874efb592 MSVC: Always define a character set
When targeting the MSVC ABI, define `_MBCS` by default if the project
does not define `_SBCS` or `_UNICODE`.  Visual Studio has long defined
one of the three character set macros automatically.  For consistency,
define it when compiling for the MSVC ABI with other generators.
Add policy CMP0204 for compatibility.

Fixes: #27275
2025-10-07 09:29:32 -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
Eduard Voronkin
23fd5703ad FASTBuild: add support for Unity builds 2025-09-18 09:40:55 -07:00
Ben Boeckel
b2ebfd7709 shortobj: properly force long names when computing long names
The arguments need to be able to force a long name computation so that
install paths can use the intended long paths. Use this computed state
rather than asking the generator for its base state.

Also force long paths for Visual Studio generators when computing it.

Fixes: #27233
2025-09-17 14:36:29 -04:00
Ben Boeckel
b53837a1bd prop_sf/INSTALL_OBJECT_NAME: support custom install object names
These can support configuration-dependent queries much more easily, so
separate it out.
2025-09-09 09:58:07 -04:00
Ben Boeckel
08f1a0fbc6 cmLocalGenerator: get the configuration when building object paths
Install locations can be per-configuration, so this information is
necessary for this call. Plumb it through; usage will follow in the next
commit.
2025-09-09 09:58:07 -04:00
Ben Boeckel
84372ce0b5 prop_sf/OBJECT_NAME: no-op for the FASTBuild and Xcode generators
There's no control over the object base name implemented in the
FASTBuild generator. Rather than expecting some half-supported behavior,
just ignore it completely there.

Similarly, Xcode ends up making its own object paths internally
regardless of what CMake would like.
2025-09-09 09:58:07 -04:00
Ben Boeckel
9ef99353cb prop_sf/OBJECT_NAME: support custom object names
Projects which ship object files as artifacts may want to control the
object names as much as possible. Support setting explicit object names
as source file properties to support such use cases.
2025-09-09 09:58:07 -04:00
Ben Boeckel
7aff0d37b5 cmSourceFile: add accessors for PCH source files
`cmLocalGenerator::GetObjectFileNameWithoutTarget` used a heuristic to
detect PCH sources. Use the new special source types to detect them
reliably instead.
2025-09-08 11:59:57 -04:00
Ben Boeckel
bbdc2fd908 cmSourceFile: internally track CMake-managed source files
These source file types don't necessarily show up in the CMake code, but
are side effects of other behaviors in CMake. Support tracking them
specially so that heuristics are not required to figure out if a given
`cmSourceFile` is one of them.
2025-09-08 11:59:57 -04:00
Ben Boeckel
99d48a842d cmLocalGenerator: fix comment typo 2025-09-08 11:59:56 -04:00
Brad King
032b091c3e Merge topic 'unity-filename-prefix'
5723e65215 Unity: Add a target property to control generated filenames

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !11068
2025-09-05 09:18:26 -04:00
Stephen Kennedy
5723e65215 Unity: Add a target property to control generated filenames
If not set default to `unity_` as before.

Closes: #26927
2025-09-04 09:31:01 -04:00
Ben Boeckel
fe0163cd23 autogen: compute short directories too
Not just short directory roots. The test suites did an improper
generator check and masked them as the generator masks were put in place
after the core development but before the autogen-specific logic tests
were created.
2025-09-02 12:56:23 -04:00
Brad King
3af621006d Merge topic 'var-check-before-usage'
d614e8fb3f cmLocalGenerator: check variables before usage

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !11127
2025-09-02 09:42:42 -04:00
Marc Chevrier
d614e8fb3f cmLocalGenerator: check variables before usage
Reported by https://pvs-studio.com/en/blog/posts/cpp/1277/ (N2)

Issue: 27159
2025-08-29 18:47:28 +02:00
Eduard Voronkin
01147454e7 FASTBuild: Add generator
Fixes: #15294
2025-08-26 14:29:01 -07:00
Brad King
9062fc9c16 Merge topic 'install-object-name-strategy'
c651b0e002 objects: implement installation naming strategies
29c7f19280 cmTarget: add the `INSTALL_OBJECT_NAME_STRATEGY` property
757c40c478 cmObjectLocation: add a class to track object locations

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11046
2025-08-18 09:45:19 -04:00
Ben Boeckel
c651b0e002 objects: implement installation naming strategies 2025-08-16 09:18:44 -04:00
Ben Boeckel
390c473652 pchreuse: remove MSVC 2008-or-older condition
Testing locally, `.idb` files are *not* made unconditionally with v71 at
least. Perhaps v90 is an outlier?

In any case, the typo introduced in 1f791eb160 (Multi-Ninja: Fix
reusable PCHs for MSVC, 2020-05-24) via !4787 (see
`cmLocalGenerator.cxx:2751` for extra space inside the quotes) was
preserved when fixing `IS_NEWER_THAN` logic in 28501fca94 (PCH PDB: Fix
misuse of IS_NEWER_THAN in timestamp check, 2021-02-21) from !5825. The
typo itself was fixed in cb46c4a918 (cmLocalGenerator: fix quoting in
generated script, 2025-06-16) via !10887 but the condition was fumbled
later in that MR's commit f78f592b78 (pchreuse: defer target existence
enforcement to generation time, 2025-06-16) in constructing `to_file`
for the script.

In the end, these typos ended up making the builds pass. In fixing it
properly in the parent commit, it exposed MSVC v71 as an outlier in
passing the tests again. Since I do not see `.idb` files with the
toolchain as tested in CI, further investigation into the build that
caused the condition to be added in the first place is required. In the
meantime, removing this check makes things happy as far as CMake's own
test suite is concerned.
2025-08-11 00:05:23 -04:00
Eduard Voronkin
f0d8606267 cmLocalGenerator: fix destination path construction for PCH/PDB copying 2025-08-11 00:03:17 -04:00
Ben Boeckel
8180ecad9b autogen: support the SHORT intermediate dir strategy 2025-07-29 09:44:03 -04:00
John Parent
526a6f2a81 cmGeneratorTarget: shorten PCH filenames 2025-07-29 08:06:29 -04:00
John Parent
1feb801463 cmLocalGenerator: support shortening object filenames 2025-07-29 08:06:29 -04:00
John Parent
76f01de30e cmLocalGenerator: add a GetRelativeSourceFileName method
This will be used for short object path support.
2025-07-29 08:06:29 -04:00
Ben Boeckel
02b2153d84 cmGlobalGenerator: add a query to represent support for short object names 2025-07-28 12:01:28 -04:00
Ben Boeckel
cf1a17861b cmLocalGenerator: add <CMAKE_{BINARY,SOURCE}_DIR> expanders 2025-07-28 12:01:27 -04:00
Ben Boeckel
f78f592b78 pchreuse: defer target existence enforcement to generation time
Now that generation can work with any way the state gets to the way it
is, just do the target enforcement at generation time. This allows PCH
reuse targets to be declared before or after targets which use them.

Also update `cmLocalGenerator` to use the methods now that they reliably
provide values rather than parallel construction.
2025-07-22 12:42:57 -04:00
Ben Boeckel
99bdf2ae16 cmLocalGenerator: add PDB copying dependency on its script 2025-07-22 12:42:57 -04:00
Ben Boeckel
d3849f9de1 cmLocalGenerator: add a useful comment for the PDB copying command 2025-07-22 12:42:57 -04:00
Ben Boeckel
cb46c4a918 cmLocalGenerator: fix quoting in generated script 2025-07-22 12:42:57 -04:00
Brad King
d592558b8b cmLocalGenerator: Drop no-op link flag placeholder infrastructure
Revert infrastructure from commit 8bcf9c7a3e (Add support of "LINKER:"
prefix for artifact creation flags, 2024-10-12, v4.0.0-rc1~522^2~1).
It is not needed to populate legacy placeholders with empty strings.
2025-06-10 14:44:57 -04:00
Brad King
951e4d3f62 Ninja,Makefile: Move builtin linker flags to <LINK_FLAGS> placeholder
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 correspond to variables set by our compiler information modules.
Teach the generators to look up these variables and add them to the
existing `<LINK_FLAGS>` placeholder instead.  Substitute the empty
string for the old placeholders.

Issue: #21934
2025-06-10 14:41:58 -04:00
Brad King
6b618c6079 cmLocalGenerator: Clarify MODULE link flags placeholder population
Clarify comments from commit 8bcf9c7a3e (Add support of "LINKER:" prefix
for artifact creation flags, 2024-10-12, v4.0.0-rc1~522^2~1) about
MODULE library creation flags.  Also avoid falling back to EXECUTABLE
flag placeholders for SHARED or MODULE libraries.  I don't think we
ever populate `CMAKE_<LANG>_CREATE_SHARED_{LIBRARY,MODULE}` from the
value of `CMAKE_<LANG>_LINK_EXECUTALBE`.
2025-06-10 08:53:47 -04:00
Brad King
c52a654aa1 cmLocalGenerator: Improve formatting of rule placeholder variable list
Add a trailing comma so `clang-format` does not try to consolidate
lines.  Also move it to an anonymous namespace.
2025-06-10 08:53:47 -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
Ben Boeckel
c95a8348ce cmLocalGenerator: add an override for CMakeFiles-using paths
Visual Studio doesn't use a `CMakeFiles` subdirectory for its support
directories. However, some codepaths expect to use paths which are
always under `CMakeFiles`. Add a mechanism to keep the path for such
files.
2025-05-24 15:28:50 +02:00
Ben Boeckel
35d32b8741 cmLocalGenerator: move the CMakeFiles subdir from the target to output root
When target directories are shortened, the `CMakeFiles` path component
will be part of the root, not the target directory. Since other files
end up constructing paths manually, move the differing component into
the correct logical path construction part.
2025-05-24 15:28:47 +02:00
John Parent
b1d9a5313c cmLocalGenerator: add a GetObjectOutputRoot method
This will allow object locations to be changed in a single place.
2025-05-23 11:39:54 +02:00
Ben Boeckel
b82a74d918 generators: use GetSupportDirectory() in more places 2025-05-23 11:39:53 +02:00
Ben Boeckel
03ed0ff57c cmLocalGenerator: factor out creating a "safe" file path 2025-05-22 17:02:52 +02:00
Ben Boeckel
5374edc8bf cmLocalGenerator: remove unnecessary .c_str() 2025-05-22 16:02:49 +02:00
Ben Boeckel
557c44b93e cmStrCat: use character literals where possible
Found and replaced using the `cmstrcat-to-char-literal` rule for
`ast-grep`.
2025-05-15 19:12:04 +02: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
Marc Chevrier
2e9648e0de Ninja generator: restore correct encoding for policy CMP0181=OLD
Fixes: #26857
2025-04-12 16:37:57 +02:00
Kitware Robot
de273b2e11 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 09:56:07 -05:00