docs: using cmake with yocto recipe - example
This commit is contained in:
parent
726b151913
commit
eee10303f8
|
|
@ -3,5 +3,8 @@ functionality installed."
|
||||||
|
|
||||||
inherit coreos-image
|
inherit coreos-image
|
||||||
|
|
||||||
IMAGE_FEATURES += "ssh-server podman dev-tools cockpit networkmanager swupdate"
|
IMAGE_FEATURES += "ssh-server podman dev-tools cockpit networkmanager"
|
||||||
IMAGE_INSTALL:append = " packagegroup-core-full-cmdline swupdate-www"
|
|
||||||
|
IMAGE_INSTALL += "cmake-demo"
|
||||||
|
|
||||||
|
IMAGE_INSTALL:append = " packagegroup-core-full-cmdline"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
#Example how to make a recipe that uses CMake for building
|
||||||
|
#Please note that this is a recipe to build the package. For package to be added to an Image, another recipe needs to be changed.
|
||||||
|
#Example: This package is added to be part of coreos-image-full-cmdline image.
|
||||||
|
#A new line: IMAGE_INSTALL += "cmake-demo" is added to layers/meta-belden-coreos/recipes-core/images/coreos-image-full-cmdline.bb
|
||||||
|
|
||||||
|
DESCRIPTION = "Simple helloworld cmake application"
|
||||||
|
|
||||||
|
#Recipe must include a licence
|
||||||
|
LICENSE = "CLOSED"
|
||||||
|
|
||||||
|
#Revision of this recipe (optional)
|
||||||
|
PR = "r1"
|
||||||
|
|
||||||
|
SYSTEMD_AUTO_ENABLE = "enable"
|
||||||
|
|
||||||
|
#Systemd file
|
||||||
|
SYSTEMD_SERVICE_${PN} = "hello.service"
|
||||||
|
|
||||||
|
#Recipe needs to know where the needed files are
|
||||||
|
SRC_URI += "file://CMakeLists.txt\
|
||||||
|
file://lib/CMakeLists.txt \
|
||||||
|
file://src/CMakeLists.txt \
|
||||||
|
file://src/helloworld.c \
|
||||||
|
file://src/hello.service \
|
||||||
|
file://lib/lib-demo.c \
|
||||||
|
file://lib/lib-demo.h"
|
||||||
|
|
||||||
|
#List of files and directories that are placed in a package
|
||||||
|
FILES:${PN} += "${systemd_unitdir}/system/hello.service"
|
||||||
|
|
||||||
|
#Temporary work directory for each recipe where extracted source files are kept
|
||||||
|
S="${WORKDIR}"
|
||||||
|
|
||||||
|
#CMake will do most of the work, so it needs to be inherited
|
||||||
|
inherit cmake systemd
|
||||||
|
|
||||||
|
#Passing any needed configure options to CMake
|
||||||
|
EXTRA_OECMAKE = ""
|
||||||
|
|
||||||
|
#Systemd service is being installed using this function (this is an example). Other files are installed using CMake
|
||||||
|
do_install:append() {
|
||||||
|
install -d ${D}/${systemd_unitdir}/system
|
||||||
|
install -m 0644 ${WORKDIR}/src/hello.service ${D}/${systemd_unitdir}/system
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
#Top CMakeLists.txt file
|
||||||
|
|
||||||
|
#Firstly a minimum required version of CMake is specified
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
#Name the project, and give a version
|
||||||
|
project(cmake_demo VERSION 0.0.1)
|
||||||
|
|
||||||
|
#Setting build logs to verbose (usefull for debugging)
|
||||||
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||||
|
|
||||||
|
#Adding subdirectories that contain CMakeLists.txt
|
||||||
|
add_subdirectory(lib)
|
||||||
|
add_subdirectory(src)
|
||||||
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
#CMakeLists.txt file is gets some info from top CMakeLists.txt file (Minimum required version, Project name), so its not needed to redefine it here
|
||||||
|
|
||||||
|
|
||||||
|
# Declare the library target.
|
||||||
|
add_library(${PROJECT_NAME} SHARED lib-demo.c)
|
||||||
|
|
||||||
|
# Set the version property.
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
|
||||||
|
|
||||||
|
# Set the shared object version property to the project's major version.
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})
|
||||||
|
|
||||||
|
# Set the public header property to the one with the actual API.
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER lib-demo.h)
|
||||||
|
|
||||||
|
#Install library and dependency file
|
||||||
|
install (TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include)
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
/*
|
||||||
|
* Simple C library to be used for demonstration
|
||||||
|
* Bitbake recipe calls CMake to buld and install
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "lib-demo.h"
|
||||||
|
|
||||||
|
void demo_print(){
|
||||||
|
|
||||||
|
printf("Print from demo lib\n");
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
/*
|
||||||
|
* Library dependency file
|
||||||
|
*/
|
||||||
|
void demo_print();
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
#CMakeLists.txt file is gets some info from top CMakeLists.txt file (Minimum required version, Project name), so its not needed to redefine it here
|
||||||
|
|
||||||
|
#Create binary
|
||||||
|
add_executable(helloworld helloworld.c)
|
||||||
|
|
||||||
|
#Install binary
|
||||||
|
install(TARGETS helloworld RUNTIME DESTINATION bin)
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
#Systemd service file
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=GNU Hello World startup script for KOAN training course
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/bin/helloworld
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* Simple C code (binary is used for demonstration)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
printf("Hello, World!");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue