[CMake] Dependencies for EXEC_PROGRAM

Neal Meyer nmeyer at dottedzebra.com
Tue Oct 2 15:04:58 EDT 2007


The CustomCommand works properly with the dependencies.  This issue I
was having was that I needed the output of a EXECUTE_PROCESS command
for the outputs of the CustomCommand.  Here is what I ended up
doing...

# Check to see if there are file already in the directory
# Copy the .xml file that generated the files into the gen directory
# so we can just compare time stamps on the two xml files.

IF(NOT EXISTS ${GEN_DIR}/${INPUT_FILENAME}.build OR
   ${CONFIG_DIR}/${INPUT_FILENAME} IS_NEWER_THAN
${GEN_DIR}/${INPUT_FILENAME}.build )

   MESSAGE( STATUS "Generating code from ${INPUT_FILENAME}" )
   EXECUTE_PROCESS( COMMAND perl  make_code.pl
               ${SCRIPT_ARGS}
               ERROR_VARIABLE EXEC_ERROR
               OUTPUT_QUIET
               )
   IF( "${EXEC_ERROR}" STREQUAL "" )
      FILE( WRITE ${GEN_DIR}/${INPUT_FILENAME}.build "DUMMY File" )
   ELSE( "${EXEC_ERROR}" STREQUAL "" )
      MESSAGE( FATAL_ERROR "${EXEC_ERROR}" )
   ENDIF( "${EXEC_ERROR}" STREQUAL "" )
    ENDIF(NOT EXISTS ${GEN_DIR}/${SPEC_FILENAME}.build OR
              ${CONFIG_DIR}/${SPEC_FILENAME} IS_NEWER_THAN
${GEN_DIR}/${INPUT_FILENAME}.build )

Basically I'm using the .build file to keep track of when the files
were last generated, so when the cmake file is run it just compares
the time-stamps and if the input file is newer then the one in the
generated code directory then it re-runs the script.  The custom
command that is used does GLOBBING of the output files to properly set
all of the outputs of the CUSTOM_COMMAND..

-Neal

On 10/1/07, Alan W. Irwin <irwin at beluga.phys.uvic.ca> wrote:
> On 2007-10-01 14:15-0700 Neal Meyer wrote:
>
> > I've got a static library that contains generated code, today this is
> > done in a make file so I can check the dependencies before the PERL
> > script is called again during the build process.  I'm adding a
> > CustomBuildCommand to the project, so the dependecies are properly
> > checked in my vcproj files.
> >
> > I'm wondering if anybody has any clues on how this might be done in a
> > CMake file.  Right now I just have EXEC_PROGRAM being called
> > everytime, which just addes some time to the processing that seems to
> > be a waste.
>
> First, EXEC_PROGRAM is deprecated in favour of EXECUTE_PROCESS, but both
> are normally executed at cmake time rather than run time so I don't think
> they are suitable for what you need.
>
> Second, look for GENERATED in the documentation to see one method of dealing
> with generated code.  However, I could not get that to work for the case of
> a library in one directory being dependent on code generated by a rule set
> up by a CMakeLists.txt file in a different directory.  The solution in that
> case was to have the library depend on a custom target in another directory.
> The custom target (see
> http://plplot.svn.sourceforge.net/viewvc/plplot/trunk/include/CMakeLists.txt?view=log)
> has no internal command, but instead file depends on a custom command which
> actually contains the command that generates the source code.  Furthermore,
> the custom command has the file dependencies of that command.  The result is
> the header in question is built only when needed which is what you want.
>
> Alan
> __________________________
> Alan W. Irwin
>
> Astronomical research affiliation with Department of Physics and Astronomy,
> University of Victoria (astrowww.phys.uvic.ca).
>
> Programming affiliations with the FreeEOS equation-of-state implementation
> for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
> package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
> Linux Links project (loll.sf.net); and the Linux Brochure Project
> (lbproject.sf.net).
> __________________________
>
> Linux-powered Science
> __________________________
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list