Author: rinrab
Date: Thu Aug  8 18:44:01 2024
New Revision: 1919757

URL: http://svn.apache.org/viewvc?rev=1919757&view=rev
Log:
On the 'cmake' branch: Finally, support compilation of Python SWIG bindings.

* build/cmake/Findpy3c.cmake: New CMake module for the py3c library.
* build/generator/templates/targets.cmake.ezt
  (swig.python): Add -nofastunpack option to Python SWIG compilation using
   SWIG_COMPILE_OPTIONS target property.
* CMakeLists.txt
  (python dependency): Rework finding of the package to request the
   Development.Embed component if it is required by Python SWIG bindings.
  (external-python): aAdd finding of py3c library, create the target with
   correct include directories and link it against found py3c library.

Added:
    subversion/branches/cmake/build/cmake/Findpy3c.cmake
Modified:
    subversion/branches/cmake/CMakeLists.txt
    subversion/branches/cmake/build/generator/templates/targets.cmake.ezt

Modified: subversion/branches/cmake/CMakeLists.txt
URL: 
http://svn.apache.org/viewvc/subversion/branches/cmake/CMakeLists.txt?rev=1919757&r1=1919756&r2=1919757&view=diff
==============================================================================
--- subversion/branches/cmake/CMakeLists.txt (original)
+++ subversion/branches/cmake/CMakeLists.txt Thu Aug  8 18:44:01 2024
@@ -242,7 +242,18 @@ if (SVN_ENABLE_RA_SERF)
   add_library(external-serf ALIAS Serf::Serf)
 endif()
 
-find_package(Python COMPONENTS Interpreter REQUIRED)
+### Python
+
+if(SVN_ENABLE_SWIG_PYTHON)
+  find_package(Python REQUIRED COMPONENTS
+      Interpreter
+      Development.Embed
+  )
+else()
+  find_package(Python REQUIRED COMPONENTS
+      Interpreter
+  )
+endif()
 
 if(SVN_ENABLE_SWIG_PERL OR SVN_ENABLE_SWIG_PYTHON OR SVN_ENABLE_SWIG_RUBY)
   find_package(SWIG REQUIRED)
@@ -259,6 +270,20 @@ if(SVN_ENABLE_SWIG_PERL OR SVN_ENABLE_SW
   add_library(external-swig INTERFACE)
 endif()
 
+if(SVN_ENABLE_SWIG_PYTHON)
+  find_package(py3c REQUIRED)
+
+  add_library(external-python INTERFACE)
+  target_link_libraries(external-python INTERFACE
+    Python::Python
+    Python::py3c
+  )
+  target_include_directories(external-python INTERFACE
+    ${SWIG_INCLUDE_DIRECTORIES}
+    ${CMAKE_CURRENT_SOURCE_DIR}/subversion/bindings/swig/python/libsvn_swig_py
+  )
+endif()
+
 function(target_exports target_name)
   if (WIN32)
     set(def_file_path "${CMAKE_BINARY_DIR}/${target_name}.def")

Added: subversion/branches/cmake/build/cmake/Findpy3c.cmake
URL: 
http://svn.apache.org/viewvc/subversion/branches/cmake/build/cmake/Findpy3c.cmake?rev=1919757&view=auto
==============================================================================
--- subversion/branches/cmake/build/cmake/Findpy3c.cmake (added)
+++ subversion/branches/cmake/build/cmake/Findpy3c.cmake Thu Aug  8 18:44:01 
2024
@@ -0,0 +1,46 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# Findpy3c.cmake -- CMake module for py3c library
+#
+
+find_path(PY3C_INCLUDE_DIR
+  NAMES py3c.h
+  PATH_SUFFIXES
+    "include/py3c"
+)
+
+mark_as_advanced(
+  PY3C_INCLUDE_DIR
+)
+
+include(FindPackageHandleStandardArgs)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(
+  py3c
+  REQUIRED_VARS
+    PY3C_INCLUDE_DIR
+)
+
+# TODO: Is it okay to put py3c into 'Python' namespace?
+if(py3c_FOUND AND NOT TARGET Python::py3c)
+  add_library(Python::py3c IMPORTED INTERFACE)
+  set_target_properties(Python::py3c PROPERTIES
+    INTERFACE_INCLUDE_DIRECTORIES ${PY3C_INCLUDE_DIR}
+  )
+endif()

Modified: subversion/branches/cmake/build/generator/templates/targets.cmake.ezt
URL: 
http://svn.apache.org/viewvc/subversion/branches/cmake/build/generator/templates/targets.cmake.ezt?rev=1919757&r1=1919756&r2=1919757&view=diff
==============================================================================
--- subversion/branches/cmake/build/generator/templates/targets.cmake.ezt 
(original)
+++ subversion/branches/cmake/build/generator/templates/targets.cmake.ezt Thu 
Aug  8 18:44:01 2024
@@ -29,7 +29,10 @@ if ([targets.enable_condition])[is targe
   set_target_properties([targets.name] PROPERTIES
     SWIG_INCLUDE_DIRECTORIES "${SWIG_INCLUDE_DIRECTORIES}"
     INCLUDE_DIRECTORIES "${SWIG_INCLUDE_DIRECTORIES}"
-  )
+  )[is targets.swig_lang "python"]
+  set_target_properties([targets.name] PROPERTIES
+    SWIG_COMPILE_OPTIONS "-nofastunpack"
+  )[end]
   target_link_libraries([targets.name] PRIVATE[for targets.libs]
     [targets.libs][end]
     external-[targets.swig_lang]


Reply via email to