[CMake] Building ADD_CUSTOM_TARGET dependency

Alex Brooks a.brooks at acfr.usyd.edu.au
Tue Nov 15 03:15:41 EST 2005


Thanks for the quick reply.

On Tue, 15 Nov 2005 01:37 am, you wrote:
> You may want to look here:
>
> http://public.kitware.com/Wiki/CMake_FAQ#How_can_I_generate_a_source_file_d
>uring_the_build.3F

I read this and I think I understand it.  I seem to have all the dependencies 
set up correctly, the problem is just the '-I' flags that aren't being sent 
to the compiler.  

I have a solution now so it's not a problem, but here's what I needed to do 
just in case it's a bug or if anyone else has the same problem.

=================================

I managed to characterize thing a bit better by merging into just two 
CMakeLists.txt files:

(1) src/utils/liborcadefutil/orcadefutil/CMakeLists.txt:

-------------------------------------
# Build generatecfg
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 )
-------------------------------------

(2) src/components/lasermon/CMakeLists.txt:

-------------------------------------
SET( GENERATE_CFG_SOURCE_DIR 
${PROJ_SOURCE_DIR}/src/utils/liborcadefutil/orcadefutil )

SET( GENERATE_CFG_BINARY_DIR 
${PROJ_BINARY_DIR}/src/utils/liborcadefutil/orcadefutil )

# Add the lasermon.def -> lasermon.cfg generation rule
SET( GENERATE_CFG_EXE ${GENERATE_CFG_BINARY_DIR}/generatecfg )
ADD_CUSTOM_TARGET( 
  lasermon.cfg ALL
  ${GENERATE_CFG_EXE} lasermon.def lasermon.cfg
  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lasermon.def ${GENERATE_CFG_EXE} )
-------------------------------------

When I type 'make VERBOSE=1 lasermon.cfg' it tries to build generatecfg with:
/home/users/a.brooks/bin/g++     
src/utils/liborcadefutil/orcadefutil/generatecfg.cpp   -o 
src/utils/liborcadefutil/orcadefutil/generatecfg
(note no '-I's)

If I instead use:

ADD_CUSTOM_TARGET( 
  lasermon.cfg ALL
  ${GENERATE_CFG_EXE} lasermon.def lasermon.cfg
  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lasermon.def ${GENERATE_CFG_EXE} )

I get the same.

However if I managed to get it to work using:

  ADD_CUSTOM_TARGET( 
    lasermon.cfg ALL
    ${GENERATE_CFG_EXE} lasermon.def lasermon.cfg
    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lasermon.def )
  ADD_DEPENDENCIES( lasermon.cfg generatecfg )

(ie adding the extra ADD_DEPENDENCIES rule fixes things)

If I type 'make VERBOSE=1 lasermon.cfg' I then get the desired:

Building CXX object 
src/utils/liborcadefutil/orcadefutil/CMakeFiles/OrcaDefUtil.dir/defparser.o
/home/users/a.brooks/bin/g++  -DOrcaDefUtil_EXPORTS   -g -fPIC 
-I/home/users/a.brooks/orca2/src/utils/liborcadefutil   -Wall -o 
src/utils/liborcadefutil/orcadefutil/CMakeFiles/OrcaDefUtil.dir/defparser.o 
-c /home/users/a.brooks/orca2/src/utils/liborcadefutil/orcadefutil/defparser.cpp
... etc ...

Not sure why the extra rule is needed.


Cheers,

Alex


> At 09:02 AM 11/14/2005, Alex Brooks wrote:
> >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
> >_______________________________________________
> >CMake mailing list
> >CMake at cmake.org
> >http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list