[CMake] Difference in CMake 2.8 / 3.1+ behaviour when looking at SOURCES property

Brad King brad.king at kitware.com
Tue Jul 21 11:07:19 EDT 2015


On 07/20/2015 03:45 PM, Berteun Damman wrote:
> Note that it displays the full path for foo.txt! With later CMake
> versions (3.1 and up is my suspicion), it will display:
> 
> build$ cmake ..
> foo.cc
> foo.txt
> 
> I tried looking trough the release notes, and I've found that
> add_library gained support for generator expressions in 3.1, but I
> haven't found any explicit mention that would explain this behaviour.

It was likely changed as part of the topics merged here:

 Merge topic 'target-transitive-sources'
 http://cmake.org/gitweb?p=cmake.git;a=commit;h=5376151a

 Merge topic 'target-sources-refactor'
 http://cmake.org/gitweb?p=cmake.git;a=commit;h=93054aa8

I've added the author to Cc.

> Does anyone know why it changed?

The full path to sources is now determined at generate time to
accommodate generator expressions.  Unfortunately this incompatibility
was not noticed during development or the 6 weeks of 3.1 release
candidates posted for testing.  Now we've had 3 releases with the new
behavior so trying to change it now will just become incompatible for
projects expecting the current behavior.  Technically the documentation
in CMake 3.0 and below guaranteed only that the list returned is suitable
for passing to set_source_files_properties, which it still is.

> And secondly, is there a way to get the 2.8 behaviour back?

Not currently, though you can compute the source file locations
yourself if you know the source/build directories corresponding
to the CMakeLists.txt where the target is defined.  There is discussion
recently about exposing more information for that here:

 Listing source-tree files encountered
 http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/13676/focus=13734

> So the more general question is, is there a canonical way to get the
> full path to a source file by looking at the SOURCES of a target?

It is not possible to get this information at configure time because
full paths are not determined until generate time (since 3.1).  Of
course if you list the .txt files in your add_library calls with
${CMAKE_CURRENT_SOURCE_DIR}/foo.txt then it will be a full path when
collected back from SOURCES later.

-Brad



More information about the CMake mailing list