From 6d25aa0f94a8fb7f263b88eb3b0c0d15c1d88ed6 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 3 Jul 2018 11:33:04 +0200 Subject: cmake: Fix python2 and python3 detection Signed-off-by: Andreas Schneider --- src/python/python2/CMakeLists.txt | 40 ++++++++++++++++++++++++--------------- src/python/python3/CMakeLists.txt | 40 ++++++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/python/python2/CMakeLists.txt b/src/python/python2/CMakeLists.txt index faceec3..02b4063 100644 --- a/src/python/python2/CMakeLists.txt +++ b/src/python/python2/CMakeLists.txt @@ -1,23 +1,33 @@ project(python2-pamtest C) -unset(PYTHON_EXECUTABLE CACHE) -unset(PYTHON_INCLUDE_DIR CACHE) -unset(PYTHON_LIBRARY CACHE) -unset(PYTHON_SITELIB CACHE) -unset(PYTHONLIBS_FOUND CACHE) -unset(PYTHONLIBS_VERSION_STRING CACHE) +if (NOT PYTHON2_LIBRARY) + unset(PYTHON_EXECUTABLE CACHE) + unset(PYTHON_INCLUDE_DIR CACHE) + unset(PYTHON_LIBRARY CACHE) + unset(PYTHON_SITELIB CACHE) + unset(PYTHONLIBS_FOUND CACHE) + unset(PYTHONLIBS_VERSION_STRING CACHE) -set(Python_ADDITIONAL_VERSIONS 2.7 2.6) -find_package(PythonLibs) -find_package(PythonInterp) -find_package(PythonSiteLibs) + find_package(PythonLibs 2) + find_package(PythonInterp 2) + find_package(PythonSiteLibs 2) -if (PYTHONLIBS_FOUND) - set(PYTHON2_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "PYTHON2_EXECUTABLE") - set(PYTHON2_INCLUDE_DIR ${PYTHON_INCLUDE_DIR}) - set(PYTHON2_LIBRARY ${PYTHON_LIBRARY}) - set(PYTHON2_SITELIB ${PYTHON_SITELIB}) + if (PYTHONLIBS_FOUND) + set(PYTHON2_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "PYTHON2_EXECUTABLE") + set(PYTHON2_INCLUDE_DIR ${PYTHON_INCLUDE_DIR}) + set(PYTHON2_LIBRARY ${PYTHON_LIBRARY}) + set(PYTHON2_SITELIB ${PYTHON_SITELIB}) + endif() + unset(PYTHON_EXECUTABLE CACHE) + unset(PYTHON_INCLUDE_DIR CACHE) + unset(PYTHON_LIBRARY CACHE) + unset(PYTHON_SITELIB CACHE) + unset(PYTHONLIBS_FOUND CACHE) + unset(PYTHONLIBS_VERSION_STRING CACHE) +endif() + +if (PYTHON2_INCLUDE_DIR AND PYTHON2_LIBRARY AND PYTHON2_SITELIB) include_directories(${CMAKE_BINARY_DIR}) include_directories(${pam_wrapper-headers_DIR}) include_directories(${PYTHON2_INCLUDE_DIR}) diff --git a/src/python/python3/CMakeLists.txt b/src/python/python3/CMakeLists.txt index 1e1599b..1a61303 100644 --- a/src/python/python3/CMakeLists.txt +++ b/src/python/python3/CMakeLists.txt @@ -1,23 +1,33 @@ project(python3-pamtest C) -unset(PYTHON_EXECUTABLE CACHE) -unset(PYTHON_INCLUDE_DIR CACHE) -unset(PYTHON_LIBRARY CACHE) -unset(PYTHON_SITELIB CACHE) -unset(PYTHONLIBS_FOUND CACHE) -unset(PYTHONLIBS_VERSION_STRING CACHE) +if (NOT PYTHON3_LIBRARY) + unset(PYTHON_EXECUTABLE CACHE) + unset(PYTHON_INCLUDE_DIR CACHE) + unset(PYTHON_LIBRARY CACHE) + unset(PYTHON_SITELIB CACHE) + unset(PYTHONLIBS_FOUND CACHE) + unset(PYTHONLIBS_VERSION_STRING CACHE) -set(Python_ADDITIONAL_VERSIONS 3.8 3.7 3.6) -find_package(PythonLibs) -find_package(PythonInterp) -find_package(PythonSiteLibs) + find_package(PythonLibs 3) + find_package(PythonInterp 3) + find_package(PythonSiteLibs 3) -if (PYTHONLIBS_FOUND) - set(PYTHON3_LIBRARY ${PYTHON_LIBRARY}) - set(PYTHON3_INCLUDE_DIR ${PYTHON_INCLUDE_DIR}) - set(PYTHON3_SITELIB ${PYTHON_SITELIB}) - set(PYTHON3_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "PYTHON3_EXECUTABLE") + if (PYTHONLIBS_FOUND) + set(PYTHON3_LIBRARY ${PYTHON_LIBRARY}) + set(PYTHON3_INCLUDE_DIR ${PYTHON_INCLUDE_DIR}) + set(PYTHON3_SITELIB ${PYTHON_SITELIB}) + set(PYTHON3_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "PYTHON3_EXECUTABLE") + endif() + unset(PYTHON_EXECUTABLE CACHE) + unset(PYTHON_INCLUDE_DIR CACHE) + unset(PYTHON_LIBRARY CACHE) + unset(PYTHON_SITELIB CACHE) + unset(PYTHONLIBS_FOUND CACHE) + unset(PYTHONLIBS_VERSION_STRING CACHE) +endif() + +if (PYTHON3_INCLUDE_DIR AND PYTHON3_LIBRARY AND PYTHON3_SITELIB) include_directories(${CMAKE_BINARY_DIR}) include_directories(${pam_wrapper-headers_DIR}) include_directories(${PYTHON3_INCLUDE_DIR}) -- cgit v1.1