[CMake] Possible inconsistent behavior in target_sources() and CMake 3.14

Michele Rosso mrosso at lbl.gov
Tue Apr 2 19:58:56 EDT 2019


Hello,
according to the doc for CMake 3.14, target_sources() interprets relative
source file paths as being relative to the current source directory, i.e.
it should
prepend CMAKE_CURRENT_SOURCE_DIR to the relative paths given by the user.
However, this is not the case if the target and the sources are defined in
the same directory.
I attached a simple example to reproduce the issue. The structure of the
example is as follows:

- cmake-bug/
     - CMakeLists.txt
     - main.cpp
     - foo/
        - CMakeLists.txt
        - foo.H
        - foo.cpp
     - bar/
        - CMakeLists.txt
        - bar.H
        - bar.cpp

Target "main.exe" is defined in the top-level CMakeLists.txt, while its
headers and sources are located in the the top-level directory
and in the sub-directories 'foo' and 'bar'.
After target_sources is used to include all the headers and sources, I
retrieve the "SOURCES" property for  `main.exe`: all the sources and headers
but  `main.cpp` are given the correct (absolute) path.

Is this the intended behavior? If so, why should a source file located in
the same directory where the target is defined be treated any differently?

Thanks,
Michele
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190402/032b3c6e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmake-bug.tar.gz
Type: application/gzip
Size: 829 bytes
Desc: not available
URL: <https://cmake.org/pipermail/cmake/attachments/20190402/032b3c6e/attachment.gz>


More information about the CMake mailing list