[Cmake] ADD_CUSTOM_TARGET and SUBDIRS
Brad King
brad . king at kitware . com
Tue, 30 Sep 2003 09:37:50 -0400 (EDT)
On 29 Sep 2003, Anton Deguet wrote:
> Hello,
>
> I would like to create the same custom target in many subdirs and be
> able to make the target from the parent directory:
>
> -- parent directory with CMakeLists.txt <p>
> |-- subdir1 with CMakeLists.txt <1>
> `-- subdir2 with CMakeLists.txt <2>
>
> All my CMakeLists in subdirs (1 and 2) have an
> ADD_CUSTOM_TARGET(install_html ${BASH} myScript.sh).
>
> How can I have a target in the parent CMakeLists.txt so that I can type
> "make install_html" which does nothing but make the target
> "install_html" in all the subdirectories?
I'm not aware of any way to do this right now. The reason is that custom
targets are not just a way of adding arbitrary rules to a Makefile when
using the "UNIX Makefiles" generator. They need to be supported by all
generators. Other generators do not have a notion of "subdirectories" in
the build tree.
What you can do instead is use CONFIGURE_FILE or FILE(WRITE ...) in each
CMakeLists.txt file to create a file called something like
install_html.config in each directory in the build tree. Then have one
install_html custom target at the top level that runs your script to
traverse the treee looking for install_html.config files to tell it what
to install.
One of our feature-requests in the bug tracker is to add more complete
installation support. If this is ever implemented, your problem will
hopefully go away anyway.
-Brad