Search code examples
pythonc++cmake

How to add a directory to PYTHONPATH from CMake?


I have a c++ library which has a python API library based on Boost.python included in the directory structure.

module
|_python_files
|_cpp_files

Is there a standard way to configure CMakelist so that it automatically adds the library containing the python files to PYTHONPATH?


Solution

  • In case you use FindPython you should be able to use

    Python_add_library (my_module MODULE src1.cpp)
    

    Or you could add the path to PYTHONPATH:

    list(APPEND PYTHONPATH "${CMAKE_CURRENT_DIR}/module/python_files") 
    

    Otherwise, you want to add python_files to your python definition path:

    export PYTHONPATH="${PYTHONPATH}:../module/python_files"