Pull request #33: docs: using cmake with yocto recipe - example

Merge in ICO/coreos from doc_demo_cmake_yocto to master

* commit '04547f38760b95a1fed7afef9449c4925e657fcb':
  docs: removing from cmake-demo from image recipe
  docs: moving cmake-demo to demo layer
  docs: changing cmake version in CMakeLists.txt
  docs: editing comments and removing config setting
  docs: using cmake with yocto recipe - example
  docs: removing from cmake-demo from image recipe
  docs: moving cmake-demo to demo layer
  docs: changing cmake version in CMakeLists.txt
  docs: editing comments and removing config setting
  docs: using cmake with yocto recipe - example
This commit is contained in:
Darko Trogrlic 2023-01-30 13:34:07 +01:00 committed by Samuel Dolt
commit 259dd34e7c
9 changed files with 124 additions and 2 deletions

View File

@ -0,0 +1,44 @@
# 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 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
}

View File

@ -0,0 +1,15 @@
# Top CMakeLists.txt file
# Firstly a minimum required version of CMake is specified
cmake_minimum_required(VERSION 3.22)
# 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)

View File

@ -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)

View File

@ -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");
}

View File

@ -0,0 +1,4 @@
/*
* Library dependency file
*/
void demo_print();

View File

@ -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)

View File

@ -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

View File

@ -0,0 +1,13 @@
/*
* Simple C code (binary is used for demonstration)
*/
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}

View File

@ -3,5 +3,5 @@ functionality installed."
inherit coreos-image
IMAGE_FEATURES += "ssh-server podman dev-tools cockpit networkmanager swupdate"
IMAGE_INSTALL:append = " packagegroup-core-full-cmdline swupdate-www"
IMAGE_FEATURES += "ssh-server podman dev-tools cockpit networkmanager"
IMAGE_INSTALL:append = " packagegroup-core-full-cmdline"