[CMake] FILE command and generating files.

Brad King brad.king at kitware.com
Tue Apr 5 08:31:48 EDT 2005


Tanner Lovelace wrote:
> I'm trying to generate a file using a program that takes a list
> of files (a header file and some source files) as input.
> I tried doing this:
> 
> # Get full paths to the input files and put them into tmp.txt
> FILE(WRITE tmp.txt "${PROJ_SOURCE_DIR}/include/msgs.h")
> FOREACH(c_file ${STATIC_SRCS} ${BASE_SRCS})
>   FILE(APPEND tmp.txt "${CMAKE_CURRENT_SOURCE_DIR}/${c_file}")
> ENDFOREACH(c_file)
> ADD_CUSTOM_COMMAND(output.txt ALL
>   ${CMAKE_BINARY_DIR}/bin/command -f tmp.txt)
> 
> My problem, however, is that the file commands don't seem to
> do anything at all.  Do I need to add them to a custom command
> or perhaps make a .cmake file that gets executed by the makefile?

It is writing a tmp.txt into the source tree next to the CMakeLists.txt 
file.  You need to specify the full path:

FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/tmp.txt ....)

Also it looks like the ADD_CUSTOM_COMMAND should be ADD_CUSTOM_TARGET.

> Also, is there a better way to get full paths to the files?  The
> source varables are defined like this:
> 
> SET(STATIC_SRCS
> file1.c
> file2.c
> win32/file3.c
> [...etc...]
> )
> 
> So I can pass them directly into the library target I'm
> also creating in this directory.  However, I couldn't think
> of an easy way to transform that into full paths to the files.

${CMAKE_CURRENT_SOURCE_DIR}/${c_file} should produce a full path.  What 
do you want to happen differently?

-Brad


More information about the CMake mailing list