diff options
author | Brad King <brad.king@kitware.com> | 2018-10-29 15:47:26 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-10-29 15:47:26 (GMT) |
commit | 87d38b4038d59bbee80104e26105dc06f5c5f70c (patch) | |
tree | 71962f31bdd8121bbae0a628e5aa4799b0458e55 /Modules | |
parent | 44cef5fd9204dab2872ca87ed3c56947218aeb75 (diff) | |
parent | bb57cb80eb7d9ab779d19112f2da65c60bd37f39 (diff) | |
download | CMake-87d38b4038d59bbee80104e26105dc06f5c5f70c.zip CMake-87d38b4038d59bbee80104e26105dc06f5c5f70c.tar.gz CMake-87d38b4038d59bbee80104e26105dc06f5c5f70c.tar.bz2 |
Merge branch 'UseSWIG-multi-input' into release-3.13
Merge-request: !2539
Diffstat (limited to 'Modules')
-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() |