1

I am trying to use / learn CMake to embed Python into a C++ application that uses Qt.

I am using FIND_PACKAGE in an attempt to get a non-system package installation (Anaconda Python 2.7.9) in. I can not get the compiler to see any version other than the system installation (version 2.7.5).

My CMakeLists.txt is:

#Minimum CMAKE version
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

#Name the project
PROJECT(embedpython)

#Set the version number
SET(embedpython_VERSION_MAJOR 0)
SET(embedpython_VERSION_MINOR 1)

SET(CMAKE_AUTOMOC ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
FIND_PACKAGE(Qt4 4.8.6 REQUIRED QtGui QtCore)

QT4_WRAP_CPP(embedpython_HEADERS_MOC ${embedpython_HEADERS})
message(status "QT FOUND: ${Qt4_FOUND}")

FIND_PACKAGE(PythonLibs 2.7.9 REQUIRED)
message(status "libs found: ${PYTHONLIBS_FOUND}")
MESSAGE(STATUS "PYTHON_LIBRARIES: ${PYTHON_LIBRARIES}")
MESSAGE(STATUS "PYTHON_INCLUDE_PATH: ${PYTHON_INCLUDE_PATH}")
MESSAGE(STATUS "PYTHONLIBS_VERSION: ${PYTHONLIBS_VERSION_STRING}")
MESSAGE(STATUS "PYTHON_INCLUDE_DIRS: ${PYTHON_INCLUDE_DIRS}")

INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})

INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

SET(embedpython_SOURCES
    main.cpp
    mainwindow.cpp
    pythonutilsimpl.cpp
    ipcepythonrunner.cpp)

SET(embedpython_HEADERS
    mainwindow.h
    pythonutilsimpl.h
    ipcepythonutils.h
    ipcepythonrunner.h)

ADD_EXECUTABLE(embedpython ${embedpython_SOURCES} ${embedpython_HEADERS_MOC})

TARGET_LINK_LIBRARIES(embedpython ${QT_LIBRARIES} ${PYTHON_LIBRARIES})

Which outputs:

cmpt:build user$ /Applications/CMake.app/Contents/bin/cmake .. && make
statusQT FOUND: TRUE
statuslibs found: TRUE
-- PYTHON_LIBRARIES: /home/me/anaconda/lib/libpython2.7.dylib
-- PYTHON_INCLUDE_PATH: /home/me/anaconda/include/python2.7
-- PYTHONLIBS_VERSION: 2.7.9
-- PYTHON_INCLUDE_DIRS: /home/me/anaconda/include/python2.7
-- Configuring done
-- Generating done
-- Build files have been written to: /home/me/Desktop/EmbedPython/build
Scanning dependencies of target embedpython_automoc
[ 16%] Automatic moc for target embedpython
Generating moc_mainwindow.cpp
[ 16%] Built target embedpython_automoc
Scanning dependencies of target embedpython
[ 33%] Building CXX object CMakeFiles/embedpython.dir/main.cpp.o
[ 50%] Building CXX object CMakeFiles/embedpython.dir/mainwindow.cpp.o
[ 66%] Building CXX object CMakeFiles/embedpython.dir/pythonutilsimpl.cpp.o
[ 83%] Building CXX object CMakeFiles/embedpython.dir/ipcepythonrunner.cpp.o
[100%] Building CXX object CMakeFiles/embedpython.dir/embedpython_automoc.cpp.o
Linking CXX executable embedpython
[100%] Built target embed python

Using ccmake, I have set PYTHON_INCLUDE_DIR and PYTHON_LIBRARY so that FIND_PACKAGE succeeds in finding Python 2.7.9.

Within the C++ I have a debug to print the python version and path. Without fail, this returns Python 2.7.5. What is required in the CMake file to get the version of Python at the PATH I am aiming for?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.