-#SET (PythonLibs_FIND_VERSION 3)
-
-FIND_PACKAGE (PythonLibs)
+IF (ENABLE_PYTHON3 AND NOT DEFINED PythonLibs_FIND_VERSION)
+ # if we build both for python2 and python3, make this the python2 build.
+ # see comment in the python3 CMakeLists.txt file
+ SET (PythonLibs_FIND_VERSION 2)
+ SET (PythonLibs_FIND_VERSION_MAJOR 2)
+ENDIF IF (ENABLE_PYTHON3 AND NOT DEFINED PythonLibs_FIND_VERSION)
+
+FIND_PACKAGE (PythonLibs REQUIRED)
FIND_PACKAGE (PythonInterp ${PYTHONLIBS_VERSION_STRING} REQUIRED)
+
EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "from sys import stdout; from distutils import sysconfig; stdout.write(sysconfig.get_python_lib(True))" OUTPUT_VARIABLE PYTHON_INSTALL_DIR)
IF (NOT DEFINED PYTHON_VERSION_MAJOR)
-# Needs the following cache variables:
#
-# PYTHON3_EXECUTABLE
-# PYTHON3_INCLUDE_DIR
+# used for building both python2 and python3 bindings
+# do not use if you want to build just one flavor, use the
+# standard python bindings file in that case.
#
+# we cannot use FIND_PACKAGE PythonLibs here, as this would
+# clash with the python variables.
+#
+IF (NOT DEFINED ${PYTHON3_EXECUTABLE})
+SET (PYTHON3_EXECUTABLE "/usr/bin/python3")
+ENDIF (NOT DEFINED ${PYTHON3_EXECUTABLE})
+
EXECUTE_PROCESS(COMMAND ${PYTHON3_EXECUTABLE} -c "from sys import stdout; from distutils import sysconfig; stdout.write(sysconfig.get_python_lib(True))" OUTPUT_VARIABLE PYTHON3_INSTALL_DIR)
+EXECUTE_PROCESS(COMMAND ${PYTHON3_EXECUTABLE} -c "from sys import stdout; from distutils import sysconfig; stdout.write(sysconfig.get_python_inc())" OUTPUT_VARIABLE PYTHON3_INCLUDE_DIR)
MESSAGE (STATUS "Python3 executable: ${PYTHON3_EXECUTABLE}")
MESSAGE (STATUS "Python3 installation dir: ${PYTHON3_INSTALL_DIR}")
CMAKE_FLAGS="-DSUSE=1 -DENABLE_APPDATA=1 -DENABLE_COMPS=1"
%endif
-%if %{with python3_binding}
-# build both for python2 and python3
-CMAKE_FLAGS="$CMAKE_FLAGS -DPythonLibs_FIND_VERSION=2 -DPythonLibs_FIND_VERSION_MAJOR=2 -DENABLE_PYTHON3=1 -DPYTHON3_EXECUTABLE=/usr/bin/python3 -DPYTHON3_INCLUDE_DIR=$(/usr/bin/python3-config --includes | sed -e 's/ .*//' -e 's/-I//')"
-%endif
-
cmake $CMAKE_FLAGS \
-DCMAKE_INSTALL_PREFIX=%{_prefix} \
-DLIB=%{_lib} \
%{?with_disable_shared:-DDISABLE_SHARED=1} \
%{?with_perl_binding:-DENABLE_PERL=1} \
%{?with_python_binding:-DENABLE_PYTHON=1} \
+ %{?with_python3_binding:-DENABLE_PYTHON3=1} \
%{?with_ruby_binding:-DENABLE_RUBY=1} \
%{?with_zypp:-DENABLE_SUSEREPO=1 -DENABLE_HELIXREPO=1} \
-DUSE_VENDORDIRS=1 \