summaryrefslogtreecommitdiff
path: root/Modules/UseSWIG.cmake
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2018-07-23 10:38:08 +0200
committerMarc Chevrier <marc.chevrier@gmail.com>2018-07-25 18:00:52 +0200
commita3a0c3aa71498f76cc0e9655038de7bbb5430a03 (patch)
treed094f6028f45cc327e923afe089085f00e846783 /Modules/UseSWIG.cmake
parent3ab6f056dc8765c98e62a04a16fa24f23f201b7a (diff)
downloadcmake-a3a0c3aa71498f76cc0e9655038de7bbb5430a03.tar.gz
UseSWIG: add policy to manage target naming strategy.
Diffstat (limited to 'Modules/UseSWIG.cmake')
-rw-r--r--Modules/UseSWIG.cmake41
1 files changed, 26 insertions, 15 deletions
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake
index 7460932885..e7aaf32eef 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::
@@ -197,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.
@@ -225,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 "")
@@ -545,10 +544,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)