[CMake] CMake Digest, Vol 58, Issue 3

David.Karr at L-3COM.COM David.Karr at L-3COM.COM
Mon Feb 2 14:15:54 EST 2009


From: ankit jain <ankitguddu at gmail.com>
Subject: Re: [CMake] equivalent cmakelist for this file

> The objective here to include all the .desc files in the
> cmakelist and when we make it it should generate the executable
> for it like if we include abc.desc then after make it should
> generate a file abc which is executable and a script which has
> test cases but generated by .desc file only. In order to achieve
> that guide me how to write cmake list file for it so that it
> wiil produce equivalent behaviour as normal make does using
> unix makefiles.
>
> When we make to the unix makefiles it is generating the equivalent
> executable mentioned inthat .desc file.
>
> I want to achieve that through Cmakelist files.

First of all remember this: Your CmakeList files do not execute any of
these things: what they do is to write _new_ makefiles for you.  In
order to succeed with CMake, what you need to do is figure out how to
tell CMake the things that need to be in your new makefiles so that
those makefiles will do the _necessary_ things that the old makefiles
do.

(I stress the word "necessary" because sometimes makefiles do things
that are not really necessary and you can succeed without those things.
It sounds like something about these .desc files is necessary to your
process, so you have to figure out exactly what that is so you can tell
CMake that your new makefiles must do it.  But for example it may not
really matter what the name of a script is as long as someone executes
the script by using whatever name it has; in that case the particular
name you have previously seen is _not_ one of the "necessary things" in
your process.)

Where CMake can be very helpful is it knows a lot about the things that
almost all C/C++ projects require to be done when someone builds them.
For example, it is generally the case that there will be directories
with C or C++ files in them, and one of the things your makefile must do
is to collect a set of C and C++ files from one or more of these
directories and build some library or executable from them.  All of us
here have projects that need this, usually many different libraries
and/or executables from various sets of C and C++ files in our source
directories, so CMake provides commands such as ADD_LIBRARY and
ADD_EXECUTABLE.

But it appears that nobody here except you has ever seen a makefile that
needs to do something with a ".desc" file.  I suspect that the practice
of naming a file something.desc for this purpose is something that is
done in perhaps only one organization, or at most in a few geographic
regions in the entire world, and that is why nobody here seems to
recognize what it is.  But you have told us that after your makefile
generates some executable from the C/C++ source, it must executed some
kind of script that has something to do with your .desc file.

On the other hand, many of us have projects where the makefiles have to
do some unique things that nobody (or almost nobody) else in the world
does, and yet we succeed in using CMake to help us build these projects.
So it is very likely that you can do what you want in CMake, but you
will have to figure out many of the details yourself, as we have had to
do for our particular unusual build steps.

I still do not understand exactly what you need so I may guess wrong,
but I guess that you might be able to use the ADD_CUSTOM_COMMAND command
to tell CMake that the new makefile needs to run your script, and when
it should run.  You may have to use other CMake commands such as SET to
create new CMake variables (which you will have to name) containing
filenames and/or command-line parameters for your script, and to
manipulate those strings until they are exactly what you need to give as
parameters to ADD_CUSTOM_COMMAND so that the resulting makefile will do
what you need.  

I have used ADD_CUSTOM_COMMAND only with Visual Studio projects, not
with Unix makefile projects, so I don't know if it would work exactly
the same for you as it does for me, but I have found it works pretty
well for me once I have taken the trouble to figure out _exactly_ what
named script or executable needs to be called with _exactly_ what
command-line parameters from _exactly_ what current working directory.
I wish you success.

David Karr



More information about the CMake mailing list