[CMake] file(WRITE) versus configure_file

Eric Noulard eric.noulard at gmail.com
Fri Jun 5 03:16:01 EDT 2009


2009/6/5 James Bigler <jamesbigler at gmail.com>:
>   if(NOT EXISTS ${dependency_file})
>     #message("configuring dependency_file = ${dependency_file}")
>     configure_file(
>       ${empty_file}
>       ${dependency_file} IMMEDIATE)
>   endif()

The "IMMEDIATE" thing doesn't seem to be document, is it obsolete
or undocumented?

>   # 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.

CMake won't rerun itself on the first run right? You'll have to
1) cmake
2) first build will eventually rerun CMake ?


> 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).

Would
file(WRITE ) ...
+
include(${dependency_file} OPTIONAL)

be working for you ? See the extra OPTIONAL to include.


I'm afraid I cannot answer to your question "theoretically"
CMake developer may.



More information about the CMake mailing list