Last active
August 29, 2015 14:08
-
-
Save mic-e/01151d6fc08467d58577 to your computer and use it in GitHub Desktop.
minimal cmake python test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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}") |
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+
fails, with below errors -
CMake Error at CMakeLists.txt:4 (find_package):
find_package called with invalid argument "3.3.2+"
/usr/include/python3.3m
/usr/lib/x86_64-linux-gnu/libpython3.3m.so
3.3.2+
-- Configuring incomplete, errors occurred!
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
I get this:
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
(Required is at least version "3.3")
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindPythonLibs.cmake:208 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:2 (find_package)