summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-03-04 13:19:54 +0000
committerKitware Robot <kwrobot@kitware.com>2020-03-04 08:20:17 -0500
commitab00435e79205d6a447988f41cd53ede9ee42273 (patch)
tree6e19e16d1dca80897897c8c6621f1ebf33524016
parentb0317d9b98f35402ad18fbdb47b1f6c0ed14cc97 (diff)
parent0c97b73bc09ee34aa40667a044f05e7049d16a60 (diff)
downloadcmake-ab00435e79205d6a447988f41cd53ede9ee42273.tar.gz
Merge topic 'FindPython-manage-SOABI-suffix' into release-3.17
0c97b73bc0 FindPython: python_add_library can now manage SOABI suffix. Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !4420
-rw-r--r--Help/release/3.17.rst4
-rw-r--r--Modules/FindPython.cmake8
-rw-r--r--Modules/FindPython/Support.cmake29
-rw-r--r--Modules/FindPython2.cmake5
-rw-r--r--Modules/FindPython3.cmake10
-rw-r--r--Tests/FindPython/SOABI/CMakeLists.txt10
6 files changed, 52 insertions, 14 deletions
diff --git a/Help/release/3.17.rst b/Help/release/3.17.rst
index 30e6cc37f4..23dec84174 100644
--- a/Help/release/3.17.rst
+++ b/Help/release/3.17.rst
@@ -179,7 +179,9 @@ Modules
* The :module:`FindPython3` and :module:`FindPython` modules gained,
respectively, variable ``Python3_SOABI`` and ``Python_SOABI`` giving
- the standard extension suffix for modules.
+ the standard extension suffix for modules. Moreover, commands
+ ``Python3_add_library`` and ``Python_add_library`` gained the option
+ ``WITH_SOABI`` to prefix the library suffix with the value of ``SOABI``.
* The :module:`FindLibXml2` module now provides an imported target for the
``xmllint`` executable
diff --git a/Modules/FindPython.cmake b/Modules/FindPython.cmake
index be272e19fb..9dfa222dc2 100644
--- a/Modules/FindPython.cmake
+++ b/Modules/FindPython.cmake
@@ -297,9 +297,13 @@ This module defines the command ``Python_add_library`` (when
when library type is ``MODULE``, to target ``Python::Module`` and takes care of
Python module naming rules::
- Python_add_library (my_module MODULE src1.cpp)
+ Python_add_library (<name> [STATIC | SHARED | MODULE [WITH_SOABI]]
+ <source1> [<source2> ...])
-If library type is not specified, ``MODULE`` is assumed.
+If the library type is not specified, ``MODULE`` is assumed.
+
+For ``MODULE`` library type, if option ``WITH_SOABI`` is specified, the
+module suffix will include the ``Python_SOABI`` value, if any.
#]=======================================================================]
diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake
index 0f52008f9a..bf55bf53a8 100644
--- a/Modules/FindPython/Support.cmake
+++ b/Modules/FindPython/Support.cmake
@@ -2514,15 +2514,21 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT")
#
function (__${_PYTHON_PREFIX}_ADD_LIBRARY prefix name)
cmake_parse_arguments (PARSE_ARGV 2 PYTHON_ADD_LIBRARY
- "STATIC;SHARED;MODULE" "" "")
+ "STATIC;SHARED;MODULE;WITH_SOABI" "" "")
- unset (type)
- if (NOT (PYTHON_ADD_LIBRARY_STATIC
- OR PYTHON_ADD_LIBRARY_SHARED
- OR PYTHON_ADD_LIBRARY_MODULE))
+ if (prefix STREQUAL "Python2" AND PYTHON_ADD_LIBRARY_WITH_SOABI)
+ message (AUTHOR_WARNING "FindPython2: Option `WITH_SOABI` is not supported for Python2 and will be ignored.")
+ unset (PYTHON_ADD_LIBRARY_WITH_SOABI)
+ endif()
+
+ if (PYTHON_ADD_LIBRARY_STATIC)
+ set (type STATIC)
+ elseif (PYTHON_ADD_LIBRARY_SHARED)
+ set (type SHARED)
+ else()
set (type MODULE)
endif()
- add_library (${name} ${type} ${ARGN})
+ add_library (${name} ${type} ${PYTHON_ADD_LIBRARY_UNPARSED_ARGUMENTS})
get_property (type TARGET ${name} PROPERTY TYPE)
@@ -2533,7 +2539,18 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set_property (TARGET ${name} PROPERTY SUFFIX ".pyd")
endif()
+
+ if (PYTHON_ADD_LIBRARY_WITH_SOABI AND ${prefix}_SOABI)
+ get_property (suffix TARGET ${name} PROPERTY SUFFIX)
+ if (NOT suffix)
+ set (suffix "${CMAKE_SHARED_MODULE_SUFFIX}")
+ endif()
+ set_property (TARGET ${name} PROPERTY SUFFIX ".${${prefix}_SOABI}${suffix}")
+ endif()
else()
+ if (PYTHON_ADD_LIBRARY_WITH_SOABI)
+ message (AUTHOR_WARNING "Find${prefix}: Option `WITH_SOABI` is only supported for `MODULE` library type.")
+ endif()
target_link_libraries (${name} PRIVATE ${prefix}::Python)
endif()
endfunction()
diff --git a/Modules/FindPython2.cmake b/Modules/FindPython2.cmake
index 9d4eda2174..af8ad3913a 100644
--- a/Modules/FindPython2.cmake
+++ b/Modules/FindPython2.cmake
@@ -240,13 +240,14 @@ setting the following variables:
Commands
^^^^^^^^
-This module defines the command ``Python_add_library`` (when
+This module defines the command ``Python2_add_library`` (when
:prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
:command:`add_library` and adds a dependency to target ``Python2::Python`` or,
when library type is ``MODULE``, to target ``Python2::Module`` and takes care
of Python module naming rules::
- Python2_add_library (my_module MODULE src1.cpp)
+ Python2_add_library (<name> [STATIC | SHARED | MODULE]
+ <source1> [<source2> ...])
If library type is not specified, ``MODULE`` is assumed.
#]=======================================================================]
diff --git a/Modules/FindPython3.cmake b/Modules/FindPython3.cmake
index 00c354ed90..66f4f7581a 100644
--- a/Modules/FindPython3.cmake
+++ b/Modules/FindPython3.cmake
@@ -288,15 +288,19 @@ setting the following variables:
Commands
^^^^^^^^
-This module defines the command ``Python_add_library`` (when
+This module defines the command ``Python3_add_library`` (when
:prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
:command:`add_library` and adds a dependency to target ``Python3::Python`` or,
when library type is ``MODULE``, to target ``Python3::Module`` and takes care
of Python module naming rules::
- Python3_add_library (my_module MODULE src1.cpp)
+ Python3_add_library (<name> [STATIC | SHARED | MODULE [WITH_SOABI]]
+ <source1> [<source2> ...])
-If library type is not specified, ``MODULE`` is assumed.
+If the library type is not specified, ``MODULE`` is assumed.
+
+For ``MODULE`` library type, if option ``WITH_SOABI`` is specified, the
+module suffix will include the ``Python3_SOABI`` value, if any.
#]=======================================================================]
diff --git a/Tests/FindPython/SOABI/CMakeLists.txt b/Tests/FindPython/SOABI/CMakeLists.txt
index aea2baff1c..4a6aea3537 100644
--- a/Tests/FindPython/SOABI/CMakeLists.txt
+++ b/Tests/FindPython/SOABI/CMakeLists.txt
@@ -10,3 +10,13 @@ endif()
if(NOT DEFINED Python3_SOABI)
message(FATAL_ERROR "Python3_SOABI for ${CMake_TEST_FindPython_COMPONENT} not found")
endif()
+
+if (Python3_Development_FOUND AND Python3_SOABI)
+ Python3_add_library (spam3 MODULE WITH_SOABI ../spam.c)
+ target_compile_definitions (spam3 PRIVATE PYTHON3)
+
+ get_property (suffix TARGET spam3 PROPERTY SUFFIX)
+ if (NOT suffix MATCHES "^.${Python3_SOABI}")
+ message(FATAL_ERROR "Module suffix do not include Python3_SOABI")
+ endif()
+endif()