[CMake] Creating subdirectories from within CMake

Leo Breebaart leo at lspace.org
Tue Sep 30 09:28:10 EDT 2008


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. (I know, I know -- it was naive of me to
expect that the argument to add_subdirectory() would be itself
interpreted as a target.)

Is there any way to have CMake create a directory, and *then*
process that directory as a subdirectory, in a single pass? I can
do the unpacking unconditionally in an 'execute_process()' call,
but one of the goals of the exercise is to have CMake use
dependency information and *only* unpack foo.tar.gz if (a) either
foo/ does not exist yet, or (b) foo.tar.gz itself or the custom
CMakeLists.txt file have changed.

Does anybody here have any suggestions for me?

-- 
Leo Breebaart  <leo at lspace.org>



More information about the CMake mailing list