Cmake niceties for Python3, like librepo does it.
authorRalph Bean <rbean@redhat.com>
Mon, 23 Nov 2015 19:16:41 +0000 (14:16 -0500)
committerRalph Bean <rbean@redhat.com>
Mon, 23 Nov 2015 19:16:41 +0000 (14:16 -0500)
CMakeLists.txt
README.md
src/python/CMakeLists.txt
tests/python/tests/CMakeLists.txt
tests/python/tests/run_nosetests.sh.in

index 10ea85c411d150e87ff66954cf435324dc780ad1..c4f06f80f327140a6f67ace556fc14346c5ff44e 100644 (file)
@@ -91,6 +91,11 @@ SET (VERSION "${CR_MAJOR}.${CR_MINOR}.${CR_PATCH}")
 message("Package version: ${VERSION}")
 
 
+# Default python version
+if (NOT PYTHON_DESIRED)
+    set (PYTHON_DESIRED "2")
+endif()
+
 # Other files
 
 pkg_check_modules(BASHCOMP bash-completion)
index 6a1e247b897fe8538bd3eebdccaf6caa869616d3..53c513937c1e9d9704ece6dfe43d7db203a33ffe 100644 (file)
--- a/README.md
+++ b/README.md
@@ -73,14 +73,9 @@ where the path is path to your build of drpm library.
 
 ## Building for a different Python version
 
-By default, cmake should find the default version of python on your system
-(say, Python 2), but if you want to build for Python 3 you need to specify
-parameters like the following:
-
-    cmake \
-        -DPYTHON_LIBRARY=/usr/lib64/libpython3.4m.so \
-        -DPYTHON_INCLUDE_DIR=/usr/include/python3.4m \
-        -D PYTHON_EXECUTABLE=/usr/bin/python3 .
+By default, cmake should set up things to build for Python 2, but you can do a build for Python 3 like this::
+
+    cmake -DPYTHON_DESIRED=2 .
 
 ## Build tarball
 
index 551c6eda2dc7198f37b1b557a325060c1bff5ad5..9f1ac6420981e651902d6e34592a860464ee7d06 100644 (file)
@@ -1,5 +1,24 @@
-FIND_PACKAGE (PythonLibs 2)
-FIND_PACKAGE (PythonInterp 2 REQUIRED)
+if (${PYTHON_DESIRED} STREQUAL "2")
+    unset(PYTHON_LIBRARY)
+    unset(PYTHON_INCLUDE_DIR)
+    unset(PYTHON_EXECUTABLE)
+    unset(PYTHON_LIBRARY CACHE)
+    unset(PYTHON_INCLUDE_DIR CACHE)
+    unset(PYTHON_EXECUTABLE CACHE)
+    FIND_PACKAGE(PythonLibs 2)
+    FIND_PACKAGE(PythonInterp 2 REQUIRED)
+else()
+    SET(Python_ADDITIONAL_VERSIONS 3.0)
+    unset(PYTHON_LIBRARY)
+    unset(PYTHON_INCLUDE_DIR)
+    unset(PYTHON_EXECUTABLE)
+    unset(PYTHON_LIBRARY CACHE)
+    unset(PYTHON_INCLUDE_DIR CACHE)
+    unset(PYTHON_EXECUTABLE CACHE)
+    FIND_PACKAGE(PythonLibs 3.0)
+    FIND_PACKAGE(PythonInterp 3.0 REQUIRED)
+endif()
+
 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)
 INCLUDE_DIRECTORIES (${PYTHON_INCLUDE_PATH})
 
index e0651e9809a6208c7712197a0bbde11c5323e949..e9aab054cca653407a762451c03df04e5dbe9693 100644 (file)
@@ -1,2 +1,15 @@
+# Detect nosetest version suffix
+EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write('%s.%s' % (sys.version_info[0], sys.version_info[1]))" OUTPUT_VARIABLE PYTHON_MAJOR_DOT_MINOR_VERSION)
+SET(NOSETEST_VERSION_SUFFIX "-${PYTHON_MAJOR_DOT_MINOR_VERSION}")
+message("-- nosetests program is nosetests${NOSETEST_VERSION_SUFFIX}")
+
+execute_process(COMMAND which nosetests${NOSETEST_VERSION_SUFFIX}
+                OUTPUT_QUIET ERROR_QUIET
+                RESULT_VARIABLE NOSE_CHECK_RESULT)
+IF (NOT NOSE_CHECK_RESULT STREQUAL "0")
+    MESSAGE("Command 'nosetests${NOSETEST_VERSION_SUFFIX}' doesn't exist! Using only 'nosetests' instead")
+    SET(NOSETEST_VERSION_SUFFIX "")
+ENDIF()
+
 CONFIGURE_FILE("run_nosetests.sh.in"  "${CMAKE_BINARY_DIR}/tests/python/tests/run_nosetests.sh")
 ADD_TEST(test_python run_nosetests.sh -s ${CMAKE_CURRENT_SOURCE_DIR})
index 02c956b9117042989477bcb0edc9969b6d1129b7..61d130a79a24c022d8daece6559c5991bb1ff1f2 100755 (executable)
@@ -1 +1 @@
-LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/: PYTHONPATH=${CMAKE_BINARY_DIR}/src/python/ nosetests -s -v ${CMAKE_CURRENT_SOURCE_DIR}/
+LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/: PYTHONPATH=${CMAKE_BINARY_DIR}/src/python/ nosetests${NOSETEST_VERSION_SUFFIX} -s -v ${CMAKE_CURRENT_SOURCE_DIR}/