Version 1 (modified by stefan, 10 years ago) (diff)

new page for info on configuration header files

Configuration Header Files

Recall the introduction on configuration header files. The AC_CONFIG_HEADER macro in allows to setup a list of configuration header files that convey information about the configuration run to the source code of the package in the form of #define statements. Since the define statements in different projects may define the same symbols (e.g., PACKAGE_NAME or HAVE_ZLIB), it is undesirable to install a full configuration header file and to require them for building against the package. On the other hand, sometimes it is necessary to convey some information about a package configuration via the header file to users of that package.

Private and public header files

Therefore, in COIN-OR, the convention is to use two header files, a private header file which has the defines for all symbols that are needed to build the package, and a public header file which has the defines only for symbols that may be required by a user of the package. The private header file uses the name config.h and must not be installed. The public header file uses the name config_prjct.h and can be installed. However, it is important that the public header defines only symbols with unique names, so conflicts from including several header files are avoided.

Header files for non-autotools setups

To complicate things further, COIN-OR wants to make it possible to compile COIN-OR code in environments which do not support autotools (e.g., MS Developer Studio). In these systems, the config.h and config_prjct.h are substituted by header files config_default.h and config_prjct_default.h that define a set of default symbols. A user may then have to adjust these files for her system.

Bringing them all together

The logic which of the four header files to include in which situation is implemented in a fifth header file PrjctConfig.h. In any source code, none of the config*.h files should be included, but always the file PrjctConfig.h. It ensures that in an autotools based setup, the file config.h is included whenever the project itself is build and otherwise (i.e., someone builds against the project) the file config_prjct.h is included. Further, in a non-autotools based setup, it includes either config_default.h or config_prjctdefault.h. The distinction is made by two defines that may be specified as arguments in the compiler command line. These ensure that in an autotools setup with configuration header files, always the symbol HAVE_CONFIG_H is defined. Further, the symbol Prjct_BUILD is defined whenever a file belonging to project Prjct is build.


As an example, the CoinUtilsConfig.h contains


#include "config.h"
#include "config_coinutils.h"

#else /* HAVE_CONFIG_H */

#include "config_default.h"
#include "config_coinutils_default.h"

#endif /* HAVE_CONFIG_H */

#endif /*__COINUTILSCONFIG_H__*/

The files config.h and config_coinutils.h are created by the autotools scripts at the end of configure from template files and, because CoinUtils' file contains the statement

AC_CONFIG_HEADER([inc/config.h inc/config_coinutils.h])

Further, the template file is generated automatically by autoheader when the project manager calls the autotools. Therefore, only the public header file config_coinutils.h needed to be setup, which can be done by copying interesting lines from the private header file. In case of CoinUtils, the public header is

/* inc/  */

/* Version number of project */

/* Major Version number of project */

/* Minor Version number of project */

/* Release Version number of project */

/* Define to 64bit integer type */
#undef COIN_INT64_T

/* Define to integer type capturing pointer */

/* Define to 64bit unsigned integer type */
#undef COIN_UINT64_T

After a user run configure, the #undef statements are replaced by corresponding #define statements, depending on the outcome of tests performed by configure.

For a non-autotools based setup, the files config_default.h and config_coinutils_default.h are provided. The public header config_coinutils_default.h is currently

/* Version number of project */
#define COINUTILS_VERSION  "trunk"

/* Major Version number of project */

/* Minor Version number of project */

/* Release Version number of project */

  Define to 64bit integer types. Note that MS does not provide __uint64.

  Microsoft defines types in BaseTsd.h, part of the Windows SDK. Given
  that this file only gets used in the Visual Studio environment, it
  seems to me we'll be better off simply including it and using the
  types MS defines. But since I have no idea of history here, I'll leave
  all of this inside the guard for MSC_VER >= 1200. If you're reading this
  and have been developing in MSVS long enough to know, fix it.  -- lh, 100915 --
#if _MSC_VER >= 1200
# include <BaseTsd.h>
# define COIN_INT64_T INT64
# define COIN_UINT64_T UINT64
  /* Define to integer type capturing pointer */
# define COIN_INT64_T long long
# define COIN_UINT64_T unsigned long long
# define COIN_INTPTR_T int*

and the private header file is config_default.h is

/* include the COIN-OR-wide system specific configure header */
#include "configall_system.h"

/* include the public project specific macros */
#include "config_coinutils_default.h"

/*             HERE DEFINE THE PROJECT SPECIFIC MACROS                     */
/*    These are only in effect in a setting that doesn't use configure     */

/* Define to the debug sanity check level (0 is no test) */

/* Define to the debug verbosity level (0 is no output) */

/* Define to 1 if bzlib is available */
/* #define COIN_HAS_BZLIB */

/* Define to 1 if zlib is available */
/* #define COIN_HAS_ZLIB */

#ifdef _MSC_VER
/* Define to be the name of C-function for Inf check */
#define COIN_C_FINITE _finite

/* Define to be the name of C-function for NaN check */
#define COIN_C_ISNAN _isnan

Since both files need to be setup by the user, here the private header includes the public header to avoid redundancy. Further, a header configall_system.h is included that tries to provide commonly used defines.