[CMake] file(WRITE) versus configure_file

James Bigler jamesbigler at gmail.com
Thu Jun 4 18:07:16 EDT 2009


  if(NOT EXISTS ${dependency_file})
    #message("configuring dependency_file = ${dependency_file}")
    configure_file(
      ${empty_file}
      ${dependency_file} IMMEDIATE)
  endif()
  # Always include this file to force CMake to run again next
  # invocation and rebuild the dependencies.
  #message("including dependency_file = ${dependency_file}")
  include(${dependency_file})

I need to include the dependency file in my CMakeLists.txt file, so that if
the dependency file changes, CMake needs to rerun.  If the file doesn't
exist, I need to create an empty file and include it, so that after the
first build (when the dependency file is finally generated) cmake runs again
to generate new build rules to incorporate the dependencies.

When I originally wrote this script several years ago, I had to use
configure_file, because write_file() wouldn't work.  Since I'm updating the
script, I would like to remove the dependency on calling configure_file with
a blank file (empty file).

James

On Thu, Jun 4, 2009 at 3:58 PM, Eric Noulard <eric.noulard at gmail.com> wrote:

> 2009/6/4 James Bigler <jamesbigler at gmail.com>:
> > Back in the day before file(WRITE) there was write_file().  write_file()
> had
> > the problem that you couldn't use the file as input to CMake, so you had
> to
> > use configure_file.
>
> What do you mean as "input", you mean a source file in
> add_library or add_executable?
>
> > Does file(WRITE) have this same restriction?
>
> Don't know but I guess that now you can:
>
> set_property(SOURCE blah.h PROPERTY GENERATED TRUE)
> or
> set_source_files_properties(blah.h PROPERTIES GENERATED TRUE)
>
> I guess it should work even if blah.h is generated at CMake time.
>
> > I currently use a blank template file for configure_file for one of my
> > projects, and it would be nice to do away with this and just write a
> blank
> > file when I need to.
>
> Could you explain what do you mean by "blank file"?
>
> --
> Erk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090604/b99474f9/attachment-0001.htm>


More information about the CMake mailing list