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

Bitbake recipe copy local sources in sub folders

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

I'm leanrning yocto and bitbake and I'm confused with fews things.

When I'm developing a C project my tree files look like :

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

My CMakeLists.txt look like :

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)

My recipe look like :

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 

I'm not understanding how can I set the recipe to copy the local sources in sub folders. Bitbake copy each sources in the same folder and the code can't be compiled.

I've try to set differently the S="${WORKDIR}" but without result.

Can you give me an explanation ?

Thank you.

EDIT : I've corrected my files and now it's working.

My CMakeLists.txt, now look like :

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)

My recipe, now look like :

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 

I've also modified my tree files as suggested in the answer.

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

FILESEXTRAPATHS is only to add paths where to look for files declared in SRC_URI. You should just do the following:

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"

Also, your tree layout should be the following:

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