Search code examples
cmakeyoctopybind11

install targets after pybind11_add_module in cmake and Yocto


I am trying to use python to interfacing my own c++ library. Actually I can do it manually copying pybind11_example.so to the target device. I hope to do this by using install(TARGETS...

I found this link. But it doesn't help in my Yocto build.

This is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.14.4)
project(pybind11_example)

set(CMAKE_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../lib/math/include")

find_package(PythonLibs REQUIRED)
set(PYTHON_MODULE_EXTENSION ".so" CACHE INTERNAL "Cross python lib extension")

find_package(pybind11 REQUIRED)
pybind11_add_module(${PROJECT_NAME} pybind11_wrapper.cpp)

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_INCLUDE_PATH})
target_link_libraries(${PROJECT_NAME} PRIVATE simplemath)

include(GNUInstallDirs)

# without lines below, yocto build works fine
install(TARGETS ${PROJECT_NAME}
  COMPONENT python
  RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
  LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
  ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")

This is the error from devtool build:

ERROR: pybind11-example-1.0+git999-r0 do_package: QA Issue: pybind11-example: Files/directories were installed but not shipped in any package:
  /usr/lib/pybind11_example.so
Please set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install.
pybind11-example: 1 installed and not shipped files. [installed-vs-shipped]
ERROR: pybind11-example-1.0+git999-r0 do_package: Fatal QA errors found, failing task.

Solution

  • Oops, I found the reason. The problem was not in cmake but in .bb file. After I add FILES_${PN} += "/usr/lib" in the .bb, it works fine.

    For more detail, please see this link.