Discussion:
[CMake] cmake config.h
luxInteg
2010-11-27 03:24:36 UTC
Permalink
Greetings,

I am learning cmake.

I have a package that compiles fine with autoconf but fails with cmake. (The
former generates automatically a required header-file config.h
) I have checked the cmake mailing list to see if the autoheader utility has
been ported to cmake. This seems unclear. So I would be gateful if someone
on list could verify if this facility is/isNOT (..yet) available using
cmake. (And if it is -how it is used)

sincerely
luxInteg
Clifford Yapp
2010-11-27 14:24:01 UTC
Permalink
To the best of my knowledge, there is no automatic feature available
in CMake for this. Fortunately, it is not terribly hard to set up
something reasonably functional yourself with a few Macros -
autoheader uses some fairly standard naming conventions. For BRL-CAD
I've wrapped the key tests in macros that check for a filename stored
in some standard global variable (CONFIG_H probably, but I don't
recall) and if that variable does indeed have a filename the macro
appends the appropriate line to the file. For bonus points, write out
a config.h.in file using (again, IIRC) #cmakedefine lines and then run
configure_file - this ensures the CMakeLists.txt logic gets a chance
to clear out something based on conditionals that a simple
functionality check might include (say, for example, you check for
something on system, find it, and then discover later in the build
logic that the user wants the Boost version, if Boost is found...
usually you can structure to avoid these situations but conceptually
its often simpler to be able to have configure_file pronounce the
"final" judgment on variables at the end of the process. You can
check the cmake branch of the BRL-CAD svn on sourceforge for an
example; while I make no claim the setup is optimal it does seem to
work.

One thing you won't find (yet) is a library of autoconf-compat
functions to replicate the specialized tests that autoconf provides -
there has been some discussion about that but as yet no concerted,
organized effort to put together a library file. Hopefully as more
projects undergo this process something will coalesce and even become
standard in CMake.

Cheers and best of luck,
CY
Post by luxInteg
Greetings,
I am learning cmake.
I have   a package that compiles fine with autoconf but fails with cmake. (The
former generates automatically  a  required header-file config.h
) I have checked the cmake mailing  list to see if the autoheader utility has
been ported to cmake.  This seems unclear.  So I would be gateful if someone
on list could  verify if this facility is/isNOT (..yet)  available using
cmake.  (And if it is -how  it  is used)
sincerely
luxInteg
luxInteg
2010-11-28 02:41:43 UTC
Permalink
Post by Clifford Yapp
To the best of my knowledge, there is no automatic feature available
in CMake for this. Fortunately, it is not terribly hard to set up
something reasonably functional yourself with a few Macros -
autoheader uses some fairly standard naming conventions. For BRL-CAD
I've wrapped the key tests in macros that check for a filename stored
in some standard global variable (CONFIG_H probably, but I don't
recall) and if that variable does indeed have a filename the macro
appends the appropriate line to the file. For bonus points, write out
a config.h.in file using (again, IIRC) #cmakedefine lines and then run
configure_file - this ensures the CMakeLists.txt logic gets a chance
to clear out something based on conditionals that a simple
functionality check might include (say, for example, you check for
something on system, find it, and then discover later in the build
logic that the user wants the Boost version, if Boost is found...
usually you can structure to avoid these situations but conceptually
its often simpler to be able to have configure_file pronounce the
"final" judgment on variables at the end of the process. You can
check the cmake branch of the BRL-CAD svn on sourceforge for an
example; while I make no claim the setup is optimal it does seem to
work.
One thing you won't find (yet) is a library of autoconf-compat
functions to replicate the specialized tests that autoconf provides -
there has been some discussion about that but as yet no concerted,
organized effort to put together a library file. Hopefully as more
projects undergo this process something will coalesce and even become
standard in CMake.
Thanks and keep up the good work.
Michael Jackson
2010-11-27 14:58:15 UTC
Permalink
You use a combination of some CMake macros and "configure_file()" command.

First, in your CMakeLists.txt file (or another cmake file) you would have lines such as:


# In this file we are doing all of our 'configure' checks. Things like checking
# for headers, functions, libraries, types and size of types.
INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckCXXSourceCompiles.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckSymbolExists.cmake)

# To check for an include file you do this:
CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)

# To check the size of a primitive type:
CHECK_TYPE_SIZE("int" SIZEOF_INT)

And you continue doing these types of checks for each item that you want to check. You can even do custom "try-compiles/Try-run" for more elaborate setups.

Now that you have your variables define you add lines like this to your CMakeLists.txt file:

configure_file ("${PROJECT_SOURCE_DIR}/Headers/config.h.in"
"${PROJECT_BINARY_DIR}/config.h" )
# Now make sure that you the the build directory on your "Include" path when compiling
include_directories(${PROJECT_BINARY_DIR})

Lastly, you need to create a file in your project inside "Headers" called "config.h.in" with the following content:

/*--------------------------------------------------------------------------
* This file is autogenerated from config.h.in
* during the cmake configuration of your project. If you need to make changes
* edit the original file NOT THIS FILE.
* --------------------------------------------------------------------------*/
#ifndef _CONFIGURATION_HEADER_GUARD_H_
#define _CONFIGURATION_HEADER_GUARD_H_

/* Define to 1 if you have the <stdint.h> header file. */
#cmakedefine HAVE_STDINT_H @HAVE_STDINT_H@

/* The size of `long', as computed by sizeof. */
#define SIZEOF_INT @SIZEOF_INT@

......

#endif

When you run CMake a new file in your build directory will be generated with the name "config.h" and it will have the content appropriate for inclusion into a C/C++ program.

Now, this is the "basic" setup. If you use this exactly as it appears AND you include other projects into your own projects then you _may_ run into conflicts as some projects will already have these preprocessor statements defined. So what I usually do is prefix the "HAVE_*" and "SIZEOF_*" variables with something from my own project. I have a project template that I pull from located at <href="http://scm.bluequartz.net/support-libraries/cmp"> Look in CoreTests/cmpConfigureChecks.cmake and ConfiguredFiles/cmpConfiguration.h.in
Most of the code is gathered from other CMake based projects such as CMake itself, vtk, paraview and few others and then made more consistent with how I want my projects setup.

Hope all that helps
___________________________________________________________
Mike Jackson www.bluequartz.net
Principal Software Engineer ***@bluequartz.net
BlueQuartz Software Dayton, Ohio
Post by luxInteg
Greetings,
I am learning cmake.
I have a package that compiles fine with autoconf but fails with cmake. (The
former generates automatically a required header-file config.h
) I have checked the cmake mailing list to see if the autoheader utility has
been ported to cmake. This seems unclear. So I would be gateful if someone
on list could verify if this facility is/isNOT (..yet) available using
cmake. (And if it is -how it is used)
sincerely
luxInteg
luxInteg
2010-11-28 02:39:23 UTC
Permalink
Post by Michael Jackson
You use a combination of some CMake macros and "configure_file()" command.
# In this file we are doing all of our 'configure' checks. Things like
checking # for headers, functions, libraries, types and size of types.
INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckCXXSourceCompiles.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckSymbolExists.cmake)
CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)
CHECK_TYPE_SIZE("int" SIZEOF_INT)
And you continue doing these types of checks for each item that you want to
check. You can even do custom "try-compiles/Try-run" for more elaborate
setups.
Now that you have your variables define you add lines like this to your
configure_file ("${PROJECT_SOURCE_DIR}/Headers/config.h.in"
"${PROJECT_BINARY_DIR}/config.h" )
# Now make sure that you the the build directory on your "Include" path
when compiling include_directories(${PROJECT_BINARY_DIR})
Lastly, you need to create a file in your project inside "Headers" called
/*-------------------------------------------------------------------------
- * This file is autogenerated from config.h.in
* during the cmake configuration of your project. If you need to make
changes * edit the original file NOT THIS FILE.
*
--------------------------------------------------------------------------
*/ #ifndef _CONFIGURATION_HEADER_GUARD_H_
#define _CONFIGURATION_HEADER_GUARD_H_
/* Define to 1 if you have the <stdint.h> header file. */
/* The size of `long', as computed by sizeof. */
......
#endif
When you run CMake a new file in your build directory will be generated
with the name "config.h" and it will have the content appropriate for
inclusion into a C/C++ program.
Now, this is the "basic" setup. If you use this exactly as it appears AND
you include other projects into your own projects then you _may_ run into
conflicts as some projects will already have these preprocessor statements
defined. So what I usually do is prefix the "HAVE_*" and "SIZEOF_*"
variables with something from my own project. I have a project template
that I pull from located at
<href="http://scm.bluequartz.net/support-libraries/cmp"> Look in
CoreTests/cmpConfigureChecks.cmake and
ConfiguredFiles/cmpConfiguration.h.in Most of the code is gathered from
other CMake based projects such as CMake itself, vtk, paraview and few
others and then made more consistent with how I want my projects setup.
Hope all that helps
Thanks I maybe had done a blind-man stubmle into a bastardised version
thereof before I say your email. I will give your perhaps more elegant
offering a run sometimes.
luxInteg
2010-11-28 14:04:50 UTC
Permalink
Post by Michael Jackson
# In this file we are doing all of our 'configure' checks. Things like
checking # for headers, functions, libraries, types and size of types.
INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)
this I find straightforward
Post by Michael Jackson
# In this file we are doing all of our 'configure' checks. Things like
checking # for headers, functions, libraries, types and size of types.
INCLUDE (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
I presume can be used aas for example:-
CHECK_FUNCTION_EXISTS(pow HAVE_POW)
CHECK_FUNCTION_EXISTS(realloc HAVE_HAVE_REALLOC) etc etc
Post by Michael Jackson
CHECK_TYPE_SIZE("int" SIZEOF_INT)
QUESTION:
the ones that frequently come into what I do are long, zint, dzint (complex)
So would these translate to
CHECK_TYPE_SIZE("long" SIZEOF_LONG) etc etc ?
Post by Michael Jackson
# In this file we are doing all of our 'configure' checks. Things like
checking # for headers, functions, libraries, types and size of types.
INCLUDE (${CMAKE_ROOT}/Modules/CheckCXXSourceCompiles.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckSymbolExists.cmake)
headers, datatypes, functions seem straight forward, I currently have a
config.h.in refering to 'package' (I assume something to do with pkgconfig
) for which I have not a clue how to translate using the tools above:-
The said problematic config.h.in file has lines like these:-

-----------------------------
/* Name of package */
#undef PACKAGE

/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT

/* Define to the full name of this package. */
#undef PACKAGE_NAME

/* Define to the full name and version of this package. */
#undef PACKAGE_STRING

/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME

/* Define to the version of this package. */
#undef PACKAGE_VERSION

/* Version number of package */
#undef VERSION

/* Define to empty if `const' does not conform to ANSI C. */
#undef const

/* Define to rpl_malloc if the replacement function should be used. */
#undef malloc

/* Define to rpl_realloc if the replacement function should be used. */
#undef realloc
-----------------------

thanks again for your suggestion and advice on the above would be
apprecuated
luxInteg
2010-11-28 16:03:33 UTC
Permalink
Post by luxInteg
headers, datatypes, functions seem straight forward, I currently have a
config.h.in refering to 'package' (I assume something to do with
pkgconfig ) for which I have not a clue how to translate using the
tools above:- The said problematic config.h.in file has lines like
these:-
-----------------------------
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent.
*/ #undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Version number of package */
#undef VERSION
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Define to rpl_malloc if the replacement function should be used. */
#undef malloc
/* Define to rpl_realloc if the replacement function should be used. */
#undef realloc
-----------------------
I came across the useful wiki
http://www.cmake.org/Wiki/CMake:How_To_Write_Platform_Checks

And I have also done some searching on the net to learn to use
CheckVariableExists.cmake to set arguments for 'PACKAGE' (if so required)
in config.h. I have not been successful. So I would be grateful if someone
on list could give an example of how CheckVariableExists.cmake is used.
Michael Jackson
2010-11-28 15:21:45 UTC
Permalink
Those variables are specific for the project you are trying to
convert. For example if this was the LibTiff project then you might
have something like:

#define PACKAGE "libTif"
#define PACKAGE_BUGREPORT "***@libtiff.com"
#define PACKAGE_VERSION "8.9.10"

You can set these as CMake varables in your CMakeLists.txt file as the
following:

set (MY_PACKAGE "MyProject")

Then in the config.h.in you would have

#cmakedefine PACKAGE @MY_PACKAGE@

And do that for the remaining variables in the list you provided.

Again, if this is an existing project that is well known then you
probably can not mess with the preprocessor #defines BUT if this is a
new project or if you have control over the project then I HIGHLY
recommend you use something like this:

#cmakedefine MYPROJECT_PACKAGE "MyProject"

or somehow prefix or suffix those variables. I have had instances
where I have used several different packages where each one defined
PACKAGE which created some interesting side effects.

Hope that helps.

_________________________________________________________
Mike Jackson                  ***@bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio
Post by luxInteg
headers, datatypes, functions  seem straight forward,  I currently have  a
config.h.in    refering to 'package' (I assume something to do with
pkgconfig )  for which  I  have not a clue how  to translate using the
tools above:- The said  problematic  config.h.in file  has lines like
these:-
-----------------------------
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent.
*/ #undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Version number of package */
#undef VERSION
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Define to rpl_malloc if the replacement function should be used. */
#undef malloc
/* Define to rpl_realloc if the replacement function should be used. */
#undef realloc
-----------------------
I came across the useful wiki
http://www.cmake.org/Wiki/CMake:How_To_Write_Platform_Checks
And I have also done some searching on the net to learn to  use
CheckVariableExists.cmake to   set   arguments for  'PACKAGE' (if so required)
 in config.h.  I have not been successful.  So I would be grateful if someone
on list could   give an example of how CheckVariableExists.cmake  is used.
luxInteg
2010-11-28 21:07:25 UTC
Permalink
Post by Michael Jackson
Those variables are specific for the project you are trying to
convert. For example if this was the LibTiff project then you might
#define PACKAGE "libTif"
#define PACKAGE_VERSION "8.9.10"
You can set these as CMake varables in your CMakeLists.txt file as the
set (MY_PACKAGE "MyProject")
Then in the config.h.in you would have
And do that for the remaining variables in the list you provided.
v helpful thanks
luxInteg
2011-01-25 03:32:36 UTC
Permalink
Post by luxInteg
I came across the useful wiki
http://www.cmake.org/Wiki/CMake:How_To_Write_Platform_Checks
I need '1's in config.g and I dont know how these are generated.
For gsl This the cmake output:-

-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for stdlib.h
-- Looking for stdlib.h - found
-- Looking for string.h
-- Looking for string.h - found
-- Looking for memory.h
-- Looking for memory.h - found
-- Looking for strings.h
-- Looking for strings.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for dlfcn.h
-- Looking for dlfcn.h - found
-- Looking for vprintf
-- Looking for vprintf - found
-- Looking for memcpy
-- Looking for memcpy - found
-- Looking for memmove
-- Looking for memmove - found
-- Looking for strdup
-- Looking for strdup - found
-- Looking for strtol
-- Looking for strtol - found
-- Looking for strtoul
-- Looking for strtoul - found
-- HAVE_EXIT_SUCCESS_AND_FAILURE
-- Looking for cos in m
-- Looking for cos in m - found
-- HAVE_DECL_FEENABLEEXCEPT
-- HAVE_DECL_HYPOT
-- HAVE_DECL_EXPM1
-- HAVE_DECL_ACOSH
-- HAVE_DECL_ASINH
-- HAVE_DECL_ATANH
-- Looking for ldexp
-- Looking for ldexp - found
-- Looking for frexp
-- Looking for frexp - found
-- Looking for isinf
-- Looking for isinf - found
-- Looking for finite
-- Looking for finite - found
-- Looking for isnan
-- Looking for isnan - found
-- HAVE_DECL_ISFINITE
-- HAVE_DECL_LOG1P
-- HAVE_PRINTF_LONGDOUBLE
-- HAVE_EXTENDED_PRECISION_REGISTERS
-- HAVE_FPU_X86_SSE
-- Performing Test HAVE__FPU_SETCW
-- Performing Test HAVE__FPU_SETCW - Success
-- Performing Test HAVE_FPSETPREC
-- Performing Test HAVE_FPSETPREC - Failed
-- Performing Test HAVE__CONTROLFP
-- Performing Test HAVE__CONTROLFP - Failed
-- Performing Test HAVE__CONTROLFP_S
-- Performing Test HAVE__CONTROLFP_S - Failed
-- Performing Test HAVE_FPU_INLINE_ASM_X86
-- Performing Test HAVE_FPU_INLINE_ASM_X86 - Success
-- HAVE_GNUX86_IEEE_INTERFACE
-- HAVE_IEEE_COMPARISONS
-- HAVE_IEEE_DENORMALS
-- Configuring done
-- Generating done
-- Build files have been written to: ~/S_TESTS/gsl-1.14/build




make fails like so

~/sys/infnan.c:98:3: error: #error "cannot define gsl_finite without
HAVE_DECL_FINITE or HAVE_IEEE_COMPARISONS"
~/sys/infnan.c:115:3: error: #error "cannot define gsl_isnan without
HAVE_DECL_ISNAN or HAVE_IEEE_COMPARISONS"

I thought I ensured that HAVE_IEEE_COMPARISONS and HAVE_DECL_FINITE and
HAVE_DECL_ISNAN etc were tested for and set to 1 in the config.h-
generating file (when these were not not generated by 'standard cmake
macros) and hoped that they would be with the latter. However there were no
'1's in the config.h file and the make failed. A quick/crude substitute of
appropriate '1's in the said file and the make progressed. So how do I
ensure that '1's are set in the generated config.h file?


thanks in advance

sincerely
luxInteg
luxInteg
2011-01-26 20:03:44 UTC
Permalink
Post by luxInteg
Post by luxInteg
I came across the useful wiki
http://www.cmake.org/Wiki/CMake:How_To_Write_Platform_Checks
I need '1's in config.g and I dont know how these are generated.
For gsl This the cmake output:-
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for stdlib.h
-- Looking for stdlib.h - found
-- Looking for string.h
-- Looking for string.h - found
-- Looking for memory.h
-- Looking for memory.h - found
-- Looking for strings.h
-- Looking for strings.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for dlfcn.h
-- Looking for dlfcn.h - found
-- Looking for vprintf
-- Looking for vprintf - found
-- Looking for memcpy
-- Looking for memcpy - found
-- Looking for memmove
-- Looking for memmove - found
-- Looking for strdup
-- Looking for strdup - found
-- Looking for strtol
-- Looking for strtol - found
-- Looking for strtoul
-- Looking for strtoul - found
-- HAVE_EXIT_SUCCESS_AND_FAILURE
-- Looking for cos in m
-- Looking for cos in m - found
-- HAVE_DECL_FEENABLEEXCEPT
-- HAVE_DECL_HYPOT
-- HAVE_DECL_EXPM1
-- HAVE_DECL_ACOSH
-- HAVE_DECL_ASINH
-- HAVE_DECL_ATANH
-- Looking for ldexp
-- Looking for ldexp - found
-- Looking for frexp
-- Looking for frexp - found
-- Looking for isinf
-- Looking for isinf - found
-- Looking for finite
-- Looking for finite - found
-- Looking for isnan
-- Looking for isnan - found
-- HAVE_DECL_ISFINITE
-- HAVE_DECL_LOG1P
-- HAVE_PRINTF_LONGDOUBLE
-- HAVE_EXTENDED_PRECISION_REGISTERS
-- HAVE_FPU_X86_SSE
-- Performing Test HAVE__FPU_SETCW
-- Performing Test HAVE__FPU_SETCW - Success
-- Performing Test HAVE_FPSETPREC
-- Performing Test HAVE_FPSETPREC - Failed
-- Performing Test HAVE__CONTROLFP
-- Performing Test HAVE__CONTROLFP - Failed
-- Performing Test HAVE__CONTROLFP_S
-- Performing Test HAVE__CONTROLFP_S - Failed
-- Performing Test HAVE_FPU_INLINE_ASM_X86
-- Performing Test HAVE_FPU_INLINE_ASM_X86 - Success
-- HAVE_GNUX86_IEEE_INTERFACE
-- HAVE_IEEE_COMPARISONS
-- HAVE_IEEE_DENORMALS
-- Configuring done
-- Generating done
-- Build files have been written to: ~/S_TESTS/gsl-1.14/build
make fails like so
~/sys/infnan.c:98:3: error: #error "cannot define gsl_finite without
HAVE_DECL_FINITE or HAVE_IEEE_COMPARISONS"
~/sys/infnan.c:115:3: error: #error "cannot define gsl_isnan without
HAVE_DECL_ISNAN or HAVE_IEEE_COMPARISONS"
I thought I ensured that HAVE_IEEE_COMPARISONS and HAVE_DECL_FINITE
and HAVE_DECL_ISNAN etc were tested for and set to 1 in the config.h-
generating file (when these were not not generated by 'standard cmake
macros) and hoped that they would be with the latter. However there
were no '1's in the config.h file and the make failed. A quick/crude
substitute of appropriate '1's in the said file and the make
progressed. So how do I ensure that '1's are set in the generated
config.h file?
I still have not seen a reproducible way of generating a config.h.in to
reflect results of 'platform' checks in cmake. Would a simple approach of
generating )dynamically) such a config.h.in not be useful?

Suppose we were start with an empty file -call this config.h.cmake (for
instance)

so to do a header file check for example
check_include_file(somefile.h HAVE_SOMEFILE_H)

if the above is true
use the execute_process()
to add a line (for example ) like so :-
--------------
cat>>config.h.cmake<<"EOF"
#define HAVE_SOMEFILE_H 1
EOF
--------------

then repeat for other checks{and custom checks}
adding compile definitions (to the appropriate CMakeLists,txt file) as
required

then in the end use configure_file() to transform this file in to the required
config.h
Michael Jackson
2011-01-26 19:07:57 UTC
Permalink
I _think_ there are issues with generating a file that is later used by CMake. I think. The other issue is that every time you run CMake (by default) that file is going to be written, then configured by cmake which will most likely mean a larger recompile than might be necessary.

I don't see the problem here. Most projects just have a one-to-one relationship between the tests that they perform such as looking for include files, and the entries in their configuration file.

So if you do a test looking for <sys/types.h> then you would also have an entry in your config.h.in file like this:

#cmakedefine01 HAVE_SYSTYPES_H @HAVE_SYSTYPES_H@

Yes, this has a large initial "coming up to speed" but once you have it adding a few more tests is simple and fast.

Take a look at http://scm.bluequartz.net/support-libraries/cmp I kind of tried what you are doing but ended up with just a bunch of templates that I can easily use with new CMake projects that will run all the same tests and create the same type of "Config.h" file for each project.
___________________________________________________________
Mike Jackson www.bluequartz.net
Principal Software Engineer ***@bluequartz.net
BlueQuartz Software Dayton, Ohio
Post by luxInteg
Post by luxInteg
Post by luxInteg
I came across the useful wiki
http://www.cmake.org/Wiki/CMake:How_To_Write_Platform_Checks
I need '1's in config.g and I dont know how these are generated.
For gsl This the cmake output:-
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for stdlib.h
-- Looking for stdlib.h - found
-- Looking for string.h
-- Looking for string.h - found
-- Looking for memory.h
-- Looking for memory.h - found
-- Looking for strings.h
-- Looking for strings.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for dlfcn.h
-- Looking for dlfcn.h - found
-- Looking for vprintf
-- Looking for vprintf - found
-- Looking for memcpy
-- Looking for memcpy - found
-- Looking for memmove
-- Looking for memmove - found
-- Looking for strdup
-- Looking for strdup - found
-- Looking for strtol
-- Looking for strtol - found
-- Looking for strtoul
-- Looking for strtoul - found
-- HAVE_EXIT_SUCCESS_AND_FAILURE
-- Looking for cos in m
-- Looking for cos in m - found
-- HAVE_DECL_FEENABLEEXCEPT
-- HAVE_DECL_HYPOT
-- HAVE_DECL_EXPM1
-- HAVE_DECL_ACOSH
-- HAVE_DECL_ASINH
-- HAVE_DECL_ATANH
-- Looking for ldexp
-- Looking for ldexp - found
-- Looking for frexp
-- Looking for frexp - found
-- Looking for isinf
-- Looking for isinf - found
-- Looking for finite
-- Looking for finite - found
-- Looking for isnan
-- Looking for isnan - found
-- HAVE_DECL_ISFINITE
-- HAVE_DECL_LOG1P
-- HAVE_PRINTF_LONGDOUBLE
-- HAVE_EXTENDED_PRECISION_REGISTERS
-- HAVE_FPU_X86_SSE
-- Performing Test HAVE__FPU_SETCW
-- Performing Test HAVE__FPU_SETCW - Success
-- Performing Test HAVE_FPSETPREC
-- Performing Test HAVE_FPSETPREC - Failed
-- Performing Test HAVE__CONTROLFP
-- Performing Test HAVE__CONTROLFP - Failed
-- Performing Test HAVE__CONTROLFP_S
-- Performing Test HAVE__CONTROLFP_S - Failed
-- Performing Test HAVE_FPU_INLINE_ASM_X86
-- Performing Test HAVE_FPU_INLINE_ASM_X86 - Success
-- HAVE_GNUX86_IEEE_INTERFACE
-- HAVE_IEEE_COMPARISONS
-- HAVE_IEEE_DENORMALS
-- Configuring done
-- Generating done
-- Build files have been written to: ~/S_TESTS/gsl-1.14/build
make fails like so
~/sys/infnan.c:98:3: error: #error "cannot define gsl_finite without
HAVE_DECL_FINITE or HAVE_IEEE_COMPARISONS"
~/sys/infnan.c:115:3: error: #error "cannot define gsl_isnan without
HAVE_DECL_ISNAN or HAVE_IEEE_COMPARISONS"
I thought I ensured that HAVE_IEEE_COMPARISONS and HAVE_DECL_FINITE
and HAVE_DECL_ISNAN etc were tested for and set to 1 in the config.h-
generating file (when these were not not generated by 'standard cmake
macros) and hoped that they would be with the latter. However there
were no '1's in the config.h file and the make failed. A quick/crude
substitute of appropriate '1's in the said file and the make
progressed. So how do I ensure that '1's are set in the generated
config.h file?
I still have not seen a reproducible way of generating a config.h.in to
reflect results of 'platform' checks in cmake. Would a simple approach of
generating )dynamically) such a config.h.in not be useful?
Suppose we were start with an empty file -call this config.h.cmake (for
instance)
so to do a header file check for example
check_include_file(somefile.h HAVE_SOMEFILE_H)
if the above is true
use the execute_process()
to add a line (for example ) like so :-
--------------
cat>>config.h.cmake<<"EOF"
#define HAVE_SOMEFILE_H 1
EOF
--------------
then repeat for other checks{and custom checks}
adding compile definitions (to the appropriate CMakeLists,txt file) as
required
then in the end use configure_file() to transform this file in to the required
config.h
luxInteg
2011-01-29 20:02:18 UTC
Permalink
Post by Michael Jackson
I _think_ there are issues with generating a file that is later used by
CMake. I think. The other issue is that every time you run CMake (by
default) that file is going to be written, then configured by cmake which
will most likely mean a larger recompile than might be necessary.
I don't see the problem here. Most projects just have a one-to-one
relationship between the tests that they perform such as looking for
include files, and the entries in their configuration file.
So if you do a test looking for <sys/types.h> then you would also have an
Yes, this has a large initial "coming up to speed" but once you have it
adding a few more tests is simple and fast.
Thanks for the advice, Progress so far:-


A decenT config.h file is generated as per the instructions you provided.

here is the major parts of it:-
#######################
/*--------------------------------------------------------------------------
* This file is autogenerated from config.h.in
* during the cmake configuration of your project. If you need to make changes
* edit the original file NOT THIS FILE.
* --------------------------------------------------------------------------
*/
#ifndef _CONFIGURATION_HEADER_GUARD_H_
#define _CONFIGURATION_HEADER_GUARD_H_

/* Disable deprecated functions and enums while building */
#define GSL_DISABLE_DEPRECATED 1

/* Define if you have inline with C99 behavior */
#define HAVE_C99_INLINE HAVE_C99_INLINE 0
/* Define to 1 if you have the declaration of `acosh', and to 0 if you don't.
*/
#define HAVE_DECL_ACOSH HAVE_DECL_ACOSH 1

/* Define to 1 if you have the declaration of `asinh', and to 0 if you don't.
*/
#define HAVE_DECL_ASINH HAVE_DECL_ASINH 1

/* Define to 1 if you have the declaration of `atanh', and to 0 if you don't.
*/
#define HAVE_DECL_ATANH HAVE_DECL_ATANH 1

/* Define to 1 if you have the declaration of `expm1', and to 0 if you don't.
*/
#define HAVE_DECL_EXPM1 HAVE_DECL_EXPM1 1

/* Define to 1 if you have the declaration of `feenableexcept', and to 0 if
you don't. */
#define HAVE_DECL_FEENABLEEXCEPT HAVE_DECL_FEENABLEEXCEPT 1

/* Define to 1 if you have the declaration of `fesettrapenable', and to 0 if
you don't. */
#define HAVE_DECL_FESETTRAPENABLE HAVE_DECL_FESETTRAPENABLE 0

/* Define to 1 if you have the declaration of `finite', and to 0 if you don't.
*/
#define HAVE_DECL_FINITE HAVE_DECL_FINITE 1

/* Define to 1 if you have the declaration of `frexp', and to 0 if you don't.
*/
#define HAVE_DECL_FREXP HAVE_DECL_FREXP 1

/* Define to 1 if you have the declaration of `hypot', and to 0 if you don't.
*/
#define HAVE_DECL_HYPOT HAVE_DECL_HYPOT 1

/* Define to 1 if you have the declaration of `isfinite', and to 0 if you
don't. */
#define HAVE_DECL_ISFINITE HAVE_DECL_ISFINITE 1

/* Define to 1 if you have the declaration of `isinf', and to 0 if you don't.
*/
#define HAVE_DECL_ISINF HAVE_DECL_ISINF 1

/* Define to 1 if you have the declaration of `isnan', and to 0 if you don't.
*/
#define HAVE_DECL_ISNAN HAVE_DECL_ISNAN 1

/* Define to 1 if you have the declaration of `ldexp', and to 0 if you don't.
*/
#define HAVE_DECL_LDEXP HAVE_DECL_LDEXP 1

/* Define to 1 if you have the declaration of `log1p', and to 0 if you don't.
*/
#define HAVE_DECL_LOG1P HAVE_DECL_LOG1P 1

/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H HAVE_DLFCN_H 1

/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
#define HAVE_DOPRNT HAVE_DOPRNT 0

/* Defined if you have ansi EXIT_SUCCESS and EXIT_FAILURE in stdlib.h */
#define HAVE_EXIT_SUCCESS_AND_FAILURE HAVE_EXIT_SUCCESS_AND_FAILURE 1

/* Defined on architectures with excess floating-point precision */
#define HAVE_EXTENDED_PRECISION_REGISTERS HAVE_EXTENDED_PRECISION_REGISTERS 1

/* Define if x86 processor has sse extensions. */
#define HAVE_FPU_X86_SSE HAVE_FPU_X86_SSE 1

/* Define to 1 if you have the <ieeefp.h> header file. */
#define HAVE_IEEEFP_H HAVE_IEEEFP_H 0

/* Define this if IEEE comparisons work correctly (e.g. NaN != NaN) */
#define HAVE_IEEE_COMPARISONS HAVE_IEEE_COMPARISONS 1

/* Define this if IEEE denormalized numbers are available */
#define HAVE_IEEE_DENORMALS HAVE_IEEE_DENORMALS 1

/* Define if you have inline */
#define HAVE_INLINE HAVE_INLINE 0

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H HAVE_INTTYPES_H 1

/* Define to 1 if you have the `m' library (-lm). */
#define HAVE_LIBM HAVE_LIBM 1

/* Define to 1 if you have the `memcpy' function. */
#define HAVE_MEMCPY HAVE_MEMCPY 1

/* Define to 1 if you have the `memmove' function. */
#define HAVE_MEMMOVE HAVE_MEMMOVE 1

/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H HAVE_MEMORY_H 1

/* Define this if printf can handle %Lf for long double */
#define HAVE_PRINTF_LONGDOUBLE HAVE_PRINTF_LONGDOUBLE 1

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H HAVE_STDINT_H 1

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H HAVE_STDLIB_H 1

/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP HAVE_STRDUP 1

/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H HAVE_STRINGS_H 1

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H HAVE_STRING_H 1

/* Define to 1 if you have the `strtol' function. */
#define HAVE_STRTOL HAVE_STRTOL 1

/* Define to 1 if you have the `strtoul' function. */
#define HAVE_STRTOUL HAVE_STRTOUL 1

/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H HAVE_SYS_STAT_H 1

/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H HAVE_SYS_TYPES_H 1

/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H HAVE_UNISTD_H 1

/* Define to 1 if you have the `vprintf' function. */
#define HAVE_VPRINTF HAVE_VPRINTF 1

/* Define if you need to hide the static definitions of inline functions */
#define HIDE_INLINE_STATIC HIDE_INLINE_STATIC 0

/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR LT_OBJDIR 0




/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1

-------
-------
/* Define to 1 if type `char' is unsigned and you are not using gcc. */
#ifndef __CHAR_UNSIGNED__
# undef __CHAR_UNSIGNED__
#endif

/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
#define inline 0
#endif

/* Define to `unsigned int' if <sys/types.h> does not define. */
#define size_t 0

/* Define to empty if the keyword `volatile' does not work. Warning: valid
code using `volatile' can become incorrect without. Disable with care. */
#define volatile 0



/* Define one of these if you have a known IEEE arithmetic interface */
------
------
#define HAVE_GNUX86_IEEE_INTERFACE HAVE_GNUX86_IEEE_INTERFACE 1

--------
#if HAVE_EXTENDED_PRECISION_REGISTERS
#define GSL_COERCE_DBL(x) (gsl_coerce_double(x))
#else
#define GSL_COERCE_DBL(x) (x)
#endif

------
-----

#endif

################################

the bad news is there is a troublesome section (the last shown) therein
leading to cmake errors shown below:-



----------- snippet from the cmake output

~TESTS/gsl-1.14/sys/minmax.c
In file included from ~/sys/minmax.c:20:
~/build/config.h:16:1: warning: "HAVE_DECL_ACOSH" redefined
<command-line>: warning: this is the location of the previous definition
~/build/config.h:20:1: warning: "HAVE_DECL_ASINH" redefined
<command-line>: warning: this is the location of the previous definition
~/build/config.h:24:1: warning: "HAVE_DECL_ATANH" redefined
<command-line>: warning: this is the location of the previous definition
~/build/config.h:28:1: warning: "HAVE_DECL_EXPM1" redefined
<command-line>: warning: this is the location of the previous definition
~/build/config.h:32:1: warning: "HAVE_DECL_FEENABLEEXCEPT" redefined
<command-line>: warning: this is the location of the previous definition
~/build/config.h:48:1: warning: "HAVE_DECL_HYPOT" redefined
<command-line>: warning: this is the location of the previous definition
~/build/config.h:52:1: warning: "HAVE_DECL_ISFINITE" redefined
<command-line>: warning: this is the location of the previous definition
~/build/config.h:68:1: warning: "HAVE_DECL_LOG1P" redefined
<command-line>: warning: this is the location of the previous definition
~/build/config.h:77:1: warning: "HAVE_EXIT_SUCCESS_AND_FAILURE" redefined
<command-line>: warning: this is the location of the previous definition
~/build/config.h:89:1: warning: "HAVE_IEEE_COMPARISONS" redefined
<command-line>: warning: this is the location of the previous definition
~/build/config.h:92:1: warning: "HAVE_IEEE_DENORMALS" redefined
<command-line>: warning: this is the location of the previous definition
~/build/config.h:113:1: warning: "HAVE_PRINTF_LONGDOUBLE" redefined
<command-line>: warning: this is the location of the previous definition
~/build/config.h:200:1: warning: "inline" redefined
<command-line>: warning: this is the location of the previous definition


~/build/config.h:245:5: error: missing binary operator before token "1"



############
line 245 is this line
#if HAVE_EXTENDED_PRECISION_REGISTERS

Si I am perplexed where this '1' came from or indeed which '1' is being
referred to

advice would be appreciaed.

sincerely
luxInteg
Rolf Eike Beer
2011-01-29 19:20:49 UTC
Permalink
Post by luxInteg
~/build/config.h:245:5: error: missing binary operator before token "1"
############
line 245 is this line
#if HAVE_EXTENDED_PRECISION_REGISTERS
Si I am perplexed where this '1' came from or indeed which '1' is being
referred to
You probably have named your CMake variable this way, too. CMake replaced
the name of the variable in the template with the value of the variable.

You should go read about @ONLY and #cmakedefine to get your config.h.in
safe for these type of errors.

Eike

Loading...