summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-10-02 13:55:20 +0000
committerKitware Robot <kwrobot@kitware.com>2020-10-02 09:55:26 -0400
commit3ec0f9d6209117e768e3d5c02e5d3cc0dc001a16 (patch)
tree60f336e1e16faf00e42234053eb55eb165501add /Modules
parenta64c77974623b5de9635de3e3e53e33b8cd146bc (diff)
parent4a81a0ce3d6cfc923f399b9933ca2ec87a31be5e (diff)
downloadcmake-3ec0f9d6209117e768e3d5c02e5d3cc0dc001a16.tar.gz
Merge topic 'UseSWIG-output-source-file-properties'
4a81a0ce3d UseSWIG: Add OUTPUT_DIR and OUTFILE_DIR source file properties Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5303
Diffstat (limited to 'Modules')
-rw-r--r--Modules/UseSWIG.cmake51
1 files changed, 42 insertions, 9 deletions
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake
index 59a0707aac..757e5392b1 100644
--- a/Modules/UseSWIG.cmake
+++ b/Modules/UseSWIG.cmake
@@ -76,8 +76,8 @@ Defines the following command for use with ``SWIG``:
``OUTFILE_DIR``
Specify an output directory name where the generated source file will be
- placed (swig -o option). If not specified, the ``SWIG_OUTFILE_DIR`` variable
- will be used. If neither is specified, ``OUTPUT_DIR`` or
+ placed (swig ``-o`` option). If not specified, the ``SWIG_OUTFILE_DIR``
+ variable will be used. If neither is specified, ``OUTPUT_DIR`` or
``CMAKE_SWIG_OUTDIR`` is used instead.
``SOURCES``
@@ -156,6 +156,19 @@ ensure generated files will receive the required settings.
If policy :policy:`CMP0086` is set to ``NEW``, ``-module <module_name>``
is passed to ``SWIG`` compiler.
+``OUTPUT_DIR``
+ Specify where to write the language specific files (swig ``-outdir`` option)
+ for the considered source file. If not specified, the other ways to define
+ the output directory applies (see ``OUTPUT_DIR`` option of
+ ``swig_add_library()`` command).
+
+``OUTFILE_DIR``
+ Specify an output directory where the generated source file will be placed
+ (swig ``-o`` option) for the considered source file. If not specified,
+ ``OUTPUT_DIR`` source property will be used. If neither are specified, the
+ other ways to define output file directory applies (see ``OUTFILE_DIR``
+ option of ``swig_add_library()`` command).
+
Target library properties can be set to apply same configuration to all SWIG
input files.
@@ -209,6 +222,11 @@ information about support files generated by ``SWIG`` interface compilation.
This output property specifies the directory where support files will be
generated.
+ .. note::
+
+ When source property ``OUTPUT_DIR`` is defined, multiple directories can be
+ specified as part of ``SWIG_SUPPORT_FILES_DIRECTORY``.
+
Some variables can be set to customize the behavior of ``swig_add_library``
as well as ``SWIG``:
@@ -375,15 +393,24 @@ endfunction()
function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
get_filename_component(swig_source_file_name_we "${infile}" NAME_WE)
get_source_file_property(swig_source_file_cplusplus "${infile}" CPLUSPLUS)
-
- # If CMAKE_SWIG_OUTDIR was specified then pass it to -outdir
- if(CMAKE_SWIG_OUTDIR)
+ get_source_file_property(swig_source_file_outdir "${infile}" OUTPUT_DIR)
+ get_source_file_property(swig_source_file_outfiledir "${infile}" OUTFILE_DIR)
+
+ if (swig_source_file_outdir)
+ # use source file property
+ set(outdir "${swig_source_file_outdir}")
+ if (NOT swig_source_file_outfiledir)
+ set (swig_source_file_outfiledir "${outdir}")
+ endif()
+ elseif(CMAKE_SWIG_OUTDIR)
set(outdir ${CMAKE_SWIG_OUTDIR})
else()
set(outdir ${CMAKE_CURRENT_BINARY_DIR})
endif()
- if(SWIG_OUTFILE_DIR)
+ if (swig_source_file_outfiledir)
+ set (outfiledir "${swig_source_file_outfiledir}")
+ elseif(SWIG_OUTFILE_DIR)
set(outfiledir ${SWIG_OUTFILE_DIR})
else()
set(outfiledir ${outdir})
@@ -725,6 +752,7 @@ function(SWIG_ADD_LIBRARY name)
set(swig_generated_sources)
set(swig_generated_timestamps)
+ set(swig_generated_outdirs "${outputdir}")
list(LENGTH swig_dot_i_sources swig_sources_count)
if (swig_sources_count GREATER "1")
# option -interface cannot be used
@@ -740,11 +768,16 @@ function(SWIG_ADD_LIBRARY name)
"${workingdir}" swig_timestamp)
list (APPEND swig_generated_timestamps "${swig_timestamp}")
endif()
+ get_source_file_property(swig_source_file_outdir "${swig_it}" OUTPUT_DIR)
+ if (swig_source_file_outdir)
+ list (APPEND swig_generated_outdirs "${swig_source_file_outdir}")
+ endif()
endforeach()
+ list(REMOVE_DUPLICATES swig_generated_outdirs)
set_property (DIRECTORY APPEND PROPERTY
ADDITIONAL_CLEAN_FILES ${swig_generated_sources} ${swig_generated_timestamps})
if (UseSWIG_MODULE_VERSION VERSION_GREATER 1)
- set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${outputdir}")
+ set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${swig_generated_outdirs})
endif()
add_library(${target_name}
@@ -828,8 +861,8 @@ function(SWIG_ADD_LIBRARY name)
set_target_properties (${target_name} PROPERTIES PREFIX "")
endif ()
- # target property SWIG_SUPPORT_FILES_DIRECTORY specify output directory of support files
- set_property (TARGET ${target_name} PROPERTY SWIG_SUPPORT_FILES_DIRECTORY "${outputdir}")
+ # target property SWIG_SUPPORT_FILES_DIRECTORY specify output directories of support files
+ set_property (TARGET ${target_name} PROPERTY SWIG_SUPPORT_FILES_DIRECTORY ${swig_generated_outdirs})
# target property SWIG_SUPPORT_FILES lists principal proxy support files
if (NOT SWIG_MODULE_${name}_NOPROXY)
string(TOUPPER "${_SAM_LANGUAGE}" swig_uppercase_language)