[CMake] Building ADD_CUSTOM_TARGET dependency

Alex Brooks a.brooks at acfr.usyd.edu.au
Mon Nov 14 09:02:14 EST 2005


Hi,

I've used CMake for a while now, but I can't seem to do the following kinda 
complicated task:
[ I'm using CMake version 2.2.2 ]


(1): ADD_CUSTOM_TARGET definition
================================

I want to generate .cfg files from .def files using the following macro:

MACRO( GENERATE_FROM_DEF DEF_FILE )
  STRING( REGEX REPLACE "\\.def" ".cfg" CFG_FILE ${DEF_FILE} )
  ADD_CUSTOM_TARGET( 
    ${CFG_FILE} ALL
    generatecfg ${DEF_FILE} ${CFG_FILE}
    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${DEF_FILE} generatecfg )
ENDMACRO( GENERATE_FROM_DEF DEF_FILE )

The problem is that generatecfg is a c++ executable that has to be compiled 
first.  That's why I put it as a dependency (the last term in 
ADD_CUSTOM_TARGET above).

(2): generatecfg taget definition
==========================

The generatecfg target is defined as follows (in 
src/utils/liborcadefutil/orcadefutil/):

INCLUDE_DIRECTORIES( ${PROJ_SOURCE_DIR}/src/utils/liborcadefutil )
ADD_LIBRARY( OrcaDefUtil SHARED defparser.cpp componentdefinition.cpp )
ADD_EXECUTABLE( generatecfg generatecfg.cpp )
TARGET_LINK_LIBRARIES( generatecfg OrcaDefUtil )

The important bit here is the INCLUDE_DIRECTORIES line, which is required to 
build generatecfg.cpp.

(3): generatecfg use
=================

At some point (from src/components/lasermon) I call the macro:

GENERATE_FROM_DEF( lasermon.def )

This command relies on generatecfg.  From (1), CMake knows that generatecfg 
has to be built first.  So if I try to compile from the 
src/components/lasermon directory I get:

$ cd src/components/lasermon
$ make VERBOSE=1

<snip>
make[3]: Entering directory `/home/users/a.brooks/cvs/orca2'
/home/users/a.brooks/bin/g++     
src/utils/liborcadefutil/orcadefutil/generatecfg.cpp   -o 
src/utils/liborcadefutil/orcadefutil/generatecfg
src/utils/liborcadefutil/orcadefutil/generatecfg.cpp:1:35: 
orcadefutil/defparser.h: No such file or directory
<snip>

The problem is that when compiling generatecfg, CMake seems to have neglected 
to add "-Isrc/utils/liborcadefutil/orcadefutil/".  It should have done this 
from the "INCLUDE_DIRECTORIES( ${PROJ_SOURCE_DIR}/src/utils/liborcadefutil )" 
line in (2).

Does anyone know what's happening here?  I've been battling with this for a 
while...


Thanks very much,

Alex


More information about the CMake mailing list