如何在Yocto中指定一个本地工作的CMake包含路径?

vlju58qv  于 2023-08-05  发布在  其他
关注(0)|答案(1)|浏览(202)

我正在开发一个C++应用程序,它可以从Optris thermal camera读取图像数据。要与相机对话,我使用的是Direct SDK,可以从here下载。我使用CMake在我的Linux开发机器上构建我的应用程序,它似乎工作得很好。
SDK由一个.deb文件组成,它基本上只是将一些库安装到/usr/lib中,并将一些头文件安装到/usr/include/libirimager中。
我现在正试图将这个相同的应用程序构建到我的Yocto映像中,用于Nvidia Jetson板。但是,我不能#include SDK头文件,因为我的CMakeLists.txt文件指定了libirimager头文件的绝对路径。
我已经将代码精简到重现问题所需的最低限度。
main.cpp:

#include "IRImager.h"

int main()
{
    return 0;
}

字符串
CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)

project(libir-example)

add_executable(libir-example
    main.cpp
)

target_include_directories(libir-example PRIVATE
    /usr/include/libirimager
)

target_link_libraries(libir-example PUBLIC
    irdirectsdk
)


上面的代码在我的Linux机器上正确构建。
我做了一个yocto recipe示例,它只是尝试使用CMake文件编译main.cpp
网址:libir-example.bb

DESCRIPTION = "Example of trying to build for libir"
LICENSE = "BSD"

SRCREV = "0.1"
PV = "0.1"
SRC_URI = "file://main.cpp file://CMakeLists.txt"

S = "${WORKDIR}"

DEPENDS += "optris-directsdk"

deltask do_populate_lic

inherit cmake


运行bitbake libir-example直到尝试编译它,但随后失败:

| /home/foo/build/tmp/work/armv8a-oe4t-linux/libir-example/0.1-r0/main.cpp:1:10: fatal error: IRImager.h: No such file or directory
|     1 | #include "IRImager.h"
|       |          ^~~~~~~~~~~~


上面提到的文件肯定已经复制到我的recipe-sysroot中了:

-rw-r--r-- 5 foo foo 27565 Apr  7  2022 recipe-sysroot/usr/include/libirimager/IRImager.h


我相当肯定这是因为我在CMakeLists.txt文件中有一个绝对路径,但我不确定应该使用什么。
我试着把我的include指令改成这样:

target_include_directories(libir-example PRIVATE
    ${CMAKE_SYSROOT}/usr/include/libirimager
)


但这没有效果。(传递给g++-I没有改变。)我也试过这个:

target_include_directories(libir-example PRIVATE
    ${CMAKE_BINARY_DIR}/../recipe-sysroot/usr/include/libirimager
)


这是可行的,但非常丑陋,更重要的是,这意味着我不能再在本地构建了。
我相信有一个非常简单的解决办法,我不明白。
编辑:以下是我为安装SDK到sysroot中所做的optris-directsdk配方:
optris-directsdk_8.8.5.bb:

SUMMARY = "Optris DirestSDK"
DESCRIPTION = "SDK for talking to Optris thermal cameras"
HOMEPAGE = "https://www.optris.co.uk/optris-pi-sdks"
LICENSE = "CLOSED"

inherit bin_package

SRC_URI += " \
    https://ftp.evocortex.org/libirimager-latest?arch=arm64&type=deb;subdir=optris-directsdk-8.8.5;downloadfilename=libirimager-8.8.5.deb \
"

SRC_URI[sha256sum] = "97661cd4c258c1dde55938b7d18d7be5fa9a1480e0f0b0bb96268ad62089905f"

# Force the .so files into the regular package (not the -dev one)
FILES:${PN} += "/usr/lib/lib*.so"
FILES:${PN}-dev = ""

RDEPENDS:${PN} = "libudev libusb1"

# Need this because the libraries in the SDK are already stripped, which
# bitbake does not expect

INSANE_SKIP:${PN} = "already-stripped"

# Remove the parts of the SDK that we don't need (e.g. udev rules), otherwise
# bitbake complains about things existing that are not installed.

do_install:append() {
    rm -rf ${D}/lib
    rm -rf ${D}/usr/lib/libirextras.so
}

smtd7mpg

smtd7mpg1#

你可以使用GNUInstallDirs,例如:

include(GNUInstallDirs)

...

target_include_directories(libir-example PRIVATE
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/libirimager>"
    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libirimager>"
)

字符串
或者简单地说:

include(GNUInstallDirs)

...

target_include_directories(libir-example PRIVATE
    "${CMAKE_INSTALL_INCLUDEDIR}/libirimager"
)

相关问题