Warm tip: This article is reproduced from serverfault.com, please click

c-Bitbake配方将子文件夹中的本地源复制

(c - Bitbake recipe copy local sources in sub folders)

发布于 2020-11-30 17:54:28

我正在学习yocto和bitbake,我对一些东西感到困惑。

当我开发C项目时,我的树文件如下所示:

myproject
├── commons
│   ├── commons.c
│   ├── commons.h
│   └── path.h
├── config
│   ├── config.c
│   └── config.h
├── errors
│   ├── error.c
│   └── error.h
├── files
│   ├── COPYING
│   ├── ...
├── jimini
│   ├── jimini.c        # source including the main()
│   └── jimini.h
├── Doxyfile
├── CMakeLists.txt
└── jimini-collector_0.3.bb

我的CMakeLists.txt看起来像:

cmake_minimum_required(VERSION 3.0.0)

if(CMAKE_VERSION VERSION_LESS "3.7.0")
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()

project(myproject VERSION 0.3.0)

find_library(LIBCONFIG config)
message(STATUS "libconfig path :  ${LIBCONFIG}")

find_library(CURL curl)
message("CURL path : ${CURL}")

find_library(JSON json-c)
message("JSON path : ${JSON}")

find_library(RT rt)
message("RT path : ${RT}")

include(CTest)
enable_testing()

aux_source_directory(../commons SOURCES)
aux_source_directory(../config SOURCES)
aux_source_directory(../errors SOURCES)
aux_source_directory(../jimini SOURCES)

message(STATUS "project folder : " ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS "My sources: " ${SOURCES})

add_executable(${PROJECT_NAME} ${SOURCES})

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

set(CMAKE_BUILD_TYPE Debug)
#set(CMAKE_BUILD_TYPE RelWithDebInfo)

target_link_libraries(${PROJECT_NAME} config)
target_link_libraries(${PROJECT_NAME} m)
target_link_libraries(${PROJECT_NAME} pthread)
target_link_libraries(${PROJECT_NAME} curl)
target_link_libraries(${PROJECT_NAME} json-c)
target_link_libraries(${PROJECT_NAME} rt)

# install the executable in /usr/bin
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)

我的食谱看起来像:

DESCRIPTION="This is my recipe to my super package"
MAINTAINER="Me <me@me.com>"

# Define license file and file checksum verification
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=39bba7d2cf0ba1036f2a6e2be52fe3f0"

DEPENDS += "libconfig"
DEPENDS += "json-c"

FILESEXTRAPATHS_prepend := "${THISDIR}"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
FILESEXTRAPATHS_prepend := "${THISDIR}/commons:"
FILESEXTRAPATHS_prepend := "${THISDIR}/config:"
FILESEXTRAPATHS_prepend := "${THISDIR}/errors:"
FILESEXTRAPATHS_prepend := "${THISDIR}/jimini:"

# include license and cmake config files
SRC_URI+="file://COPYING file://CMakeLists.txt"

# include sources files
SRC_URI+= " file://jimini.c file://commons.c file://config.c file://error.c"
SRC_URI+= " file://jimini.h file://commons.h file://path.h file://config.h file://error.h"

# where to copy sources and headers files
S="${WORKDIR}"

# define dependencies to build and package
inherit pkgconfig cmake 

我不明白如何设置配方以将本地源复制到子文件夹中。Bitbake将每个源复制到同一文件夹中,并且代码无法编译。

我尝试设置不同的,S="${WORKDIR}"但没有结果。

你能给我一个解释吗?

谢谢你。

编辑:我已经更正了我的文件,现在可以正常工作了。

我的CMakeLists.txt现在看起来像:

cmake_minimum_required(VERSION 3.0.0)

if(CMAKE_VERSION VERSION_LESS "3.7.0")
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()

project(myproject VERSION 0.3.0)

find_library(LIBCONFIG config)
message(STATUS "libconfig path :  ${LIBCONFIG}")

find_library(CURL curl)
message("CURL path : ${CURL}")

find_library(JSON json-c)
message("JSON path : ${JSON}")

find_library(RT rt)
message("RT path : ${RT}")

include(CTest)
enable_testing()

aux_source_directory(commons SOURCES)    # removed the ../
aux_source_directory(config SOURCES)     # removed the ../
aux_source_directory(errors SOURCES)     # removed the ../
aux_source_directory(jimini SOURCES)     # removed the ../

message(STATUS "project folder : " ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS "My sources: " ${SOURCES})

add_executable(${PROJECT_NAME} ${SOURCES})

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

set(CMAKE_BUILD_TYPE Debug)
#set(CMAKE_BUILD_TYPE RelWithDebInfo)

target_link_libraries(${PROJECT_NAME} config)
target_link_libraries(${PROJECT_NAME} m)
target_link_libraries(${PROJECT_NAME} pthread)
target_link_libraries(${PROJECT_NAME} curl)
target_link_libraries(${PROJECT_NAME} json-c)
target_link_libraries(${PROJECT_NAME} rt)

# install the executable in /usr/bin
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)

我的食谱,现在看起来像:

DESCRIPTION="This is my recipe to my super package"
MAINTAINER="Me <me@me.com>"

# Define license file and file checksum verification
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=39bba7d2cf0ba1036f2a6e2be52fe3f0"

DEPENDS += "libconfig"
DEPENDS += "json-c"

SCR_URI+= "file://files/"
SCR_URI+= "file://commons/"
SCR_URI+= "file://config/"
SCR_URI+= "file://errors/"
SCR_URI+= "file://jimini/"

# include license and cmake config files
SRC_URI+="file://COPYING file://CMakeLists.txt"

# include sources files
SRC_URI+= " file://*.c"
SRC_URI+= "file://*.h"

# where to copy sources and headers files
S="${WORKDIR}"

# define dependencies to build and package
inherit pkgconfig cmake 

我还按照答案中的建议修改了我的树文件。

Questioner
gilou
Viewed
11
qschulz 2020-12-01 02:13:11

FILESEXTRAPATHS仅用于添加路径以查找在中声明的文件SRC_URI你应该执行以下操作:

SRC_URI += "file://files/"
SRC_URI += "file://commons/"
SRC_URI += "file://config/"
SRC_URI += "file://errors/"
SRC_URI += "file://jimini/"

# include license and cmake config files
SRC_URI+="file://COPYING file://CMakeLists.txt"

另外,你的树布局应如下所示:

myproject
├── jimini-collector-0.3 # or files, or jimini-collector
│   ├──commons
|   │   ├── commons.c
|   │   ├── commons.h
|   │   └── path.h
|   ├── config
|   │   ├── config.c
|   │   └── config.h
|   ├── errors
|   │   ├── error.c
|   │   └── error.h
|   ├── files
|   │   ├── COPYING
|   │   ├── ...
|   ├── jimini
|   │   ├── jimini.c        # source including the main()
|   │   └── jimini.h
|   ├── Doxyfile
|   ├── CMakeLists.txt
└── jimini-collector_0.3.bb