[CMake] Passing back list of files from Function

Alexander Neundorf a.neundorf-work at gmx.net
Fri May 11 15:40:59 EDT 2012


On Friday 11 May 2012, Michael Jackson wrote:
> I have a function where I am generating a number of files and I need to
> pass that list of files back to the original calling cmake
> command/file/scope. How would I go about that?
> 
> 
> 
> function(create_files)
>   set(options)
>   set(multiValueArgs GENERATED_HEADERS)
>   cmake_parse_arguments( WIG "${options}" "${oneValueArgs}"
> "${multiValueArgs}" ${ARGN} )
> 
>   foreach (....)
>      .. Generate some files
> 
>   endforeach()
> 
> 
> ??
> 
> endfunction()
> 
> 
> set(headers "")
> create_files (GENERATED_HEADERS headers)
> 
> 
> Could someone help me fill in the blanks? Thanks

Give the name of a variable to create_files() which will be used to return the 
values:

function(create_files)
  set(options)
  set(multiValueArgs GENERATED_HEADERS)
  cmake_parse_arguments( WIG "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )
 
  foreach (....)
     .. Generate some files

  endforeach()

  # the following line sets generatedFiles to file[123].x
  set(${outVar} file1.x file2.x file3.x PARENT_SCOPE)

endfunction()

 
 
set(headers foo.h bar.h blub.h)
set(generatedFiles )
create_files (GENERATED_HEADERS INFILES ${headers} OUTVAR generatedFiles)

Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120511/5cb9a6d0/attachment-0001.htm>


More information about the CMake mailing list