diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-08 09:13:15 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-08 09:13:15 +0900 |
commit | a9a515dd6b7b96484920a3f0f1202393b91dfd2e (patch) | |
tree | 62e21c47bbffdc30a405d1ef04f452ee46a384b6 /Modules/UseSWIG.cmake | |
parent | 0375131677cc32a24352f205d05c730690c55af6 (diff) | |
download | cmake-a9a515dd6b7b96484920a3f0f1202393b91dfd2e.tar.gz cmake-a9a515dd6b7b96484920a3f0f1202393b91dfd2e.tar.bz2 cmake-a9a515dd6b7b96484920a3f0f1202393b91dfd2e.zip |
Imported Upstream version 3.11.0upstream/3.11.0
Diffstat (limited to 'Modules/UseSWIG.cmake')
-rw-r--r-- | Modules/UseSWIG.cmake | 153 |
1 files changed, 100 insertions, 53 deletions
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index c8b1cd7c4..959893fe5 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -1,58 +1,70 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -#.rst: -# UseSWIG -# ------- -# -# Defines the following macros for use with SWIG: -# -# :: -# -# SWIG_ADD_LIBRARY(<name> -# [TYPE <SHARED|MODULE|STATIC|USE_BUILD_SHARED_LIBS>] -# LANGUAGE <language> -# SOURCES <file>... -# ) -# - Define swig module with given name and specified language -# SWIG_LINK_LIBRARIES(name [ libraries ]) -# - Link libraries to swig module -# -# Source files properties on module files can be set before the invocation -# of the SWIG_ADD_LIBRARY macro to specify special behavior of SWIG. -# -# The source file property CPLUSPLUS calls SWIG in c++ mode, e.g.:: -# -# set_property(SOURCE mymod.i PROPERTY CPLUSPLUS ON) -# swig_add_library(mymod LANGUAGE python SOURCES mymod.i) -# -# The source file property SWIG_FLAGS adds custom flags to the SWIG executable. -# -# The source-file property SWIG_MODULE_NAME have to be provided to specify the actual -# import name of the module in the target language if it cannot be scanned automatically -# from source or different from the module file basename.:: -# -# set_property(SOURCE mymod.i PROPERTY SWIG_MODULE_NAME mymod_realname) -# -# To get the name of the swig module target library, use: ${SWIG_MODULE_${name}_REAL_NAME}. -# -# Also some variables can be set to specify special behavior of SWIG. -# -# CMAKE_SWIG_FLAGS can be used to add special flags to all swig calls. -# -# CMAKE_SWIG_OUTDIR allows one to specify where to write -# the language specific files (swig -outdir option). -# -# SWIG_OUTFILE_DIR allows one to specify where to write the output file -# (swig -o option). If not specified, CMAKE_SWIG_OUTDIR is used. -# -# The name-specific variable SWIG_MODULE_<name>_EXTRA_DEPS may be used to specify extra -# dependencies for the generated modules. -# -# If the source file generated by swig need some special flag you can use:: -# -# set_source_files_properties( ${swig_generated_file_fullname} -# PROPERTIES COMPILE_FLAGS "-bla") +#[=======================================================================[.rst: +UseSWIG +------- + +Defines the following macros for use with SWIG: + +.. command:: swig_add_library + + Define swig module with given name and specified language:: + + swig_add_library(<name> + [TYPE <SHARED|MODULE|STATIC|USE_BUILD_SHARED_LIBS>] + LANGUAGE <language> + SOURCES <file>... + ) + + The variable ``SWIG_MODULE_<name>_REAL_NAME`` will be set to the name + of the swig module target library. + +.. command:: swig_link_libraries + + Link libraries to swig module:: + + swig_link_libraries(<name> [ libraries ]) + +Source file properties on module files can be set before the invocation +of the ``swig_add_library`` macro to specify special behavior of SWIG: + +``CPLUSPLUS`` + Call SWIG in c++ mode. For example: + + .. code-block:: cmake + + set_property(SOURCE mymod.i PROPERTY CPLUSPLUS ON) + swig_add_library(mymod LANGUAGE python SOURCES mymod.i) + +``SWIG_FLAGS`` + Add custom flags to the SWIG executable. + + +``SWIG_MODULE_NAME`` + Specify the actual import name of the module in the target language. + This is required if it cannot be scanned automatically from source + or different from the module file basename. For example: + + .. code-block:: cmake + + set_property(SOURCE mymod.i PROPERTY SWIG_MODULE_NAME mymod_realname) + +Some variables can be set to specify special behavior of SWIG: + +``CMAKE_SWIG_FLAGS`` + Add flags to all swig calls. + +``CMAKE_SWIG_OUTDIR`` + Specify where to write the language specific files (swig ``-outdir`` option). + +``SWIG_OUTFILE_DIR`` + Specify an output directory name where the generated source file will be + placed. If not specified, ``CMAKE_SWIG_OUTDIR`` is used. + +``SWIG_MODULE_<name>_EXTRA_DEPS`` + Specify extra dependencies for the generated module for ``<name>``. +#]=======================================================================] set(SWIG_CXX_EXTENSION "cxx") set(SWIG_EXTRA_LIBRARIES "") @@ -201,10 +213,32 @@ macro(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) if(SWIG_MODULE_${name}_EXTRA_FLAGS) set(swig_extra_flags ${swig_extra_flags} ${SWIG_MODULE_${name}_EXTRA_FLAGS}) endif() + # IMPLICIT_DEPENDS below can not handle situations where a dependent file is + # removed. We need an extra step with timestamp and custom target, see #16830 + # As this is needed only for Makefile generator do it conditionally + if(CMAKE_GENERATOR MATCHES "Make") + get_filename_component(swig_generated_timestamp + "${swig_generated_file_fullname}" NAME_WE) + set(swig_gen_target gen_${name}_${swig_generated_timestamp}) + set(swig_generated_timestamp + "${swig_outdir}/${swig_generated_timestamp}.stamp") + set(swig_custom_output ${swig_generated_timestamp}) + set(swig_custom_products + BYPRODUCTS "${swig_generated_file_fullname}" ${swig_extra_generated_files}) + set(swig_timestamp_command + COMMAND ${CMAKE_COMMAND} -E touch ${swig_generated_timestamp}) + else() + set(swig_custom_output + "${swig_generated_file_fullname}" ${swig_extra_generated_files}) + set(swig_custom_products) + set(swig_timestamp_command) + endif() add_custom_command( - OUTPUT "${swig_generated_file_fullname}" ${swig_extra_generated_files} + OUTPUT ${swig_custom_output} + ${swig_custom_products} # Let's create the ${swig_outdir} at execution time, in case dir contains $(OutDir) COMMAND ${CMAKE_COMMAND} -E make_directory ${swig_outdir} + ${swig_timestamp_command} COMMAND "${SWIG_EXECUTABLE}" ARGS "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}" ${swig_source_file_flags} @@ -219,6 +253,13 @@ macro(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) DEPENDS ${SWIG_MODULE_${name}_EXTRA_DEPS} IMPLICIT_DEPENDS CXX "${swig_source_file_fullname}" COMMENT "Swig source") + if(CMAKE_GENERATOR MATCHES "Make") + add_custom_target(${swig_gen_target} DEPENDS ${swig_generated_timestamp}) + endif() + unset(swig_generated_timestamp) + unset(swig_custom_output) + unset(swig_custom_products) + unset(swig_timestamp_command) set_source_files_properties("${swig_generated_file_fullname}" ${swig_extra_generated_files} PROPERTIES GENERATED 1) set(${outfiles} "${swig_generated_file_fullname}" ${swig_extra_generated_files}) @@ -270,9 +311,11 @@ macro(SWIG_ADD_LIBRARY name) endforeach() set(swig_generated_sources) + set(swig_generated_targets) foreach(it ${swig_dot_i_sources}) SWIG_ADD_SOURCE_TO_MODULE(${name} swig_generated_source ${it}) set(swig_generated_sources ${swig_generated_sources} "${swig_generated_source}") + list(APPEND swig_generated_targets "${swig_gen_target}") endforeach() get_directory_property(swig_extra_clean_files ADDITIONAL_MAKE_CLEAN_FILES) set_directory_properties(PROPERTIES @@ -281,6 +324,10 @@ macro(SWIG_ADD_LIBRARY name) ${_SAM_TYPE} ${swig_generated_sources} ${swig_other_sources}) + if(CMAKE_GENERATOR MATCHES "Make") + # see IMPLICIT_DEPENDS above + add_dependencies(${SWIG_MODULE_${name}_REAL_NAME} ${swig_generated_targets}) + endif() if("${_SAM_TYPE}" STREQUAL "MODULE") set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES NO_SONAME ON) endif() |