config.h.cmake issue ?
Ralf Habacker
ralf.habacker at freenet.de
Wed May 3 15:32:44 CEST 2006
Hi all,
in recent cmake releases it is required to setup two places in case C defines are required.
One place is the ...h.cmake and one the related CMakeLists.txt or Find...cmake module.
One example:
in kdelibs/kjs/CMakeLists.txt there is:
macro_optional_find_package(PCRE)
if(PCRE_FOUND)
set(HAVE_PCREPOSIX 1)
else(PCRE_FOUND)
set(HAVE_PCREPOSIX 0)
endif(PCRE_FOUND)
# Generate global.h
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/global.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/global.h )
in kdelibs/kjs/global.h.cmake there is
#cmakedefine HAVE_PTHREAD_ATTR_GET_NP 1
#cmakedefine HAVE_PTHREAD_GETATTR_NP 1
#cmakedefine HAVE_PCREPOSIX 1
The problem is that if someone forgets to add this constants the resulting errors are hards to detect.
Another example I encountered was the preparation of the CMakeLists.txt for a dbus test build. I took the config.h.cmake from kdecore and added it to the dbus sources. Now I had to disable all not required #cmakedefine by hand, which wasn't very easy to detect. And if I had forgotten one, this was only detected by an compiler error, so this ends up in an iterative process until i had fixed this area.
Now imagine there is an developer, who adds stuff to a package which uses cmake and it new to cmake. He adds and Find....cmake from another package and is thinking, thats all, but unfortunally he had to add the #cmakedefine by hand, which will be probably forgotten after a time not working with the build system.
In scons/bksys or the successor waf I think there is a better way for this. See the below mentioned example.
# create a config instance
conf = Configure.Configure()
# add config define by hand
conf.addDefine('HAVE_MY_DEFINE',1)
#check one header an set default define ('HAVE_TEST_H') in internal array if test.h found
conf.checkHeader('test.h')
#check one header and set HAVE_SPECIFIC_TEST_H in internal array if test.h found
conf.checkHeader('test.h','HAVE_SPECIFIC_TEST_H')
#check for library z using function compress and an set HAVE_COMPRESS in internal array if library was found
conf.checkLibrary('z','compress','HAVE_COMPRESS')
# write all HAVE_ defines since config instance creating into config.h
conf.writeConfigHeader('config.h')
Because I'm not very deeply knowledged about cmake internals I don't
know who such a support should be implemented best, but maybe by using a
second parameter in macro_optional_find_package()
macro_optional_find_package(PCRE,HAVE_PCREPOSIX)
or similar functions
Then configure_file(${CMAKE_CURRENT_SOURCE_DIR}/global.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/global.h ) would take all this HAVE_ defines and write it into global.h. Maybe in global.h.cmake there will be a #cmakedefines construct required to activate this support, i don't know.
One open problem i haven't a solution is for is about overlapping definitions. In the above waf example all symbols since creating the config instance were written into the config header and not more. To differentiate two config headers a second object or recreating the same object variable does the job.
In kdelibs this may be possible between the config.h and kjs/global.h
Just my 2 cent
Ralf
More information about the Kde-buildsystem
mailing list