Finding python site-packages directory with CMake

前端 未结 4 1077
野的像风
野的像风 2020-12-31 05:29

I use CMake to build my application. How can I find where the python site-packages directory is located? I need the path in order to compile an extension to python.

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-31 05:46

    Since CMake 3.12 you can use FindPython module which populates Python_SITELIB and Python_SITEARCH variables for architecture independent and specific libraries, respectively.

    Example:

    find_package(Python ${PYTHON_VERSION} REQUIRED COMPONENTS Development)
    Python_add_library(foo MODULE
        src/foo.cc src/python_interface.cc
    )
    install(TARGETS foo DESTINATION ${Python_SITEARCH}/foo)
    

提交回复
热议问题