Skip to content

Instantly share code, notes, and snippets.

@mic-e
Last active August 29, 2015 14:08
Show Gist options
  • Save mic-e/01151d6fc08467d58577 to your computer and use it in GitHub Desktop.
Save mic-e/01151d6fc08467d58577 to your computer and use it in GitHub Desktop.
minimal cmake python test
# testing instructions:
# - save this file as /tmp/x/CMakeLists.txt
# - cd /tmp/x
# - cmake .
# - paste output and your distro version in comments
cmake_minimum_required(VERSION 2.8)
# cmake 2.8 doesn't know about python3.4
set(Python_ADDITIONAL_VERSIONS 3.4)
# find py libs
find_package(PythonLibs 3.3 REQUIRED)
message("PYTHON_LIBRARY: ${PYTHON_LIBRARY}")
message("PYTHON_INCLUDE_DIR: ${PYTHON_INCLUDE_DIR}")
message("PYTHONLIBS_VERSION_STRING: ${PYTHONLIBS_VERSION_STRING}")
# on some distros (ubuntu 13.10) there seems to be additional clutter at the end,
# which needs to be stripped to prevent find_package(PythonInterp) from erroring.
if(PYTHONLIBS_VERSION_STRING MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)([^0-9].*)?$")
set(PYTHON_SANITIZED_VERSION "${CMAKE_MATCH_1}")
else()
message(WARNING "PYTHONLIBS_VERSION_STRING is ${PYTHONLIBS_VERSION_STRING}, expected major.minor.patch*")
set(PYTHON_SANITIZED_VERSION "${PYTHONLIBS_VERSION_STRING}")
endif()
message("PYTHON_SANITIZED_VERSION: ${PYTHON_SANITIZED_VERSION}")
# find python interpreter with the exact version of the chosen pythonlibs
find_package(PythonInterp "${PYTHON_SANITIZED_VERSION}" EXACT REQUIRED)
message("PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}")
message("PYTHON_VERSION_STRING: ${PYTHON_VERSION_STRING}")
@phoenix24
Copy link

distro details below -

Linux csharma-desktop 3.11.0-14-generic #21-Ubuntu SMP Tue Nov 12 17:04:55 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
ubuntu 13.10
gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
cmake version 2.8.11.2
Python 3.3.2+

script output below

PYTHON_LIBRARY:            /usr/lib/x86_64-linux-gnu/libpython3.3m.so
PYTHON_INCLUDE_DIR:        /usr/include/python3.3m
PYTHONLIBS_VERSION_STRING: 3.3.2+
PYTHON_SANITIZED_VERSION:  3.3.2
-- Found PythonInterp: /usr/bin/python3.3 (found suitable exact version "3.3.2")
PYTHON_EXECUTABLE:         /usr/bin/python3.3
PYTHON_VERSION_STRING:     3.3.2
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/tesrt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment