[CMake] How to have build steps operate on files in a copied directory?

Michael Ellery mellery451 at gmail.com
Mon Jul 10 14:04:26 EDT 2017


> On Jul 10, 2017, at 10:46 AM, Christopher E Robison <cerobison at utexas.edu> wrote:
> 
> I've recently begun using CMake on an existing project I've taken over, and I feel like I'm mostly getting used to it, though there is still a vast amount to learn.  I've got nearly the entire project building successfully, with the exception of a directory of external scripts that need to be configured at the end of the install process to create some index files.
> 
> So, in a nutshell, there's a script that takes care of this post-install configuration, that needs to be executed once the target tree of directories and script files are in place, copied from the source tree. And I'm finding that when the script is called during the build, the INSTALL(DIRECTORY ...) command from the CMakeLists.txt directory hasn't been run yet, so the tree of script files hasn't been put in place yet and the script (and the build) fails.
> 
> FWIW, if I leave out the add_custom_command and add_custom_target that execute the script, the directory tree does copy correctly.
> 
> I have not found any guidance on how to specify that the directory tree gets copied first. How is this normally done?
> 
> 
> Thanks,
> CR
> 
> 
> 

I think you might be getting confused by two distinct phases: BUILD and INSTALL.

BUILD is what happens when building your sources and all the results of this step are in your build directory (or source directory if you do in-source building). Both add_custom_command and add_custom_target are evaluated (and potentially executed) at BUILD time.  The BUILD phase is what is processed when you just do “make” in Makefile terms.

INSTALL is what happens when you request your project to be installed. The various install() directives in your CMake files will be processed during INSTALL. In Makefile terms, this what happens when you do “make install” (BUILD is also done in that case since INSTALL always depends on BUILD)

So the first question is: does this custom step need to be done at BUILD time or INSTALL time? Running custom code is easier at BUILD time since you have the add_custom_command and the like. If you need to run custom code at INSTALL time, maybe consider this:

https://stackoverflow.com/questions/41254902/cmake-run-script-for-install-target

…although I have not done something like this myself. I suspect it is difficult to get just right, depending on the various platforms you support.

Does that make sense?

-Mike 





More information about the CMake mailing list