[CMake] [ADD_CUSTOM_COMMAND] How to add source dependences to the target ouside of the command?

Brad King brad.king at kitware.com
Sat Aug 26 13:34:39 EDT 2006


Tristan Carel wrote:
> The module `UseSwig' provided in the version 2.4.3 provides a macro
> named `SWIG_ADD_MODULE' to define a C/C++ library wrapped for one of
> the targets supported by Swig. This macro uses the command
> `ADD_CUSTOM_COMMAND' to define the rule as below:
> 
> wrapper.cxx: foo.i
>     swig [too many options] foo.i
> 
> But `foo.i' can include other files (.i, .h, ...) so `wrapper.cxx' 's
> build must depend to these other files too. I guess it can't be
> specified by using the macros provided by the module `SWIG_ADD_MODULE'

There are two kinds of dependencies: explicit and implicit.  Explicit
dependencies are those specified by CMake code by the user, known to
cmake, and generated explicitly into the build files.  Implicit
dependencies are those stored in the source of the input file such as
with #include statements.  For building C and C++ source files with the
compiler CMake knows how to do dependency scanning to automatically
account for these implicit dependencies.

Currently there is no way to handle implicit dependencies for custom
commands.  A huge technical challenge exists here: Visual Studio does
implicit dependency scanning for C and C++ sources automatically, but
does not seem to provide an interface for specifying custom command
dependency scanning.  This is why such a feature has not been added to
CMake.

Therefore any extra dependencies need to be specified explicitly.  CMake
currently does not have a way to add dependencies to custom commands
after the initial ADD_CUSTOM_COMMAND call and we will probably not add
one.  Calls to ADD_CUSTOM_COMMAND in a macro must then provide a way to
add such dependencies.  I've applied your patch to make this easier for
SWIG dependencies.

Thanks,
-Brad





More information about the CMake mailing list