diff options
author | Mathieu Malaterre <mathieu.malaterre@gmail.com> | 2011-03-28 16:14:23 (GMT) |
---|---|---|
committer | Mathieu Malaterre <mathieu.malaterre@gmail.com> | 2011-04-08 13:07:40 (GMT) |
commit | 1088b0278e74526298d0821589973918da33c44b (patch) | |
tree | 67c26155d41f417c03059d7f904c3dd1a5ed3852 | |
parent | 0e66141bea25a93a5ef42c39d5c3a0b6612c1fe6 (diff) | |
download | CMake-1088b0278e74526298d0821589973918da33c44b.zip CMake-1088b0278e74526298d0821589973918da33c44b.tar.gz CMake-1088b0278e74526298d0821589973918da33c44b.tar.bz2 |
Add a new function SWIG_GET_WRAPPER_DEPENDENCIES to UseSWIG.cmake
This commit fixes BUG: 0004147 it directly uses swig executable
to compute a list of dependencies directly from the .i files
to make sure to rebuild the swig module any of its direct dep.
is touched
-rw-r--r-- | Modules/UseSWIG.cmake | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index b547dc7..f9808c5 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -4,6 +4,9 @@ # - Define swig module with given name and specified language # SWIG_LINK_LIBRARIES(name [ libraries ]) # - Link libraries to swig module +# SWIG_GET_WRAPPER_DEPENDENCIES(swigFile genWrapper language DEST_VARIABLE) +# - Put dependencies of the wrapper genWrapper generated by swig from +# swigFile in DEST_VARIABLE # All other macros are for internal use only. # To get the actual name of the swig module, # use: ${SWIG_MODULE_${name}_REAL_NAME}. @@ -39,6 +42,58 @@ SET(SWIG_EXTRA_LIBRARIES "") SET(SWIG_PYTHON_EXTRA_FILE_EXTENSION "py") # +# Get dependencies of the generated wrapper. +# +MACRO(SWIG_GET_WRAPPER_DEPENDENCIES swigFile genWrapper language DEST_VARIABLE) + GET_FILENAME_COMPONENT(swig_getdeps_basename ${swigFile} NAME_WE) + GET_FILENAME_COMPONENT(swig_getdeps_outdir ${genWrapper} PATH) + GET_SOURCE_FILE_PROPERTY(swig_getdeps_extra_flags "${swigFile}" SWIG_FLAGS) + IF("${swig_getdeps_extra_flags}" STREQUAL "NOTFOUND") + SET(swig_getdeps_extra_flags "") + ENDIF("${swig_getdeps_extra_flags}" STREQUAL "NOTFOUND") + + IF(NOT swig_getdeps_outdir) + SET(swig_getdeps_outdir ${CMAKE_CURRENT_BINARY_DIR}) + ENDIF(NOT swig_getdeps_outdir) + SET(swig_getdeps_depsfile + ${swig_getdeps_outdir}/swig_${swig_getdeps_basename}_deps.txt) + GET_DIRECTORY_PROPERTY(swig_getdeps_include_directories INCLUDE_DIRECTORIES) + SET(swig_getdeps_include_dirs) + FOREACH(it ${swig_getdeps_include_directories}) + SET(swig_getdeps_include_dirs ${swig_getdeps_include_dirs} "-I${it}") + ENDFOREACH(it) + EXECUTE_PROCESS( + COMMAND ${SWIG_EXECUTABLE} + -MM -MF ${swig_getdeps_depsfile} ${swig_getdeps_extra_flags} + ${CMAKE_SWIG_FLAGS} -${language} + -o ${genWrapper} ${swig_getdeps_include_dirs} ${swigFile} + RESULT_VARIABLE swig_getdeps_result + ERROR_VARIABLE swig_getdeps_error + OUTPUT_STRIP_TRAILING_WHITESPACE) + IF(NOT ${swig_getdeps_error} EQUAL 0) + MESSAGE(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -MM -MF ${swig_getdeps_depsfile} ${swig_getdeps_extra_flags} ${CMAKE_SWIG_FLAGS} -${language} -o ${genWrapper} ${swig_getdeps_include_dirs} ${swigFile}\" failed with output:\n${swig_getdeps_error}") + SET(swig_getdeps_dependencies "") + ELSE(NOT ${swig_getdeps_error} EQUAL 0) + FILE(READ ${swig_getdeps_depsfile} ${DEST_VARIABLE}) + # Remove the first line + STRING(REGEX REPLACE "^.+: +\\\\\n +" "" + ${DEST_VARIABLE} "${${DEST_VARIABLE}}") + # Clean the end of each line + STRING(REGEX REPLACE " +(\\\\)?\n" "\n" ${DEST_VARIABLE} + "${${DEST_VARIABLE}}") + # Clean beginning of each line + STRING(REGEX REPLACE "\n +" "\n" + ${DEST_VARIABLE} "${${DEST_VARIABLE}}") + # clean paths + STRING(REGEX REPLACE "\\\\\\\\" "/" ${DEST_VARIABLE} + "${${DEST_VARIABLE}}") + STRING(REGEX REPLACE "\n" ";" + ${DEST_VARIABLE} "${${DEST_VARIABLE}}") + ENDIF(NOT ${swig_getdeps_error} EQUAL 0) +ENDMACRO(SWIG_GET_WRAPPER_DEPENDENCIES) + + +# # For given swig module initialize variables associated with it # MACRO(SWIG_MODULE_INITIALIZE name language) @@ -166,6 +221,10 @@ MACRO(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) IF(SWIG_MODULE_${name}_EXTRA_FLAGS) SET(swig_extra_flags ${swig_extra_flags} ${SWIG_MODULE_${name}_EXTRA_FLAGS}) ENDIF(SWIG_MODULE_${name}_EXTRA_FLAGS) + SWIG_GET_WRAPPER_DEPENDENCIES("${swig_source_file_fullname}" + "${swig_generated_file_fullname}" ${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG} + swig_extra_dependencies) + LIST(APPEND SWIG_MODULE_${name}_EXTRA_DEPS ${swig_extra_dependencies}) ADD_CUSTOM_COMMAND( OUTPUT "${swig_generated_file_fullname}" ${swig_extra_generated_files} COMMAND "${SWIG_EXECUTABLE}" |