[CMake] [ADD_CUSTOM_COMMAND] How to add source dependences to the
target ouside of the command?
Tristan Carel
tristan.carel at gmail.com
Thu Aug 24 18:08:49 EDT 2006
Hi dear maintainers, hi lucky users!!!
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'
So I tried to add dependences to the target `wrapper.cxx' in the "user
land" (I mean without patching the module `UseSWIG.cmake' :) but I
failed.
I guess there are two commands to add dependences to entities:
`ADD_DEPENDENCIES' and `SET_SOURCE_FILES_PROPERTIES'
Now a use case: a swig input file `foo.i' which includes the header
`foo.hh', I would like to simply have a rule like below:
wrapper.cxx: foo.i foo.hh
swig [too many options] foo.i
I tried the following commands:
1.
ADD_DEPENDENCIES(wrapper.cxx foo.hh)
it doesn't work because `foo.hh' is a source file, so not considered
by CMake as a target.
2.
INCLUDE(AddFileDependencies)
ADD_FILE_DEPENDENCIES(foo.i foo.hh)
It compiles but doesn't work and I don't understand why. It should
generate something like:
wrapper.cxx: foo.i
swig [too many options] foo.i
foo.i: foo.hh # <--- not generated
Where am I wrong?
3.
ADD_FILE_DEPENDENCIES(wrapper.cxx foo.hh)
But it'is like if `wrappers.cxx' included `foo.hh' , isn't it? (so
it's not what I'm looking for).
Have you got an idea on how to proceed, CMake wizards?
Even if it can be done in the user land, the variable which contains
`wrapper.cxx' defined in the module `UseSWIG.cmake' is private
(internal to the module).
If there is not solution, it means that there's a lack in the module
`UseSWIG.cmake', isn't it?
--- Modules/UseSWIG.cmake.orig 2006-08-24 13:46:46.033254900 -0400
+++ Modules/UseSWIG.cmake 2006-08-24 14:06:31.525217000 -0400
@@ -7,6 +7,8 @@
# All other macros are for internal use only.
# To get the actual name of the swig module,
# use: ${SWIG_MODULE_name_REAL_NAME}.
+# To add extra dependancies to the generated wrapper
+# use: ${SWIG_MODULE_name_EXTRA_DEPS}.
# Set Source files properties such as CPLUSPLUS and SWIG_FLAGS to specify
# special behavior of SWIG. Also global CMAKE_SWIG_FLAGS can be used to add
# special flags to all swig calls.
@@ -145,6 +147,7 @@
-o "${swig_generated_file_fullname}"
"${swig_source_file_fullname}"
MAIN_DEPENDENCY "${swig_source_file_fullname}"
+ DEPENDS ${SWIG_MODULE_${name}_EXTRA_DEPS}
COMMENT "Swig source")
ELSE(CMAKE_SWIG_OUTDIR)
ADD_CUSTOM_COMMAND(
@@ -160,6 +163,7 @@
-o "${swig_generated_file_fullname}"
"${swig_source_file_fullname}"
MAIN_DEPENDENCY "${swig_source_file_fullname}"
+ DEPENDS ${SWIG_MODULE_${name}_EXTRA_DEPS}
COMMENT "Swig source")
ENDIF(CMAKE_SWIG_OUTDIR)
SET_SOURCE_FILES_PROPERTIES("${swig_generated_file_fullname}"
So in the user land, we have to do as below:
SET(SWIG_MODULE_foo_EXTRA_DEPS foo.hh)
SWIG_ADD_MODULE(foo PYTHON foo.i foo.hh foo.cc)
I think it's dirty because:
- It could be nicer with an option in the macro instead than with a
new variable.
- you can have multiple .i files in the same module:
SWIG_ADD_MODULE(foo PYTHON foo.i foo.hh foo.cc bar.i)
it will generate:
wrapper1.cxx: foo.i
swig .... foo.i
wrapper1.cxx: bar.i
swig .... bar.i
It means that the variable `SWIG_MODULE_foo_EXTRA_DEPS' has to
contains dependencies for both `foo.i' and `bar.i'.
==> Useless dependencies are created
==> The Swig modules will sometimes be compile uselessly.
Extra dependencies have to be specified for each swig file, so why not
use the new variable like below:
SET(SWIG_MODULE_foo_FILE_foo_EXTRA_DEPS foo.hh)
SET(SWIG_MODULE_foo_FILE_bar_EXTRA_DEPS bar.hh misc.i)
SWIG_ADD_MODULE(foo PYTHON foo.i foo.hh foo.cc)
--- UseSWIG.cmake.orig 2006-08-24 13:46:46.033254900 -0400
+++ UseSWIG.cmake 2006-08-24 17:54:42.675339800 -0400
@@ -7,6 +7,8 @@
# All other macros are for internal use only.
# To get the actual name of the swig module,
# use: ${SWIG_MODULE_name_REAL_NAME}.
+# To add extra dependancies to a swig input file of a module
+# set: ${SWIG_MODULE_name_FILE_name_EXTRA_DEPS} before calling SWIG_ADD_MODULE.
# Set Source files properties such as CPLUSPLUS and SWIG_FLAGS to specify
# special behavior of SWIG. Also global CMAKE_SWIG_FLAGS can be used to add
# special flags to all swig calls.
@@ -145,6 +147,7 @@
-o "${swig_generated_file_fullname}"
"${swig_source_file_fullname}"
MAIN_DEPENDENCY "${swig_source_file_fullname}"
+ DEPENDS ${SWIG_MODULE_${name}_FILE_${swig_source_file_name_we}_EXTRA_DEPS}
COMMENT "Swig source")
ELSE(CMAKE_SWIG_OUTDIR)
ADD_CUSTOM_COMMAND(
@@ -160,6 +163,7 @@
-o "${swig_generated_file_fullname}"
"${swig_source_file_fullname}"
MAIN_DEPENDENCY "${swig_source_file_fullname}"
+ DEPENDS ${SWIG_MODULE_${name}_FILE_${swig_source_file_name_we}_EXTRA_DEPS}
COMMENT "Swig source")
ENDIF(CMAKE_SWIG_OUTDIR)
SET_SOURCE_FILES_PROPERTIES("${swig_generated_file_fullname}"
Thank you by advance.
--
Tristan Carel
More information about the CMake
mailing list