If you have a cmake
module . You can create a folder called in
to store all config files.
For example,you have a project called FOO
, you can create a FOO_config.h.in
file like:
//===================================================================================
// CMake configuration file, based on SDL 2 version header
// ===================================================================================
#pragma once
#include <string>
#include <sstream>
namespace yournamespace
{
/**
* \brief Information the version of FOO_PROJECT in use.
*
* Represents the library's version as three levels: major revision
* (increments with massive changes, additions, and enhancements),
* minor revision (increments with backwards-compatible changes to the
* major revision), and patchlevel (increments with fixes to the minor
* revision).
*
* \sa FOO_VERSION
* \sa FOO_GetVersion
*/
typedef struct FOO_version
{
int major; /**< major version */
int minor; /**< minor version */
int patch; /**< update version */
} FOO_version;
/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
*/
#define FOO_MAJOR_VERSION 0
#define FOO_MINOR_VERSION 1
#define FOO_PATCHLEVEL 0
/**
* \brief Macro to determine FOO version program was compiled against.
*
* This macro fills in a FOO_version structure with the version of the
* library you compiled against. This is determined by what header the
* compiler uses. Note that if you dynamically linked the library, you might
* have a slightly newer or older version at runtime. That version can be
* determined with GUCpp_GetVersion(), which, unlike GUCpp_VERSION(),
* is not a macro.
*
* \param x A pointer to a FOO_version struct to initialize.
*
* \sa FOO_version
* \sa FOO_GetVersion
*/
#define FOO_VERSION(x) \
{ \
(x)->major = FOO_MAJOR_VERSION; \
(x)->minor = FOO_MINOR_VERSION; \
(x)->patch = FOO_PATCHLEVEL; \
}
/**
* This macro turns the version numbers into a numeric value:
* \verbatim
(1,2,3) -> (1203)
\endverbatim
*
* This assumes that there will never be more than 100 patchlevels.
*/
#define FOO_VERSIONNUM(X, Y, Z) \
((X)*1000 + (Y)*100 + (Z))
/**
* This is the version number macro for the current GUCpp version.
*/
#define FOO_COMPILEDVERSION \
FOO_VERSIONNUM(FOO_MAJOR_VERSION, FOO_MINOR_VERSION, FOO_PATCHLEVEL)
/**
* This macro will evaluate to true if compiled with FOO at least X.Y.Z.
*/
#define FOO_VERSION_ATLEAST(X, Y, Z) \
(FOO_COMPILEDVERSION >= FOO_VERSIONNUM(X, Y, Z))
}
// Paths
#cmakedefine FOO_PATH_MAIN "@FOO_PATH_MAIN@"
This file will create a FOO_config.h
in the install path, with a variable defined in c FOO_PATH_MAIN
from cmake variable. To generate it you need to include in
file in your CMakeLists.txt,like this (set paths and variables):
MESSAGE("Configuring FOO_config.h ...")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/common/in/FOO_config.h.in"
"${FOO_PATH_INSTALL}/common/include/FOO_config.h" )
That file will contain the data from template, and variable with your real path, for example:
// Paths
#define FOO_PATH_MAIN "/home/YOUR_USER/Respositories/git/foo_project"