[CMake] CMake and Python

Tim Gallagher tim.gallagher at gatech.edu
Wed Nov 23 01:44:15 EST 2011


Hi all,

I don't know if anybody would find this useful or not, but I thought I'd let everybody know about it and if somebody would like to use it, I can figure out the best way to get it out there. 

We have a fairly extensive python library that we use to setup our code and manipulate our data. Part of this process is generating/manipulating CMake cache files. To that end, I wrote a module that can do the following:

- Given a CMakeLists.txt, build a dictionary of available options (possibly including advanced) including the type and default values (and take in some options to turn on before checking for options, to activate if's for example; also allow the caller to specify a prefix they want to include, for instance 'CMAKE' would result in a dictionary only containing CMAKE_* variables).
- Given a CMakeCache.txt file, build the above dictionary
- Given a dictionary of options (built from above or by hand), write out a script to generate the initial cache (to be used with cmake -C)
- Given a dictionary of options, take in another dictionary of options to modify original dictionary with possible include/exclude lists (an example use is to take a dictionary from the user to modify default values, combined with the include/exclude list to say "Only let the user change options X, Y, Z regardless of what they tried to change")

The final thing it currently does may get left in or stripped out if I release it to people -- it writes a simple python script to execute a code using MPI based on the values for the MPI variables found by CMake. This is because we use it to setup test cases and needed an easy way to determine the MPIEXEC and MAX_PROCS variables. 

So, if people are interested in using it or expanding it, let me know and I can throw it up on GitHub or something. If it's something useful for inclusion in CMake now or down the road, that can be figured out too.

Tim


More information about the CMake mailing list