diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2020-09-30 16:47:42 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2020-09-30 17:19:14 (GMT) |
commit | 4a81a0ce3d6cfc923f399b9933ca2ec87a31be5e (patch) | |
tree | db74fbe974420a8099db04dcc4bf12117bf57c60 /Modules/UseSWIG.cmake | |
parent | d91c3e33cbf9592f90f65bd7d990a8b54ad140d1 (diff) | |
download | CMake-4a81a0ce3d6cfc923f399b9933ca2ec87a31be5e.zip CMake-4a81a0ce3d6cfc923f399b9933ca2ec87a31be5e.tar.gz CMake-4a81a0ce3d6cfc923f399b9933ca2ec87a31be5e.tar.bz2 |
UseSWIG: Add OUTPUT_DIR and OUTFILE_DIR source file properties
These properties enable to manage output directories on
per source file basis.
Fixes: #21250
Diffstat (limited to 'Modules/UseSWIG.cmake')
-rw-r--r-- | Modules/UseSWIG.cmake | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index 59a0707..757e539 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) |