When using the Autotools it's common to generate a config.h
file by specifying the AC_CONFIG_HEADERS
macro in configure.ac
like this:
AC_CONFIG_HEADERS([config.h])
What is the respective equivalent for this when using CMake?
When using the Autotools it's common to generate a config.h
file by specifying the AC_CONFIG_HEADERS
macro in configure.ac
like this:
AC_CONFIG_HEADERS([config.h])
What is the respective equivalent for this when using CMake?
You have to create a file similar to
config.h.in
. Something likeThen you have to declare the variables
Feature_A_FOUND
,Feature_B_FOUND
,B_BITSIZE
in your CMake code and callwhich will result in a config.h file similar to the one from the autotools. If a variable is not found or is set to false, the line will be commented. Otherwise the value will be inserted. Assume
Feature_A_FOUND=A-NOTFOUND
¸Feature_B_FOUND=/usr/lib/b
,B_BITSIZE=64
, which will result inProbably HAVE_FEATURE_B would be better defined as
#cmakedefine01
which results in 0 or 1 depending on the value of the variable.In general it is possible to create every config.h file generated by Autotools as CMake is more flexible. But it requires more work and you cannot automatically get a config.h, but you have to write the .in file yourself.
Documentation: https://cmake.org/cmake/help/v3.6/command/configure_file.html