diff options
Diffstat (limited to 'Modules/UseSWIG.cmake')
-rw-r--r-- | Modules/UseSWIG.cmake | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index b7b9fe1..dc4febc 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -30,9 +30,10 @@ Defines the following command for use with ``SWIG``: .. note:: - The variable ``SWIG_MODULE_<name>_REAL_NAME`` will be set to the name - of the swig module target library. This variable is useless if variable - ``UseSWIG_TARGET_NAME_PREFERENCE`` is set to ``STANDARD``. + This command creates a target with the specified ``<name>`` when + policy :policy:`CMP0078` is set to ``NEW``. Otherwise, the legacy + behavior will choose a different target name and store it in the + ``SWIG_MODULE_<name>_REAL_NAME`` variable. .. note:: @@ -117,6 +118,13 @@ ensure generated files will receive the required settings. :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and :prop_sf:`COMPILE_OPTIONS`. +``USE_TARGET_INCLUDE_DIRECTORIES`` + If set to ``TRUE``, contents of target property + :prop_tgt:`INCLUDE_DIRECTORIES` will be forwarded to ``SWIG`` compiler. + If set to ``FALSE`` target property :prop_tgt:`INCLUDE_DIRECTORIES` will be + ignored. If not set, target property ``SWIG_USE_TARGT_INCLUDE_DIRECTORIES`` + will be considered. + ``GENERATED_INCLUDE_DIRECTORIES``, ``GENERATED_COMPILE_DEFINITIONS`` and ``GENERATED_COMPILE_OPTIONS`` Add custom flags to the C/C++ generated source. They will fill, respectively, properties :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and @@ -149,6 +157,13 @@ input files. set_property(TARGET mymod PROPERTY SWIG_COMPILE_DEFINITIONS MY_DEF1 MY_DEF2) set_property(TARGET mymod PROPERTY SWIG_COMPILE_OPTIONS -bla -blb) +``SWIG_USE_TARGET_INCLUDE_DIRECTORIES`` + If set to ``TRUE``, contents of target property + :prop_tgt:`INCLUDE_DIRECTORIES` will be forwarded to ``SWIG`` compiler. + If set to ``FALSE`` or not defined, target property + :prop_tgt:`INCLUDE_DIRECTORIES` will be ignored. This behavior can be + overridden by specifying source property ``USE_TARGET_INCLUDE_DIRECTORIES``. + ``SWIG_GENERATED_INCLUDE_DIRECTORIES``, ``SWIG_GENERATED_COMPILE_DEFINITIONS`` and ``SWIG_GENERATED_COMPILE_OPTIONS`` These properties will populate, respectively, properties :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and @@ -183,13 +198,6 @@ information about support files generated by ``SWIG`` interface compilation. Some variables can be set to customize the behavior of ``swig_add_library`` as well as ``SWIG``: -``UseSWIG_TARGET_NAME_PREFERENCE`` - Specify target name strategy. - - * Set to ``LEGACY`` or undefined: legacy strategy is applied. Variable - ``SWIG_MODULE_<name>_REAL_NAME`` must be used to get real target name. - * Set to ``STANDARD``: target name matches specified name. - ``UseSWIG_MODULE_VERSION`` Specify different behaviors for ``UseSWIG`` module. @@ -211,8 +219,13 @@ as well as ``SWIG``: Specify extra dependencies for the generated module for ``<name>``. #]=======================================================================] - +cmake_policy(GET CMP0078 target_name_policy) cmake_policy (VERSION 3.12) +if (target_name_policy) + # respect user choice regarding CMP0078 policy + cmake_policy(SET CMP0078 ${target_name_policy}) +endif() +unset(target_name_policy) set(SWIG_CXX_EXTENSION "cxx") set(SWIG_EXTRA_LIBRARIES "") @@ -347,6 +360,14 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) endif() set (property "$<TARGET_PROPERTY:${target_name},SWIG_INCLUDE_DIRECTORIES>") list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-I$<JOIN:$<TARGET_GENEX_EVAL:${target_name},${property}>,$<SEMICOLON>-I>>") + set (property "$<TARGET_PROPERTY:${target_name},INCLUDE_DIRECTORIES>") + get_source_file_property(use_target_include_dirs "${infile}" USE_TARGET_INCLUDE_DIRECTORIES) + if (use_target_include_dirs) + list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-I$<JOIN:${property},$<SEMICOLON>-I>>") + elseif(use_target_include_dirs STREQUAL "NOTFOUND") + # not defined at source level, rely on target level + list (APPEND swig_source_file_flags "$<$<AND:$<BOOL:$<TARGET_PROPERTY:${target_name},SWIG_USE_TARGET_INCLUDE_DIRECTORIES>>,$<BOOL:${property}>>:-I$<JOIN:${property},$<SEMICOLON>-I>>") + endif() set (property "$<TARGET_PROPERTY:${target_name},SWIG_COMPILE_DEFINITIONS>") list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-D$<JOIN:$<TARGET_GENEX_EVAL:${target_name},${property}>,$<SEMICOLON>-D>>") @@ -524,10 +545,22 @@ function(SWIG_ADD_LIBRARY name) unset(_SAM_TYPE) endif() - if (NOT DEFINED UseSWIG_TARGET_NAME_PREFERENCE) - set (UseSWIG_TARGET_NAME_PREFERENCE LEGACY) - elseif (NOT UseSWIG_TARGET_NAME_PREFERENCE MATCHES "^(LEGACY|STANDARD)$") - message (FATAL_ERROR "UseSWIG_TARGET_NAME_PREFERENCE: ${UseSWIG_TARGET_NAME_PREFERENCE}: invalid value. 'LEGACY' or 'STANDARD' is expected.") + cmake_policy(GET CMP0078 target_name_policy) + if (target_name_policy STREQUAL "NEW") + set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD) + else() + if (NOT target_name_policy) + message(AUTHOR_WARNING + "Policy CMP0078 is not set. " + "Run \"cmake --help-policy CMP0078\" for policy details. " + "Use the cmake_policy command to set the policy and suppress this warning." + ) + endif() + if (NOT DEFINED UseSWIG_TARGET_NAME_PREFERENCE) + set (UseSWIG_TARGET_NAME_PREFERENCE LEGACY) + elseif (NOT UseSWIG_TARGET_NAME_PREFERENCE MATCHES "^(LEGACY|STANDARD)$") + message (FATAL_ERROR "UseSWIG_TARGET_NAME_PREFERENCE: ${UseSWIG_TARGET_NAME_PREFERENCE}: invalid value. 'LEGACY' or 'STANDARD' is expected.") + endif() endif() if (NOT DEFINED UseSWIG_MODULE_VERSION) |