[CMake] A CMake language peculiarity I have just discovered

Alexander Neundorf a.neundorf-work at gmx.net
Sun Sep 17 04:40:34 EDT 2006


Von: "Alan W. Irwin" <irwin at beluga.phys.uvic.ca>

> I am pleased with the way that CMake normally defaults to writing files
> to the build tree.  This default behaviour encourages users to keep a
> clean, unmolested source tree.
> 
> Thus, I was surprised recently to discover that
> 
> FILE(WRITE filename "message to write"... )
> 
> created by default a file called filename in the source tree.
> 
> Of course, to keep a clean source tree you can use
> ${CMAKE_CURRENT_BINARY_DIR}/filename which I was forced to do.  But I
> was wondering if this default contamination of the source tree by
>
> FILE(WRITE...
> was a recently introduced bug (I use cmake-2.4.3) that should be fixed?
> Or is there some logical reason which I am missing for putting
> FILE(WRITE...
> results in the source tree by default?


All relative file- and pathnames are interpreted as relative to CMAKE_CURRENT_SOURCE_DIR. This is what one would usually expect everywhere, e.g. when adding source files, or include directories, etc. You would expect that main.cpp means the main.cpp in your source directory. Maybe it would be possible to add some special cases, so that e.g. for the FILE() commands and for the second parameter of CONFIGURE_FILE() relative paths are interpreted relative to CMAKE_CURRENT_BINBARY_DIR, but IMO this would be inconsistent.
So if you write something in the buildtree, always prefix it with CMAKE_CURRENT_BINARY_DIR.

Bye
Alex

-- 
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail


More information about the CMake mailing list