forked from pool/pam_wrapper
208 lines
6.9 KiB
Diff
208 lines
6.9 KiB
Diff
From 5c36d4284918a3fcc1c58f29f01ca64c65a66fa7 Mon Sep 17 00:00:00 2001
|
|
From: Andreas Schneider <asn@samba.org>
|
|
Date: Mon, 12 Feb 2018 12:01:22 +0100
|
|
Subject: [PATCH] cmake: Build python2 and python3 modules if possible
|
|
|
|
Signed-off-by: Andreas Schneider <asn@samba.org>
|
|
Reviewed-by: Ralph Boehme <slow@samba.org>
|
|
---
|
|
CMakeLists.txt | 5 -----
|
|
src/CMakeLists.txt | 4 +---
|
|
src/python/CMakeLists.txt | 15 ++-------------
|
|
src/python/python2/CMakeLists.txt | 33 +++++++++++++++++++++++++++++++++
|
|
src/python/python3/CMakeLists.txt | 33 +++++++++++++++++++++++++++++++++
|
|
tests/CMakeLists.txt | 29 ++++++++++++++++++++++-------
|
|
tests/pypamtest_test.py | 5 ++++-
|
|
7 files changed, 95 insertions(+), 29 deletions(-)
|
|
create mode 100644 src/python/python2/CMakeLists.txt
|
|
create mode 100644 src/python/python3/CMakeLists.txt
|
|
|
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
index f03a137..af00610 100644
|
|
--- a/CMakeLists.txt
|
|
+++ b/CMakeLists.txt
|
|
@@ -46,11 +46,6 @@ macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source buil
|
|
set(CMAKE_THREAD_PREFER_PTHREADS ON)
|
|
find_package(Threads)
|
|
|
|
-find_package(PythonInterp)
|
|
-set(Python_ADDITIONAL_VERSIONS 2.6 2.7 3.3 3.4 3.6)
|
|
-find_package(PythonLibs)
|
|
-find_package(PythonSiteLibs)
|
|
-
|
|
# config.h checks
|
|
include(ConfigureChecks.cmake)
|
|
configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
|
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
|
|
index 76a87d6..e3a1efd 100644
|
|
--- a/src/CMakeLists.txt
|
|
+++ b/src/CMakeLists.txt
|
|
@@ -69,9 +69,7 @@ install(TARGETS pamtest
|
|
ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
|
|
|
|
add_subdirectory(modules)
|
|
-if (PYTHONLIBS_FOUND)
|
|
- add_subdirectory(python)
|
|
-endif()
|
|
+add_subdirectory(python)
|
|
|
|
# This needs to be at the end
|
|
set(PAM_WRAPPER_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}pam_wrapper${CMAKE_SHARED_LIBRARY_SUFFIX}" PARENT_SCOPE)
|
|
diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt
|
|
index cbee2a6..3394a84 100644
|
|
--- a/src/python/CMakeLists.txt
|
|
+++ b/src/python/CMakeLists.txt
|
|
@@ -1,15 +1,4 @@
|
|
project(pypamtest C)
|
|
|
|
-include_directories(${CMAKE_BINARY_DIR})
|
|
-include_directories(${pam_wrapper-headers_DIR})
|
|
-include_directories(${PYTHON_INCLUDE_DIR})
|
|
-
|
|
-python_add_module(pypamtest pypamtest.c)
|
|
-target_link_libraries(pypamtest pamtest ${PYTHON_LIBRARY})
|
|
-
|
|
-install(
|
|
- TARGETS
|
|
- pypamtest
|
|
- DESTINATION
|
|
- ${CMAKE_INSTALL_PREFIX}/${PYTHON_SITELIB}
|
|
-)
|
|
+add_subdirectory(python2)
|
|
+add_subdirectory(python3)
|
|
diff --git a/src/python/python2/CMakeLists.txt b/src/python/python2/CMakeLists.txt
|
|
new file mode 100644
|
|
index 0000000..faceec3
|
|
--- /dev/null
|
|
+++ b/src/python/python2/CMakeLists.txt
|
|
@@ -0,0 +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)
|
|
+
|
|
+set(Python_ADDITIONAL_VERSIONS 2.7 2.6)
|
|
+find_package(PythonLibs)
|
|
+find_package(PythonInterp)
|
|
+find_package(PythonSiteLibs)
|
|
+
|
|
+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})
|
|
+
|
|
+ include_directories(${CMAKE_BINARY_DIR})
|
|
+ include_directories(${pam_wrapper-headers_DIR})
|
|
+ include_directories(${PYTHON2_INCLUDE_DIR})
|
|
+
|
|
+ python_add_module(python2-pamtest ${pypamtest_SOURCE_DIR}/pypamtest.c)
|
|
+ target_link_libraries(python2-pamtest pamtest ${PYTHON2_LIBRARY})
|
|
+ set_target_properties(python2-pamtest PROPERTIES OUTPUT_NAME "pypamtest")
|
|
+
|
|
+ install(TARGETS
|
|
+ python2-pamtest
|
|
+ DESTINATION
|
|
+ ${CMAKE_INSTALL_PREFIX}/${PYTHON2_SITELIB})
|
|
+endif()
|
|
diff --git a/src/python/python3/CMakeLists.txt b/src/python/python3/CMakeLists.txt
|
|
new file mode 100644
|
|
index 0000000..1e1599b
|
|
--- /dev/null
|
|
+++ b/src/python/python3/CMakeLists.txt
|
|
@@ -0,0 +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)
|
|
+
|
|
+set(Python_ADDITIONAL_VERSIONS 3.8 3.7 3.6)
|
|
+find_package(PythonLibs)
|
|
+find_package(PythonInterp)
|
|
+find_package(PythonSiteLibs)
|
|
+
|
|
+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")
|
|
+
|
|
+ include_directories(${CMAKE_BINARY_DIR})
|
|
+ include_directories(${pam_wrapper-headers_DIR})
|
|
+ include_directories(${PYTHON3_INCLUDE_DIR})
|
|
+
|
|
+ python_add_module(python3-pamtest ${pypamtest_SOURCE_DIR}/pypamtest.c)
|
|
+ target_link_libraries(python3-pamtest pamtest ${PYTHON3_LIBRARY})
|
|
+ set_target_properties(python3-pamtest PROPERTIES OUTPUT_NAME "pypamtest")
|
|
+
|
|
+ install(TARGETS
|
|
+ python3-pamtest
|
|
+ DESTINATION
|
|
+ ${CMAKE_INSTALL_PREFIX}/${PYTHON3_SITELIB})
|
|
+endif()
|
|
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
|
|
index 30f0eb2..997c15e 100644
|
|
--- a/tests/CMakeLists.txt
|
|
+++ b/tests/CMakeLists.txt
|
|
@@ -47,11 +47,26 @@ set_property(
|
|
PROPERTY
|
|
ENVIRONMENT ${TEST_ENVIRONMENT})
|
|
|
|
-if (PYTHONLIBS_FOUND)
|
|
- add_test(pypamtest_test ${CMAKE_CURRENT_SOURCE_DIR}/pypamtest_test.py)
|
|
- set_property(
|
|
- TEST
|
|
- pypamtest_test
|
|
- PROPERTY
|
|
- ENVIRONMENT ${TEST_ENVIRONMENT})
|
|
+if (PYTHON2_EXECUTABLE)
|
|
+ add_test(NAME
|
|
+ py2pamtest_test
|
|
+ COMMAND
|
|
+ ${PYTHON2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pypamtest_test.py)
|
|
+
|
|
+ set_property(TEST
|
|
+ py2pamtest_test
|
|
+ PROPERTY
|
|
+ ENVIRONMENT ${TEST_ENVIRONMENT})
|
|
+endif()
|
|
+
|
|
+if (PYTHON3_EXECUTABLE)
|
|
+ add_test(NAME
|
|
+ py3pamtest_test
|
|
+ COMMAND
|
|
+ ${PYTHON3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pypamtest_test.py)
|
|
+
|
|
+ set_property(TEST
|
|
+ py3pamtest_test
|
|
+ PROPERTY
|
|
+ ENVIRONMENT ${TEST_ENVIRONMENT})
|
|
endif()
|
|
diff --git a/tests/pypamtest_test.py b/tests/pypamtest_test.py
|
|
index 2c74c0b..32ef65d 100755
|
|
--- a/tests/pypamtest_test.py
|
|
+++ b/tests/pypamtest_test.py
|
|
@@ -16,7 +16,10 @@ class PyPamTestCase(unittest.TestCase):
|
|
class PyPamTestImport(unittest.TestCase):
|
|
def setUp(self):
|
|
" Make sure we load the in-tree module "
|
|
- self.modpath = os.path.join(os.getcwd(), "../src/python")
|
|
+ if sys.hexversion >= 0x3000000:
|
|
+ self.modpath = os.path.join(os.getcwd(), "../src/python/python3")
|
|
+ else:
|
|
+ self.modpath = os.path.join(os.getcwd(), "../src/python/python2")
|
|
self.system_path = sys.path[:]
|
|
sys.path = [ self.modpath ]
|
|
|
|
--
|
|
2.16.1
|
|
|