diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindSWIG.cmake | 7 | ||||
-rw-r--r-- | Modules/UseSWIG.cmake | 51 |
2 files changed, 48 insertions, 10 deletions
diff --git a/Modules/FindSWIG.cmake b/Modules/FindSWIG.cmake index f732289..87a3894 100644 --- a/Modules/FindSWIG.cmake +++ b/Modules/FindSWIG.cmake @@ -56,8 +56,8 @@ optional Fortran support: #]=======================================================================] # compute list of possible names +unset (_SWIG_NAMES) if (SWIG_FIND_VERSION_RANGE) - set (_SWIG_NAMES) foreach (_SWIG_MAJOR IN ITEMS 4 3 2) if (_SWIG_MAJOR VERSION_GREATER_EQUAL SWIG_FIND_VERSION_MIN_MAJOR AND ((SWIG_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND _SWIG_MAJOR VERSION_LESS_EQUAL SWIG_FIND_VERSION_MAX) @@ -73,10 +73,15 @@ elseif(SWIG_FIND_VERSION) if (_SWIG_MAJOR VERSION_GREATER_EQUAL SWIG_FIND_VERSION_MAJOR) list (APPEND _SWIG_NAMES swig${_SWIG_MAJOR}.0) endif() + endforeach() endif() else() set (_SWIG_NAMES swig4.0 swig3.0 swig2.0) endif() +if (NOT _SWIG_NAMES) + # try to find any version + set (_SWIG_NAMES swig4.0 swig3.0 swig2.0) +endif() find_program(SWIG_EXECUTABLE NAMES ${_SWIG_NAMES} swig) 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) |