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

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Christopher E Robison
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




--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to have build steps operate on files in a copied directory?

Michael Ellery

> On Jul 10, 2017, at 10:46 AM, Christopher E Robison <[hidden email]> 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



--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to have build steps operate on files in a copied directory?

Christopher E Robison
The INSTALL(SCRIPT ...) syntax might be just the answer I need, thanks!. 

As I mentioned, the index creating script in the custom step needs to operate on the copied directory tree in its final location, so if it's not all there yet it will fail.  So, if CMake has some distinction between "build" and "install"  (I'm familiar with Makefiles, where the syntax enforces no such separation -- just targets, dependencies, and commands), then this would mean the step has to be executed at the end of the "install" phase.

Can I specify somehow that this install command must be executed after the INSTALL(DIRECTORY ...) command has completed?


Thanks,
CR


On Mon, Jul 10, 2017 at 6:04 PM, Michael Ellery <[hidden email]> wrote:

> On Jul 10, 2017, at 10:46 AM, Christopher E Robison <[hidden email]> 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





--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to have build steps operate on files in a copied directory?

Michael Ellery

> On Jul 10, 2017, at 11:19 AM, Christopher E Robison <[hidden email]> wrote:
>
> The INSTALL(SCRIPT ...) syntax might be just the answer I need, thanks!.  
>
> As I mentioned, the index creating script in the custom step needs to operate on the copied directory tree in its final location, so if it's not all there yet it will fail.  So, if CMake has some distinction between "build" and "install"  (I'm familiar with Makefiles, where the syntax enforces no such separation -- just targets, dependencies, and commands), then this would mean the step has to be executed at the end of the "install" phase.
>
> Can I specify somehow that this install command must be executed after the INSTALL(DIRECTORY ...) command has completed?
>
>
> Thanks,
> CR
>
>

I *believe* the install directives are executed in the order they are encountered in the processing of CMakeLists files, so putting the custom step as the last item in your top level CMake file might do the trick.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to have build steps operate on files in a copied directory?

Christopher E Robison
It appears to be so -- the install directives execute in incident order, at least from within a single CMakeLists.txt file.

The solution ended up being INSTALL(CODE "execute_process(COMMAND ...)"). Feels like a bit of a hack, but the install works on two different platforms -- I'm satisfied for now.

Thanks again for the help!

CR




On Mon, Jul 10, 2017 at 6:25 PM, Michael Ellery <[hidden email]> wrote:

> On Jul 10, 2017, at 11:19 AM, Christopher E Robison <[hidden email]> wrote:
 
> Can I specify somehow that this install command must be executed after the INSTALL(DIRECTORY ...) command has completed?

I *believe* the install directives are executed in the order they are encountered in the processing of CMakeLists files, so putting the custom step as the last item in your top level CMake file might do the trick.




--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Loading...