diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2018-10-27 14:49:17 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2018-10-29 15:39:03 (GMT) |
commit | bb57cb80eb7d9ab779d19112f2da65c60bd37f39 (patch) | |
tree | 9a18456528d98d11abfa2091260d23061494d34b | |
parent | c780f5eea70f9b609e17adf5f192e024d1dd46b5 (diff) | |
download | CMake-bb57cb80eb7d9ab779d19112f2da65c60bd37f39.zip CMake-bb57cb80eb7d9ab779d19112f2da65c60bd37f39.tar.gz CMake-bb57cb80eb7d9ab779d19112f2da65c60bd37f39.tar.bz2 |
UseSWIG: multiple input files must be supported in version 2
Fixes: #18506
-rw-r--r-- | Modules/UseSWIG.cmake | 11 | ||||
-rw-r--r-- | Modules/UseSWIG/ManageSupportFiles.cmake | 31 |
2 files changed, 40 insertions, 2 deletions
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index f20a53b..31395d9 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -234,6 +234,8 @@ set(SWIG_PYTHON_EXTRA_FILE_EXTENSIONS ".py") set(SWIG_JAVA_EXTRA_FILE_EXTENSIONS ".java" "JNI.java") set(SWIG_CSHARP_EXTRA_FILE_EXTENSIONS ".cs" "PINVOKE.cs") +set(SWIG_MANAGE_SUPPORT_FILES_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/UseSWIG/ManageSupportFiles.cmake") + ## ## PRIVATE functions ## @@ -444,9 +446,13 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) if (UseSWIG_MODULE_VERSION VERSION_GREATER 1) # as part of custom command, start by removing old generated files # to ensure obsolete files do not stay - set (swig_cleanup_command COMMAND "${CMAKE_COMMAND}" -E remove_directory "${outdir}") + set (swig_file_outdir "${workingdir}/${swig_source_file_name_we}.files") + set (swig_cleanup_command COMMAND "${CMAKE_COMMAND}" "-DSUPPORT_FILES_WORKING_DIRECTORY=${swig_file_outdir}" "-DSUPPORT_FILES_OUTPUT_DIRECTORY=${outdir}" -DACTION=CLEAN -P "${SWIG_MANAGE_SUPPORT_FILES_SCRIPT}") + set (swig_copy_command COMMAND "${CMAKE_COMMAND}" "-DSUPPORT_FILES_WORKING_DIRECTORY=${swig_file_outdir}" "-DSUPPORT_FILES_OUTPUT_DIRECTORY=${outdir}" -DACTION=COPY -P "${SWIG_MANAGE_SUPPORT_FILES_SCRIPT}") else() + set (swig_file_outdir "${outdir}") unset (swig_cleanup_command) + unset (swig_copy_command) endif() # IMPLICIT_DEPENDS below can not handle situations where a dependent file is @@ -476,12 +482,13 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) COMMAND "${CMAKE_COMMAND}" -E env "SWIG_LIB=${SWIG_DIR}" "${SWIG_EXECUTABLE}" "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}" "${swig_source_file_flags}" - -outdir "${outdir}" + -outdir "${swig_file_outdir}" ${swig_special_flags} ${swig_extra_flags} "${swig_include_dirs}" -o "${swig_generated_file_fullname}" "${swig_source_file_fullname}" + ${swig_copy_command} MAIN_DEPENDENCY "${swig_source_file_fullname}" DEPENDS ${swig_dependencies} IMPLICIT_DEPENDS CXX "${swig_source_file_fullname}" diff --git a/Modules/UseSWIG/ManageSupportFiles.cmake b/Modules/UseSWIG/ManageSupportFiles.cmake new file mode 100644 index 0000000..4a03900 --- /dev/null +++ b/Modules/UseSWIG/ManageSupportFiles.cmake @@ -0,0 +1,31 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + + +if (ACTION STREQUAL "CLEAN") + # Collect current list of generated files + file (GLOB files LIST_DIRECTORIES FALSE RELATIVE "${SUPPORT_FILES_WORKING_DIRECTORY}" "${SUPPORT_FILES_WORKING_DIRECTORY}/*") + + if (files) + # clean-up the output directory + ## compute full paths + list (TRANSFORM files PREPEND "${SUPPORT_FILES_OUTPUT_DIRECTORY}/") + ## remove generated files from the output directory + file (REMOVE ${files}) + + # clean-up working directory + file (REMOVE_RECURSE "${SUPPORT_FILES_WORKING_DIRECTORY}") + endif() + + file (MAKE_DIRECTORY "${SUPPORT_FILES_WORKING_DIRECTORY}") +endif() + +if (ACTION STREQUAL "COPY") + # Collect current list of generated files + file (GLOB files LIST_DIRECTORIES FALSE "${SUPPORT_FILES_WORKING_DIRECTORY}/*") + + if (files) + # copy files to the output directory + file (COPY ${files} DESTINATION "${SUPPORT_FILES_OUTPUT_DIRECTORY}") + endif() +endif() |