mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-17 12:40:40 -06:00
UseSWIG: add policy to manage target naming strategy.
This commit is contained in:
@@ -57,6 +57,7 @@ Policies Introduced by CMake 3.13
|
|||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 1
|
:maxdepth: 1
|
||||||
|
|
||||||
|
CMP0078: UseSWIG generates standard target names. </policy/CMP0078>
|
||||||
CMP0077: option() honors normal variables. </policy/CMP0077>
|
CMP0077: option() honors normal variables. </policy/CMP0077>
|
||||||
CMP0076: target_sources() command converts relative paths to absolute. </policy/CMP0076>
|
CMP0076: target_sources() command converts relative paths to absolute. </policy/CMP0076>
|
||||||
|
|
||||||
|
|||||||
22
Help/policy/CMP0078.rst
Normal file
22
Help/policy/CMP0078.rst
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
CMP0078
|
||||||
|
-------
|
||||||
|
|
||||||
|
Starting with CMake 3.13, :module:`UseSWIG` generates now standard target
|
||||||
|
names. This policy provides compatibility with projects that expect the legacy
|
||||||
|
behavior.
|
||||||
|
|
||||||
|
The ``OLD`` behavior for this policy relies on
|
||||||
|
``UseSWIG_TARGET_NAME_PREFERENCE`` variable that can be used to specify an
|
||||||
|
explicit preference. The value may be one of:
|
||||||
|
|
||||||
|
* ``LEGACY``: legacy strategy is applied. Variable
|
||||||
|
``SWIG_MODULE_<name>_REAL_NAME`` must be used to get real target name.
|
||||||
|
This is the default if not specified.
|
||||||
|
* ``STANDARD``: target name matches specified name.
|
||||||
|
|
||||||
|
This policy was introduced in CMake version 3.13. CMake version
|
||||||
|
|release| warns when the policy is not set and uses ``OLD`` behavior.
|
||||||
|
Use the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW``
|
||||||
|
explicitly.
|
||||||
|
|
||||||
|
.. include:: DEPRECATED.txt
|
||||||
5
Help/release/dev/UseSWIG-target-name-policy.rst
Normal file
5
Help/release/dev/UseSWIG-target-name-policy.rst
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
UseSWIG-target-name-policy
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
* The :module:`UseSWIG` module has changed strategy for target naming.
|
||||||
|
See policy :policy:`CMP0078`.
|
||||||
@@ -30,9 +30,10 @@ Defines the following command for use with ``SWIG``:
|
|||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
The variable ``SWIG_MODULE_<name>_REAL_NAME`` will be set to the name
|
This command creates a target with the specified ``<name>`` when
|
||||||
of the swig module target library. This variable is useless if variable
|
policy :policy:`CMP0078` is set to ``NEW``. Otherwise, the legacy
|
||||||
``UseSWIG_TARGET_NAME_PREFERENCE`` is set to ``STANDARD``.
|
behavior will choose a different target name and store it in the
|
||||||
|
``SWIG_MODULE_<name>_REAL_NAME`` variable.
|
||||||
|
|
||||||
.. note::
|
.. 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``
|
Some variables can be set to customize the behavior of ``swig_add_library``
|
||||||
as well as ``SWIG``:
|
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``
|
``UseSWIG_MODULE_VERSION``
|
||||||
Specify different behaviors for ``UseSWIG`` module.
|
Specify different behaviors for ``UseSWIG`` module.
|
||||||
|
|
||||||
@@ -225,8 +219,13 @@ as well as ``SWIG``:
|
|||||||
Specify extra dependencies for the generated module for ``<name>``.
|
Specify extra dependencies for the generated module for ``<name>``.
|
||||||
#]=======================================================================]
|
#]=======================================================================]
|
||||||
|
|
||||||
|
cmake_policy(GET CMP0078 target_name_policy)
|
||||||
cmake_policy (VERSION 3.12)
|
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_CXX_EXTENSION "cxx")
|
||||||
set(SWIG_EXTRA_LIBRARIES "")
|
set(SWIG_EXTRA_LIBRARIES "")
|
||||||
@@ -545,10 +544,22 @@ function(SWIG_ADD_LIBRARY name)
|
|||||||
unset(_SAM_TYPE)
|
unset(_SAM_TYPE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT DEFINED UseSWIG_TARGET_NAME_PREFERENCE)
|
cmake_policy(GET CMP0078 target_name_policy)
|
||||||
set (UseSWIG_TARGET_NAME_PREFERENCE LEGACY)
|
if (target_name_policy STREQUAL "NEW")
|
||||||
elseif (NOT UseSWIG_TARGET_NAME_PREFERENCE MATCHES "^(LEGACY|STANDARD)$")
|
set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
|
||||||
message (FATAL_ERROR "UseSWIG_TARGET_NAME_PREFERENCE: ${UseSWIG_TARGET_NAME_PREFERENCE}: invalid value. 'LEGACY' or 'STANDARD' is expected.")
|
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()
|
endif()
|
||||||
|
|
||||||
if (NOT DEFINED UseSWIG_MODULE_VERSION)
|
if (NOT DEFINED UseSWIG_MODULE_VERSION)
|
||||||
|
|||||||
@@ -228,7 +228,9 @@ class cmMakefile;
|
|||||||
"target_sources() command converts relative paths to absolute.", 3, \
|
"target_sources() command converts relative paths to absolute.", 3, \
|
||||||
13, 0, cmPolicies::WARN) \
|
13, 0, cmPolicies::WARN) \
|
||||||
SELECT(POLICY, CMP0077, "option() honors normal variables.", 3, 13, 0, \
|
SELECT(POLICY, CMP0077, "option() honors normal variables.", 3, 13, 0, \
|
||||||
cmPolicies::WARN)
|
cmPolicies::WARN) \
|
||||||
|
SELECT(POLICY, CMP0078, "UseSWIG generates standard target names.", 3, 13, \
|
||||||
|
0, cmPolicies::WARN)
|
||||||
|
|
||||||
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
|
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
|
||||||
#define CM_FOR_EACH_POLICY_ID(POLICY) \
|
#define CM_FOR_EACH_POLICY_ID(POLICY) \
|
||||||
|
|||||||
@@ -154,6 +154,9 @@ add_RunCMake_test(FPHSA)
|
|||||||
add_RunCMake_test(FindBoost)
|
add_RunCMake_test(FindBoost)
|
||||||
add_RunCMake_test(FindLua)
|
add_RunCMake_test(FindLua)
|
||||||
add_RunCMake_test(FindOpenGL)
|
add_RunCMake_test(FindOpenGL)
|
||||||
|
if(CMake_TEST_UseSWIG)
|
||||||
|
add_RunCMake_test(UseSWIG)
|
||||||
|
endif()
|
||||||
if(NOT CMAKE_C_COMPILER_ID MATCHES "Watcom")
|
if(NOT CMAKE_C_COMPILER_ID MATCHES "Watcom")
|
||||||
add_RunCMake_test(GenerateExportHeader)
|
add_RunCMake_test(GenerateExportHeader)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
2
Tests/RunCMake/UseSWIG/CMP0078-NEW-stdout.txt
Normal file
2
Tests/RunCMake/UseSWIG/CMP0078-NEW-stdout.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
-- PREFIX='_'
|
||||||
|
-- TARGET NAME='example'
|
||||||
2
Tests/RunCMake/UseSWIG/CMP0078-NEW.cmake
Normal file
2
Tests/RunCMake/UseSWIG/CMP0078-NEW.cmake
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
cmake_policy(SET CMP0078 NEW)
|
||||||
|
include(CMP0078-common.cmake)
|
||||||
2
Tests/RunCMake/UseSWIG/CMP0078-OLD-stdout.txt
Normal file
2
Tests/RunCMake/UseSWIG/CMP0078-OLD-stdout.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
-- PREFIX=''
|
||||||
|
-- TARGET NAME='_example'
|
||||||
2
Tests/RunCMake/UseSWIG/CMP0078-OLD.cmake
Normal file
2
Tests/RunCMake/UseSWIG/CMP0078-OLD.cmake
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
cmake_policy(SET CMP0078 OLD)
|
||||||
|
include(CMP0078-common.cmake)
|
||||||
9
Tests/RunCMake/UseSWIG/CMP0078-WARN-stderr.txt
Normal file
9
Tests/RunCMake/UseSWIG/CMP0078-WARN-stderr.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
CMake Warning \(dev\) at .*/Modules/UseSWIG.cmake:[0-9]+ \(message\):
|
||||||
|
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.
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMP0078-common.cmake:6 \(swig_add_library\)
|
||||||
|
CMP0078-WARN.cmake:1 \(include\)
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
This warning is for project developers. Use -Wno-dev to suppress it.$
|
||||||
2
Tests/RunCMake/UseSWIG/CMP0078-WARN-stdout.txt
Normal file
2
Tests/RunCMake/UseSWIG/CMP0078-WARN-stdout.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
-- PREFIX=''
|
||||||
|
-- TARGET NAME='_example'
|
||||||
1
Tests/RunCMake/UseSWIG/CMP0078-WARN.cmake
Normal file
1
Tests/RunCMake/UseSWIG/CMP0078-WARN.cmake
Normal file
@@ -0,0 +1 @@
|
|||||||
|
include(CMP0078-common.cmake)
|
||||||
10
Tests/RunCMake/UseSWIG/CMP0078-common.cmake
Normal file
10
Tests/RunCMake/UseSWIG/CMP0078-common.cmake
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
set(SWIG_EXECUTABLE "swig")
|
||||||
|
set(SWIG_DIR "/swig")
|
||||||
|
include(UseSWIG)
|
||||||
|
|
||||||
|
swig_add_library(example LANGUAGE python TYPE MODULE SOURCES example.i)
|
||||||
|
|
||||||
|
get_property(prefix TARGET ${SWIG_MODULE_example_REAL_NAME} PROPERTY PREFIX)
|
||||||
|
message(STATUS "PREFIX='${prefix}'")
|
||||||
|
message(STATUS "TARGET NAME='${SWIG_MODULE_example_REAL_NAME}'")
|
||||||
3
Tests/RunCMake/UseSWIG/CMakeLists.txt
Normal file
3
Tests/RunCMake/UseSWIG/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(${RunCMake_TEST} C)
|
||||||
|
include(${RunCMake_TEST}.cmake)
|
||||||
5
Tests/RunCMake/UseSWIG/RunCMakeTest.cmake
Normal file
5
Tests/RunCMake/UseSWIG/RunCMakeTest.cmake
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
include(RunCMake)
|
||||||
|
|
||||||
|
run_cmake(CMP0078-WARN)
|
||||||
|
run_cmake(CMP0078-OLD)
|
||||||
|
run_cmake(CMP0078-NEW)
|
||||||
2
Tests/RunCMake/UseSWIG/example.i
Normal file
2
Tests/RunCMake/UseSWIG/example.i
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/* File : example.i */
|
||||||
|
%module example
|
||||||
@@ -58,7 +58,6 @@ if(${language} MATCHES lua)
|
|||||||
set(SWIG_LANG_LIBRARIES ${LUA_LIBRARIES})
|
set(SWIG_LANG_LIBRARIES ${LUA_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
|
|
||||||
unset(CMAKE_SWIG_FLAGS)
|
unset(CMAKE_SWIG_FLAGS)
|
||||||
|
|
||||||
set (CMAKE_INCLUDE_CURRENT_DIR ON)
|
set (CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.12)
|
cmake_minimum_required(VERSION 3.12...3.13)
|
||||||
|
|
||||||
project(TestBasicCsharp CXX CSharp)
|
project(TestBasicCsharp CXX CSharp)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.1...3.13)
|
||||||
|
|
||||||
project(TestBasicPerl CXX)
|
project(TestBasicPerl CXX)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.1...3.13)
|
||||||
|
|
||||||
project(TestBasicPython CXX)
|
project(TestBasicPython CXX)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.1...3.13)
|
||||||
|
|
||||||
project(TestModuleVersion2 CXX)
|
project(TestModuleVersion2 CXX)
|
||||||
|
|
||||||
@@ -16,7 +16,6 @@ else()
|
|||||||
set (PS ":")
|
set (PS ":")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
|
|
||||||
set (UseSWIG_MODULE_VERSION 2)
|
set (UseSWIG_MODULE_VERSION 2)
|
||||||
unset(CMAKE_SWIG_FLAGS)
|
unset(CMAKE_SWIG_FLAGS)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.1...3.13)
|
||||||
|
|
||||||
project(TestMultipleModules CXX)
|
project(TestMultipleModules CXX)
|
||||||
|
|
||||||
@@ -19,7 +19,6 @@ else()
|
|||||||
set (PS ":")
|
set (PS ":")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
|
|
||||||
unset(CMAKE_SWIG_FLAGS)
|
unset(CMAKE_SWIG_FLAGS)
|
||||||
|
|
||||||
set_property(SOURCE "../example.i" PROPERTY CPLUSPLUS ON)
|
set_property(SOURCE "../example.i" PROPERTY CPLUSPLUS ON)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.1...3.13)
|
||||||
|
|
||||||
project(TestMultiplePython CXX)
|
project(TestMultiplePython CXX)
|
||||||
|
|
||||||
@@ -17,7 +17,6 @@ else()
|
|||||||
set (PS ":")
|
set (PS ":")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
|
|
||||||
unset(CMAKE_SWIG_FLAGS)
|
unset(CMAKE_SWIG_FLAGS)
|
||||||
|
|
||||||
set_property(SOURCE "../example.i" PROPERTY CPLUSPLUS ON)
|
set_property(SOURCE "../example.i" PROPERTY CPLUSPLUS ON)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.1...3.13)
|
||||||
|
|
||||||
project(TestUseTargetINCLUDE_DIRECTORIES CXX)
|
project(TestUseTargetINCLUDE_DIRECTORIES CXX)
|
||||||
|
|
||||||
@@ -9,7 +9,6 @@ include(${SWIG_USE_FILE})
|
|||||||
|
|
||||||
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
|
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
|
||||||
|
|
||||||
set(UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
|
|
||||||
unset(CMAKE_SWIG_FLAGS)
|
unset(CMAKE_SWIG_FLAGS)
|
||||||
|
|
||||||
set_property(SOURCE "example.i" PROPERTY CPLUSPLUS ON)
|
set_property(SOURCE "example.i" PROPERTY CPLUSPLUS ON)
|
||||||
|
|||||||
Reference in New Issue
Block a user