[CMake] Creating subdirectories from within CMake

Alan W. Irwin irwin at beluga.phys.uvic.ca
Tue Sep 30 11:44:56 EDT 2008


On 2008-09-30 13:28-0000 Leo Breebaart wrote:

> I have some third party non-CMake-configured source packages I
> want to include in my CMake project and apply a CMake 'wrapper'
> to.
>
> So, for example, in case of software package 'foo', I would like
> to unpack the original foo-src/foo.tar.gz archive into directory
> foo/, copy my own custom foo-src/CMakeLists.txt into foo/ as
> well, and then process foo/ itself further with CMake using
> add_subdirectory(foo).
>
> Unfortunately, the add_subdirectory(foo) statement always causes
> CMake to complain that directory 'foo' does not exist, even
> though I have created a working custom_target for 'foo' that will
> actually create it.

That's your problem in a nutshell.  A custom target only runs its commands
at build time to create and populate the subdirectory, not at the earlier
time when cmake is executed.

However, there is hope.  You can run any command at cmake time with
execute_process.  Furthermore, there is no need to use that powerful command
for everything you want to do.  For example, you can create directories at
cmake time using file(MAKE_DIRECTORY...).  In sum, I have never tried what
you want to do, but so long as you stick to commands that work immediately
at cmake time such as execute_process, file, etc., I think you should be
fine so long as those commands to immediately create and populate the
subdirectory appear in the CMakeLists.txt file before the add_subdirectory
command for that created subdirectory.

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
__________________________


More information about the CMake mailing list