[CMake] CONFIGURE_FILE and ADD_DEPENDENCIES

Rupert Brooks rupert.brooks at gmail.com
Fri Mar 26 11:00:32 EDT 2010


I will now answer my own question.  The ADD_CUSTOM_COMMAND way works
BUT one must be sure to get the OUTPUT, and the named file on the
ADD_LIBRARY line
exactly the same.

or, said the other way, i made a bonehead typo in my CMakeLists.txt

Sorry for the noise,

Rupert
--------------------------------------------------------------
Rupert Brooks
rupert.brooks at gmail.com




On Fri, Mar 26, 2010 at 10:51, Rupert Brooks <rupert.brooks at gmail.com> wrote:
> Hi,
>
> In my build i have a .cpp file (actually many) which is generated from
> a template using a cmake configure file command.
>
> I tried using CONFIGURE_FILE in the CMakeLists.txt, and this works,
> but if the template is changed, or the .cpp file gets removed, then
> the file will not be regenerated unless i rerun cmake manually.  Make
> will stop with the usual
>
> 'no rule to make file.... needed by...
>
> The cmake code was like so:
>
> CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/force_template.in
>
> ${CMAKE_CURRENT_BINARY_DIR}/template_declarations/${file_name})
>
>
> I then tried using ADD_CUSTOM_COMMAND, but then on the first build, it
> cant add the cpp file to the target it is used in because it doesnt
> exist
> yet.  I had hoped that it would know that it was already a custom
> target, so that at build time it has a rule to build it when needed,
> but this didnt
> work.
>
> CMake code like this
>
>                ADD_CUSTOM_COMMAND(OUTPUT
> ${CMAKE_CURRENT_BINARY_DIR}/template_declarations/${file_name}
>                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
> ${CMAKE_CURRENT_SOURCE_DIR}/force_template.in
>                  COMMAND ${CMAKE_COMMAND}
>                  ARGS -Dfile_name=${file_name}
> -Dinclude_name=${include_name} -E
>
> "CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/force_template.in
>
> ${CMAKE_CURRENT_BINARY_DIR}/template_declarations/${file_name})"
>                              )
>
> ....later
>
> ADD_LIBRARY(wonderfullibrary
> ${CMAKE_CURRENT_BINARY_DIR}/template_declarations/${file_name})" ...)
>
> I get this error
>
>  Cannot find source file "force[...].cpp".
>  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
>  .hxx .in .txx
>
>
> I guess i could do add custom target AND configure file.. but this is
> starting to seem like i am really doing this the wrong way somehow.
> Also,
> I have seen other macros where it looks like ADD_CUSTOM_COMMAND should
> do the job... not sure what i am doing wrong.
>
> Whats the _right_ way to add a script generated .cpp file to a build?
> Is this the right way and i just have a bug, or am i totally going
> about it wrongly.
>
> Thanks
>
> Rupert
> --------------------------------------------------------------
> Rupert Brooks
> rupert.brooks at gmail.com
>


More information about the CMake mailing list