On 7/29/10 5:40 PM, Michael Jackson wrote:
Well luckily there are a whole slew of projects to take a look at. HDF5 is one. CMake, VTK, ITK, ParaView are some others. Basically you have a .cmake file that runs all the tests like looking for headers, structs, functions and stuff like that. Each result is put into a cmake variable. Then after all of that is completed you "configure_file(...)" using your .h.in file as input.

#  test.cmake example
# --------------------------------------------------------------------
#  Now check for needed Header files
# --------------------------------------------------------------------
INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
macro (CORE_CHECK_INCLUDE_FILE header var prefix)
    CHECK_INCLUDE_FILE("${header}"        ${prefix}_${var} )
endmacro()

CORE_CHECK_INCLUDE_FILE("stddef.h"        HAVE_STDDEF_H   MXA)
CORE_CHECK_INCLUDE_FILE("stdint.h"        HAVE_STDINT_H   MXA)
CORE_CHECK_INCLUDE_FILE("stdlib.h"        HAVE_STDLIB_H   MXA)
CORE_CHECK_INCLUDE_FILE("setjmp.h"        HAVE_SETJMP_H   MXA)
CORE_CHECK_INCLUDE_FILE("string.h"        HAVE_STRING_H   MXA)
CORE_CHECK_INCLUDE_FILE("stdio.h"         HAVE_STDIO_H   MXA)
CORE_CHECK_INCLUDE_FILE("math.h"          HAVE_MATH_H   MXA)
CORE_CHECK_INCLUDE_FILE("time.h"          HAVE_TIME_H   MXA)
CORE_CHECK_INCLUDE_FILE("sys/time.h"      HAVE_SYS_TIME_H   MXA)
CORE_CHECK_INCLUDE_FILE("sys/types.h"     HAVE_SYS_TYPES_H   MXA)
CORE_CHECK_INCLUDE_FILE("sys/socket.h"    HAVE_SYS_SOCKET_H   MXA)
CORE_CHECK_INCLUDE_FILE("sys/stat.h"      HAVE_SYS_STAT_H   MXA)
CORE_CHECK_INCLUDE_FILE("netinet/in.h"    HAVE_NETINET_IN_H   MXA)
CORE_CHECK_INCLUDE_FILE("arpa/inet.h"     HAVE_ARPA_INET_H   MXA)
CORE_CHECK_INCLUDE_FILE("unistd.h"        HAVE_UNISTD_H   MXA)
CORE_CHECK_INCLUDE_FILE("fcntl.h"         HAVE_FCNTL_H   MXA)
CORE_CHECK_INCLUDE_FILE("errno.h"         HAVE_ERRNO_H   MXA)

configure_file (Conf.h.in Conf.h @ONLY)
#--- End test.cmake file


// Example Conf.h.in file
/* Define to 1 if you have the <stddef.h> header file. */
#cmakedefine MXA_HAVE_STDDEF_H @MXA_HAVE_STDDEF_H@

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

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

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

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

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

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

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

/* Define to 1 if you have the <sys/time.h> header file. */
#cmakedefine MXA_HAVE_SYS_TIME_H @MXA_HAVE_SYS_TIME_H@

/* Define to 1 if you have the <sys/types.h> header file. */
#cmakedefine MXA_HAVE_SYS_TYPES_H @MXA_HAVE_SYS_TYPES_H@

/* Define to 1 if you have the <sys/socket.h> header file. */
#cmakedefine MXA_HAVE_SYS_SOCKET_H @MXA_HAVE_SYS_SOCKET_H@

/* Define to 1 if you have the <netinet/in.h> header file. */
#cmakedefine MXA_HAVE_NETINET_IN_H @MXA_HAVE_NETINET_IN_H@

/* Define to 1 if you have the <arpa/inet.h> header file. */
#cmakedefine MXA_HAVE_ARPA_INET_H @MXA_HAVE_ARPA_INET_H@

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

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

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


at least that is how I do it.
___________________________________________________________
Mike Jackson                      www.bluequartz.net
Principal Software Engineer       mike.jack...@bluequartz.net
BlueQuartz Software               Dayton, Ohio

On Jul 29, 2010, at 6:25 PM, Clifford Yapp wrote:

I'm now at the point in writing CMake logic where I need to handle the
config.h.in situation, and either have missed the autoheader
equivalent functionality in CMake or it doesn't exist yet.  Can
anybody point me to the "right" approach to this?  I have so-far
found:

The #cmakedefine mechanism and the various CHECK_* functions, which
work fine but aren't autogenerated a.l.a autoheader

A 2009 discussion about autoheader-style functionality:
http://www.cmake.org/pipermail/cmake/2009-March/028293.html
http://www.cmake.org/pipermail/cmake/2009-April/028417.html

and a still-open item in the tracker from 2008:
http://www.cmake.org/Bug/view.php?id=6438&nbn=1

Has there been any recent work on this that I missed?  Our project has
quite a slew of these #defines created by autoheader, most of which
are apparently actually needed, so manually maintaining a list is
gonna be a bit of a tough sell.

Cheers, and any help appreciated,

CY
I think in this case, as in many cases, the initial work will be the hard part, figuring out which defines are useful to test and making that first config file. After that, maintaining it should be pretty easy (has been for me), since new dependencies or defines don't just appear, they usually come in with some intentional action. My workflow has been, after I add the first usage of a define, I go put it in the .in file. Then, when I need that code to compile (because usually it's a 'if I have this, then it's OK to compile this'), I'll look up how to detect that condition with CMake and add the check to the build. (A bit of the opposite from the auto* - figure out how to add the check to configure.in first, then run autoheader, then configure, then do the code using the define.)

Good luck! The switch is well worth it, especially as you start building a library of useful modules of functionality! (And, the docs are your friend, and keeping them open on a second monitor is a very good idea.)

Ryan

--
Ryan Pavlik
Human-Computer Interaction Graduate Student
Virtual Reality Applications Center
Iowa State University

rpav...@iastate.edu
http://academic.cleardefinition.com/

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to