Cmake has the configure_file function to perform an operation similar to autotools' configure script processing foo.h.in into a foo.h, that contains macros describing relevant parameters of the toolchain and run-time. configure_file though is a very general purpose mechanism that replaces place-holders that reference a Cmake variable with a macro that defines the information for the program.
I'm trying to use Cmake to do a simple build configuration of an existing open source library (it's libwww from the W3). By default the library uses autotools, but even so, the authors see fit to do some "special" customizations of the basic autotools methodology. I'm working with a large-ish, multi-part project that cross-compiles onto some platforms, mundane and exotic. It uses Cmake to organize the build, and I wish to produce the cmake code to express (to some level of approximation) the intent of the autotools inputs. That means the code is expecting something called config.h based on config.h.in. My plan is to translate the autotools template language into that used by Cmake.
What I'm struggling with is that the space of inputs that autotools uses to populate their config.h-type files corresponds the all the results of the tests performed by the configure script to determine these values, and it's fairly well-defined in the autotools documentation (sort of). configure_file on the other hand is a very general, cmake-style mechanism that will instantiate the value of any Cmake variable into a properly-formatted template version. What I'm struggling to find is set of Cmake variables created by the equivalent configuration tests done when Cmake creates a makefile or IDE project. I'm looking for equivalencies values that the specific autotools wwwconf.h.in cares about and the name of the Cmake variable expresses that result.
So to make it concrete, the config.h.h - the autotools input template - has a large set of entries that look like this -
/* Define if you have the strerror function. */
#undef HAVE_STRERROR
So HAVE_STRERROR
by default is undefined and if configure knows the answer, it replaces the corresponding line in config.h with #define HAVE_STRERROR 1
or something equally affirmative. config.h.in is generated by autoconf based on the user-specified requirements express in configure.ac (as of course is the configure script itself).
So the binding between the macro name HAVE_STRERRO
and the result of the test performed by configure to determine the existence of strerror
in the standard libraries could be standardized or it could be user-specified in configure.ac, but for Cmake's configure_file
, it is all very open-ended. It will replace #cmakedefine FOO
in your input template with either #undef FOO
or #define FOO <foo-value>
. Its mission is simple. It doesn't care what the semantics of FOO is. It just wants to create an include file with C macros expressing that name and value. My mission is a bit more specific. I want to emulate autoconf's mechanism for creating a config.h file with the answer to the questions asked by configure at build time. That means I have to know the names of the Cmake variables that record the results of its configure-time tests, do some kind of mapping if they are not the same as the symbols used by autoconf and use the configure_file function to produce a config.h that is the same (hopefully) as would be produced by autoconf.
So my problem is that the documentation for configure_file only covers the substitution language for this very basic function. I need to find where the results of Cmake's configure-time tests are, make a mapping to the expected names in the library's config.h and use configure_file to instantiate them within my cmake-style input template.
I've been using Cmake for a long time, but these are relatively new features, and I can't seem to find the Cmake variables for the results of the configure tests or any similar mechanism to find out those data. I figured they may be stored in the .cache file, and there are some name/values like that, but the list seems too short. I have looked for, but not found, documentation on such variables or name-value query mechanism, and I'm hoping the community has some pointers on how one is supposed