[Cmake] Comments, questions from my first CMake'd app

Andy Cedilnik andy.cedilnik at kitware.com
Tue Mar 18 17:20:04 EST 2003


Hi Ian,

On Tue, 2003-03-18 at 17:05, Ian Main wrote:
> First off I'd like to thank the authors for their efforts! Thanks!
> It can be a real pain dealing with all these different build systems.
> 
> So, I've got a few projects that I am thinking of moving to CMake
> from auto*.  The first one is a utility library for C, kind of like
> glib.
> 
> I am in the process of converting everything that auto* does to
> be done by CMake.
> 
> I've had a relatively easy go of it in general, and have gotten
> most things working.
> 
> I had a few little problems with some things.  The return from
> 
> INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
> CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H)
> 
> will set HAVE_SYS_TYPES_H to 1 if it exists, or nothing if it
> does not.  This makes it hard to use in a config.h.in style
> arrangement, as you have to do funky #if stuff.  I am
> currently using:
> 
> #if 0 at HAVE_SYS_TYPES_H@
> #define HAVE_SYS_TYPES_H 1
> #endif
> 
> which will make the first line '#if 0' or '#if 01' depending
> on the result.  This works but it's a bit hackish.  Note that
> you can't just do:
> 
> #define HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ because then when
> you test for it you have to use #if still, and you end up 
> with the same problem.
> 
> It would be much better if that macro returned 1 if found, and
> 0 if not found.  Same for the library tests etc.
> 
> Of course, I may be missing something obvious, please tell me
> if I am! :)

Try #cmakedefine VAR ${VAR} or #cmakedefine VAR @VAR@, whatever you
prefer.

> The problem I am currently stumped on is getting a 'config'
> shell script to install as executable on unix.  I am generating
> a roy-config shell script from roy-config.in, which when run
> outputs the CFLAGS, libs etc needed to link with roy (just
> like gtk, glib etc. use).

Use INSTALL_PROGRAM(/bin roy-config).

> INSTALL_FILES of course installs as mode 644, and I can't
> get INSTALL_PROGRAMS to install it.  I am guessing this could
> be a problem for anyone doing any kind of scripts that
> require that they be installed executable.


> The last thing I am unsure of is how to do custom build commands.
> I have a set of pod files that I use to generate manpages.. not
> sure how to go about that one.

Use ADD_CUSTOM_COMMAND. For example:

# Need a custom target
ADD_CUSTOM_TARGET(ManPages ALL)

# Need a rule to generate GenerateManPage.1 from GeneratedManPageInput
ADD_CUSTOM_COMMAND(TARGET ManPages
                   SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/GeneratedManPageInput
COMMAND whatever_command
ARGS arguments_to_command -o
${CMAKE_CURRENT_BINARY_DIR}/GeneratedManPage.1
${CMAKE_CURRENT_SOURCE_DIR}/GeneratedManPageInput
OUTPUTS ${CMAKE_CURRENT_SOURCE_DIR}/GeneratedManPageInput)

# This one will drive the previous one
ADD_CUSTOM_COMMAND(TARGET ManPages
                   SOURCE ManPages
                   DEPENDS GeneratedManPage.1)


> If I can get this all working, I may write a tutorial for CMake
> as it seems there is a lack of documentation.  The reference is
> good but you're kind of left using your imagination a lot as to
> how things should be used, and what the most portable way to do
> things is.

That would be cool. 

			Andy




More information about the CMake mailing list