[CMake] Custom target failing to build on Mac

Alan W. Irwin irwin at beluga.phys.uvic.ca
Sat Jun 7 12:54:53 EDT 2008


On 2008-06-07 15:39+0100 Matthew Smith wrote:

> Hi everyone,
>
> I am trying to build a cross-platform Qt application, and use a header
> file, generated at build time, to produce a version number definition
> which can be included by any other source file, so I can define the
> version number once in the CMakeLists.txt file and have it reproduced
> anywhere else that it's needed.  The problem is that it is failing to
> generate on the Mac, which results in a compilation failure for the
> first source file that includes it.  This does not happen on Windows or
> Linux (using CMake 2.6 on all platforms).
>
> I have attached the CMakeLists.txt file; the bit where the source file
> is built starts at line 158.  Looking at the CMakeFiles directory, a
> target directory (VERSION_HEADER.dir) has been produced, but the target
> is not generated before the actual compilation starts; on other targets,
> it is generated before "scanning dependencies" for the main executable
> target.  Can anyone help me with this?

I had a look at your CMakeLists.txt file, and it appears you have a custom
target that file-depends on the header generated with a custom command.
That overview should work fine (it works fine on PLplot), but there are two
details in your code that seem a bit questionable to me, and I don't
think you should be using ALL on the custom target.


* You file(REMOVE ...) the header before you define the custom command, but
the remove happens at cmake time while the custom command happens at
make time.  Anyhow, if you do not distribute a stale header with your source
code, I don't think the file(REMOVE...) is necessary.

* The OUTPUT and DEPEND statements refer to the same header file name
without path, but I always prefer to see the full path
${CMAKE_CURRENT_BINARY_DIR} prepended to the file name in both cases.

The above may be minor style points rather then the cause of your
difficulties, and I think the next issue is the real source of your problem.

* Your custom target uses ALL.  That means the header will be generated
every time (which you don't want since that causes complete recompilation
each time for every source file that uses that header).  Instead, you should
drop ALL and have your executable or library target-depend on the custom
target (which insures the custom target is always run _before_ the build,
but all that does (via its file dependency on the header) is check that the
header is up to date.

When you have made the above three changes your style should be in exact
conformance with what we do with PLplot which works on all three platforms.

There is another alternative you might want to try with
set_source_files_properties and the GENERATED property, but I haven't tried
that.

HTH.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list