CMake/Help/policy/CMP0187.rst
Evan Wilde 321c647640 Include source file without an extension after the same name with an extension
CMP0115 requires that source files listed in CMake must include their
file extension, but there are cases when projects have different source
files with the same name, but one with an extension and one without.
In the current state, CMake will ignore the file without the extension
an always map it to the file with an extension.

```cmake
add_library(foo bar.c bar)
```

In the above example, the target `foo` will only recognize and depend on
`bar.c` and miss the file `bar` unless `bar` comes before `bar.c` in the
source list.
This issue also affects how custom commands emit files.

This change adds a new policy to recognize files with and without a file
extension as different files, both when building targets, and when they
are being created.

Fixes: #26058
2025-02-14 10:01:10 -05:00

34 lines
1.1 KiB
ReStructuredText

CMP0187
-------
.. versionadded:: 4.1
Include source file without an extension after the same name with an extension.
In CMake 4.0 and below, if two source files have the same filename and only one
file has a file extension and the file with the extension is listed first, the
file without the extension is omitted from the target.
For example, the following library target only include ``hello.c`` in the
target, but omits the file ``hello``.
.. code-block:: cmake
add_library(library hello.c hello)
If the file without the extension is listed before the file with the extension,
both files are included in the target.
Starting in CMake 4.1, CMake includes both files in the library target.
This policy has no effect if :policy:`CMP0115` uses the ``OLD`` behavior.
The ``OLD`` behavior for this policy is to omit the file without the extension.
The ``NEW`` behavior for this policy is to include it.
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 4.1
.. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
.. include:: STANDARD_ADVICE.txt
.. include:: DEPRECATED.txt