[CMake] Autogenerating CMakeLists.txt

Eric Noulard eric.noulard at gmail.com
Fri Nov 9 10:38:34 EST 2007


2007/11/9, Marcus <yhadin002 at sneakemail.com>:
> Hi,
>
> Please could I ask for your opinions on automatically generating
> CMakeList.txt files, rather than editing them directly.

There exists some kind of generator scripts,
see
http://www.cmake.org/Wiki/CMake#Converters_from_other_buildsystems_to_CMake
for example here in Ruby (gencmake):
http://websvn.kde.org/trunk/KDE/kdesdk/cmake/scripts/

I personnally use an home-brewed python script for generating CMakeLists.txt
for simple directory hierarchy containing C sources files.
I may post it here but it is currently very specific to my needs:

It recurses in a specified directory then goes in each
subdirs of the specified directory and look for .c or .h files.
It builds a library (ADD_LIBRARY) for each directory
and one executable (ADD_EXECUTABLE) for each c file
which contains a "main" function.
The library is named after the name of the subdir
and the executable is named using the subdir name +
the name of the C file containing "main".

I have no way to specify dependency but I think
it would be easy to add a per-directory a hand-written
"dependency.cmake" file which may be included by
the generated CMakeLists.txt if it is found by the
CMakeLists.txt generator.

The content of the "dependency.cmake"
should be something like simple VAR definition

SET(LIBDEPEND "firstdep seconddep")

>
> My motivation is that I am working on several projects, each broken-down
> into sub-projects, and all of them use a consistent directory structure.
>   I want to take advantage of this uniform structure to minimise the
> maintenance work involved in editing CMakeLists.txt files.
>
> By assuming a uniform directory structure, and adding a small
> meta-information file to each project, I believe the CMakeList.txt files
> could be automatically generated.  The meta-information would only include:

I would avoid meta information in file or let it be
define by a CMake script.

>
> * project name

Project name may be derived from the directory name

> * names of dependencies

May be an hand-written dependency.cmake

> * list of sub-projects

The directory structure may be enough?

> The generator would glob for files within each project, so it would be
> necessary to rebuild the CMakeList.txt files if meta-information is
> changed, or if new files are added to a project.  Ideally, the generated
> build system should issue a warning when the CMakeLists.txt files are
> out of date.

I don't think I would like that and would rather launch it when I want it
but...others may like it :=)

>
> Please let me know if you think this is a feasible (and sensible) solution.

I think it is feasible.
sensible depends on your needs and usage.

-- 
Erk


More information about the CMake mailing list