[CMake] cmake config.h
Michael Jackson
mike.jackson at bluequartz.net
Wed Jan 26 14:07:57 EST 2011
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 mike.jackson at bluequartz.net
BlueQuartz Software Dayton, Ohio
On Jan 26, 2011, at 3:03 PM, luxInteg wrote:
> On Tuesday 25 January 2011 03:32:36 luxInteg wrote:
>> On Sunday 28 November 2010 16:03:33 luxInteg wrote:
>>> 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
More information about the CMake
mailing list