[cmake-developers] Listing source-tree files encountered

Stephen Kelly steveire at gmail.com
Tue Jul 21 14:50:57 EDT 2015


Clifford Yapp wrote:

> With David's patch and the above SOURCE_DIR property, it looks like
> the necessary pieces are now present for target + source processing.

That might happen to work for brlcad, but it is not really true. 

CMake looks in the source dir for relative files listed in targets, then the 
binary dir, then it tries a number of language-specific extensions in each 
of the source and binary directories. 

And it does that at generate-time after evaluating generator expressions. 

And the file extensions it uses as candidates are determined by cmake 
variables that the user can modify.

 http://www.cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmSourceFile.cxx;h=86f0a7a8;hb=HEAD#l138

So, your cmake function will fail on a target like

 add_executable(hello
   # main.cpp exists
   main 
   # Exists in source dir
   foo.cpp 
   # Exists in build dir
   generated_file.cpp 
   # bar.c exists in source dir
   bar 
   # another_generated_file.h exists in build dir
   another_generated_file 
   # determined_at_generate_time.cpp exists in source dir
   $<1:determined_at_generate_time>
 )

Why not add a generator expression like $<TARGET_SOURCES:tgt> and use that 
instead? You can implement/define that as creating absolute paths.

Thanks,

Steve.




More information about the cmake-developers mailing list