[CMake] Dependencies

Chris Scharver scharver at evl.uic.edu
Wed Oct 20 14:24:27 EDT 2004


On Oct 20, 2004, at 10:13 AM, William A. Hoffman wrote:

> If Lib_A does not exist, i.e. the first time build, cmake makefiles 
> will
> jump over and build Lib_A.  But if you want it to always check, then
> you must run make from project_root.  Otherwise the make would be 
> jumping all over
> the place and check depend info too much.  All that being said, at 
> some point
> we are going to try not using recursive make, and having one big 
> makefile that
> drives everything, and all these issues may go away.

I'm having a similar problem with ADD_CUSTOM_COMMAND. I have several 
models files in a directory parallel to my source code. I want to copy 
all model files into a models directory within the build destination. 
This parallel layout works well with libraries and executables, but I 
can't seem to get it to work for copying files. Does ADD_CUSTOM_COMMAND 
track dependencies differently than TARGET_LINK_LIBRARIES?
Here's the source layout:

project
project/models
project/src

The top-level CMakeLists.txt lists the models and src directories as 
SUBDIRS. The models should only be copied if the source target was 
built. Here's the relevant portion from models/CMakeLists.txt:

# Use GLOB to grab all the model files
FILE(GLOB MODEL_FILES *.iv *.jpg)

# Copy each model file to the build directory.
MAKE_DIRECTORY(${EXECUTABLE_OUTPUT_PATH}/models)
FOREACH(modelfile ${MODEL_FILES})
   ADD_CUSTOM_COMMAND(TARGET project_target POST_BUILD
     COMMAND ${CMAKE_COMMAND}
     ARGS -E copy_if_different ${modelfile}
     ${EXECUTABLE_OUTPUT_PATH}/models/
     )
ENDFOREACH(modelfile)

The generated Makefile doesn't contain anything for copying files. Is 
this due to the fact that the models directory cannot properly detect 
the dependency on the project_target specified in the src directory? Or 
does TARGET and POST_BUILD not work for Makefiles? If I instead use:

   ADD_CUSTOM_COMMAND(OUTPUT "${modelfile}"
     COMMAND ${CMAKE_COMMAND}
     ARGS -E copy ${modelfile}
     ${EXECUTABLE_OUTPUT_PATH}/models/
     MAIN_DEPENDENCY ${EXECUTABLE_OUTPUT_PATH}/targetedreaching
     )

I see the commands in the generated Makefiles, but they never execute. 
I'm always running make from the project root build directory.

Chris
--
Chris Scharver
Electronic Visualization Laboratory
The University of Illinois at Chicago
Ph: 312-996-3002   FAX: 312-413-7585
<http://www.evl.uic.edu/scharver/>



More information about the CMake mailing list