Skip to content

Commit

Permalink
Fixed python discovery using more modern CMake functions. For old CMa…
Browse files Browse the repository at this point in the history
…ke they are bundled and backported. For newer CMake the ones shipped with CMake are used.
  • Loading branch information
KOLANICH committed Jan 23, 2020
1 parent 102ac55 commit 859ac92
Show file tree
Hide file tree
Showing 7 changed files with 3,332 additions and 42 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ OPTION (DISABLE_SHARED "Do not build a shared version of the libraries?" OFF)

OPTION (ENABLE_PERL "Build the perl bindings?" OFF)
OPTION (ENABLE_PYTHON "Build the python bindings?" OFF)
OPTION (ENABLE_PYTHON3 "Build the python3 bindings?" OFF)
OPTION (ENABLE_RUBY "Build the ruby bindings?" OFF)
OPTION (ENABLE_TCL "Build the Tcl bindings?" OFF)

Expand Down Expand Up @@ -55,8 +56,13 @@ ENDIF (NOT PKGCONFIG_INSTALL_DIR)
####################################################################

# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
SET (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
INSTALL( FILES ${CMAKE_MODULE_PATH}/FindLibSolv.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
SET (OUR_MODULES_DIR "${CMAKE_SOURCE_DIR}/cmake/modules")
SET (CMAKE_MODULE_PATH "${OUR_MODULES_DIR}")
IF (${CMAKE_VERSION} VERSION_LESS "3.12")
SET (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake/FindPythonFromGit")
ENDIF ()

INSTALL( FILES "${OUR_MODULES_DIR}/FindLibSolv.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/cmake/Modules" COMPONENT "libsolv-dev")

INCLUDE (${CMAKE_SOURCE_DIR}/VERSION.cmake)

Expand Down
34 changes: 6 additions & 28 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
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 (ENABLE_PYTHON3 AND NOT DEFINED PythonLibs_FIND_VERSION)
find_package (Python2 COMPONENTS Interpreter Development)

FIND_PACKAGE (PythonLibs REQUIRED)
IF(PYTHONLIBS_VERSION_STRING MATCHES "^([0-9.]+)")
SET(python_version "${CMAKE_MATCH_1}")
ELSE()
MESSAGE(FATAL_ERROR "PythonLibs version format unknown '${PYTHONLIBS_VERSION_STRING}'")
ENDIF()
FIND_PACKAGE (PythonInterp ${python_version} 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)
SET (PYTHON_VERSION_MAJOR 2)
ENDIF (NOT DEFINED PYTHON_VERSION_MAJOR)
IF (${PYTHON_VERSION_MAJOR} GREATER 2)
SET (SWIG_PY_FLAGS -DPYTHON3=1)
ENDIF (${PYTHON_VERSION_MAJOR} GREATER 2)
SET (SWIG_PY_FLAGS ${SWIG_PY_FLAGS} -DSWIG_PYTHON_LEGACY_BOOL=1)

MESSAGE (STATUS "Python executable: ${PYTHON_EXECUTABLE}")
MESSAGE (STATUS "Python installation dir: ${PYTHON_INSTALL_DIR}")
MESSAGE (STATUS "Python include path: ${PYTHON_INCLUDE_PATH}")
MESSAGE (STATUS "Python installation dir: ${Python2_STDARCH}")
MESSAGE (STATUS "Python include path: ${Python2_INCLUDE_DIRS}")

ADD_CUSTOM_COMMAND (
OUTPUT solv_python.c
Expand All @@ -35,12 +14,11 @@ ADD_CUSTOM_COMMAND (
)

ADD_DEFINITIONS(-Wno-unused)
INCLUDE_DIRECTORIES (${PYTHON_INCLUDE_PATH})
INCLUDE_DIRECTORIES (${Python2_INCLUDE_DIRS})

ADD_LIBRARY (bindings_python MODULE solv_python.c)
SET_TARGET_PROPERTIES (bindings_python PROPERTIES PREFIX "" OUTPUT_NAME "_solv")
TARGET_LINK_LIBRARIES (bindings_python libsolvext libsolv ${SYSTEM_LIBRARIES})

INSTALL (TARGETS bindings_python LIBRARY DESTINATION ${PYTHON_INSTALL_DIR})
INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/solv.py DESTINATION ${PYTHON_INSTALL_DIR})

INSTALL (TARGETS bindings_python LIBRARY DESTINATION ${Python2_STDARCH})
INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/solv.py DESTINATION ${Python2_STDARCH})
19 changes: 7 additions & 12 deletions bindings/python3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@
# 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)
find_package (Python3 COMPONENTS Interpreter Development)

SET (SWIG_PY3_FLAGS -DPYTHON3=1)
SET (SWIG_PY3_FLAGS ${SWIG_PY3_FLAGS} -DSWIG_PYTHON_LEGACY_BOOL=1)

MESSAGE (STATUS "Python3 executable: ${PYTHON3_EXECUTABLE}")
MESSAGE (STATUS "Python3 installation dir: ${PYTHON3_INSTALL_DIR}")
MESSAGE (STATUS "Python3 include path: ${PYTHON3_INCLUDE_DIR}")
MESSAGE (STATUS "Python3 executable: ${PYTHON_EXECUTABLE}")
MESSAGE (STATUS "Python3 installation dir: ${Python3_STDARCH}")
MESSAGE (STATUS "Python3 include path: ${Python3_INCLUDE_DIRS}")

ADD_CUSTOM_COMMAND (
OUTPUT solv_python.c
Expand All @@ -28,11 +23,11 @@ ADD_CUSTOM_COMMAND (
)

ADD_DEFINITIONS(-Wno-unused)
INCLUDE_DIRECTORIES (${PYTHON3_INCLUDE_DIR})
INCLUDE_DIRECTORIES (${Python3_INCLUDE_DIRS})

ADD_LIBRARY (bindings_python3 SHARED solv_python.c)
SET_TARGET_PROPERTIES (bindings_python3 PROPERTIES PREFIX "" OUTPUT_NAME "_solv")
TARGET_LINK_LIBRARIES (bindings_python3 libsolvext libsolv ${SYSTEM_LIBRARIES})

INSTALL (TARGETS bindings_python3 LIBRARY DESTINATION ${PYTHON3_INSTALL_DIR})
INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/solv.py DESTINATION ${PYTHON3_INSTALL_DIR})
INSTALL (TARGETS bindings_python3 LIBRARY DESTINATION ${Python3_STDARCH} COMPONENT "python3" )
INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/solv.py DESTINATION ${Python3_STDARCH} COMPONENT "python3" )
Loading

0 comments on commit 859ac92

Please sign in to comment.