背景
我正在尝试在 Yocto build 中构建自定义软件。软件由 CMake 构建。
以下是我的食谱 -
customsoftware.bb
:
SRCBRANCH = "master"
SRCREV = "master"
MY_SRC = "OMITTED"
SRC_URI = "${MY_SRC};branch=${SRCBRANCH}"
# libraries dependencies
DEPENDS += "boost"
S = "${WORKDIR}/git"
B = "${WORKDIR}/build"
PARALLEL_MAKE ?= "-j 1"
inherit cmake
# My CMake Options
EXTRA_OECMAKE+=" -DSOME_OPTION=ON"
# I want unix makefiles instead on ninja build
OECMAKE_GENERATOR="Unix Makefiles"
以下是我的 cmake 项目的淡化版本 -
CMakeLists.txt
请注意:为了简洁起见,我省略了不相关的部分
cmake_minimum_required(VERSION 3.0.0)
#---------------------------------------------------------------------------------------
# set default build to release
#---------------------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif()
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/dist/)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/bin)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "
${BoldRed}Error:${ColourReset} In-source builds are not allowed. You should create separate directory for build files.
${Magenta}CMAKE_BINARY_DIR${ColourReset}(${CMAKE_SOURCE_DIR}) must be different from ${Magenta}CMAKE_SOURCE_DIR${ColourReset}(${CMAKE_BINARY_DIR})
")
endif ()
project(myapp)
find_package(Boost REQUIRED COMPONENTS thread)
add_executable(${PROJECT_NAME}
${HEADERS}
${SOURCES}
)
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
#Copy entire contents of dist/ to /opt/myapp
install(DIRECTORY ${CMAKE_BINARY_DIR}/dist/
DESTINATION /opt/myapp
)
我已将我的食谱附加到图像中。
问题
当我运行时
du -h tmp/work/.../<customsoftware>/build/dist/bin
二进制大小是80MB。另外,部署到目标系统后二进制大小为 80MB。
更新
正如评论中所建议的,
tmp/work/.../<customsoftware>/image
处的二进制文件不会被删除。但是,位于 tmp/work/.../<customsoftware>/packages-split
的二进制文件被删除。
如果我在应用程序源中运行
make
- 不是通过配方和外部 yocto - 二进制大小为 1.7MB
问题
如果我没记错的话,OE 构建将从生成的二进制文件中删除调试符号。
为什么我的二进制文件仍然使用调试符号进行部署?我错过了什么?
如何确保仅部署剥离 - 发布类型 - 二进制文件?
显式指定包类型并继承 pkgconfig 解决了我的问题。更新食谱:
SRCBRANCH = "master"
SRCREV = "master"
MY_SRC = "OMITTED"
SRC_URI = "${MY_SRC};branch=${SRCBRANCH}"
DEPENDS += "boost"
S = "${WORKDIR}/git"
PARALLEL_MAKE ?= "-j 1"
inherit pkgconfig cmake
EXTRA_OECMAKE+=" -DSOME_OPTION"
OECMAKE_GENERATOR="Unix Makefiles"
# Specify package types
PACKAGES = "${PN}-dbg ${PN}"
FILES_${PN}-dbg += "\
<INSTALL_PATH>/.debug \
"
FILES_${PN} += "\
<INSTALL_PATH>/* \
"
您可以尝试看看这个简单的Hello World是否在您的环境中被删除了?
食谱:
DESCRIPTION = "Simple helloworld cmake"
LICENSE = "MIT"
SECTION = "examples"
LIC_FILES_CHKSUM =
"file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://CMakeLists.txt \
file://helloworld.c"
S = "${WORKDIR}"
inherit cmake
EXTRA_OECMAKE = ""
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.10)
project(helloworld)
add_executable(helloworld helloworld.c)
install(TARGETS helloworld RUNTIME DESTINATION bin)
helloworld.c:
#include <stdio.h>
int main() {
printf("Hello World Makefile from CMake!\n");
return(0);
}
如果你不介意调试版本 你可以做
OECMAKE_C_FLAGS_RELEASE += "-s"
OECMAKE_CXX_FLAGS_RELEASE += "-s"
它会删除你的二进制文件
您可能想禁用
INHIBIT_PACKAGE_STRIP
,请参阅 文档。
If set to “1”, causes the build to not strip binaries in resulting packages and prevents the -dbg package from containing the source files. By default, the OpenEmbedded build system strips binaries and puts the debugging symbols into ${PN}-dbg. Consequently, you should not set INHIBIT_PACKAGE_STRIP when you plan to debug in general.
INHIBIT_PACKAGE_STRIP = "0"