2016年1月3日 星期日

OpenEmbedded - Writing a recipes/package inherit cmake


基本上inherit cmake跟inherit autotools是差不多的,其實cmake class裡面也是有inherit autotool,比較大的差異是,source file在cmake下是放在${PN}目錄下,即package name下,檔案結構如下:
brook@vista:~/oe-core$ tree meta/recipes-support/brook-cmake
meta/recipes-support/brook-cmake
|-- brook-cmake
|   `-- brook-cmake.patch
`-- brook-cmake_1.0.bb
1 directory, 2 files


brook-cmake.patch就是放置CMakeLists.txt、main.c跟LICENSE,其內容如下:

CMakeLists.txt

cmake_minimum_required (VERSION 2.6)
project(brook-cmake-demo)
add_executable(brook-cmake main.c)
install(TARGETS brook-cmake DESTINATION bin)


main.c

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("hello, cmake\n");
    return 0;
}


brook-cmake_1.0.bb

DESCRIPTION = "Brook CMake Project"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://LICENSE;md5=5ff2bd2dd80c7cc542a6b8de3ee4ff87"

SRC_URI = "file://brook-cmake.patch \
"

inherit cmake

EXTRA_OEMAKE = "-Wall"


下面這裡是多個版本的寫法

其實寫法都一樣,只是patch file的目錄要包含版本號,檔案結構如下:
brook@vista:~/oe-core/meta/recipes-support$ tree brook-cmake
brook-cmake
|-- brook-cmake-1.0
|   `-- brook-cmake.patch
|-- brook-cmake-2.0
|   `-- brook-cmake.patch
|-- brook-cmake_1.0.bb
`-- brook-cmake_2.0.bb


BB檔與patch的內容跟上面都是一樣的
brook@vista:~/oe-core$ cat meta/recipes-support/brook-cmake/brook-cmake_1.0.bb
DESCRIPTION = "Brook CMake Project"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://LICENSE;md5=7e4bf6f59b6da8e57ed5425a10a7310b"

SRC_URI = "file://brook-cmake.patch \
"

inherit cmake

BBCLASSEXTEND = "native"

EXTRA_OEMAKE = "-Wall"

brook@vista:~/oe-core$ cat meta/recipes-support/brook-cmake/brook-cmake_2.0.bb
DESCRIPTION = "Brook CMake Project"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://LICENSE;md5=7e4bf6f59b6da8e57ed5425a10a7310b"

SRC_URI = "file://brook-cmake.patch \
"

inherit cmake

BBCLASSEXTEND = "native"

EXTRA_OEMAKE = "-Wall"

brook@vista:~/oe-core$ cat meta/recipes-support/brook-cmake/brook-cmake-1.0/brook-cmake.patch
From 037c40faba39a11e54f282c3eab5e47a4cf1c7ca Mon Sep 17 00:00:00 2001
From: Brook <rene3210 at gmail.com>
Date: Tue, 27 Sep 2016 20:42:11 +0800
Subject: [PATCH] brook oe demo code

---
 CMakeLists.txt | 5 +++++
 LICENSE        | 1 +
 main.c         | 8 ++++++++
 3 files changed, 14 insertions(+)
 create mode 100644 CMakeLists.txt
 create mode 100644 LICENSE
 create mode 100644 main.c

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..ee4d6d9
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required (VERSION 2.6)
+project(brook-cmake-demo)
+add_executable(brook-cmake main.c)
+install(TARGETS brook-cmake DESTINATION bin)
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..0664320
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1 @@
+"GPLv2"
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..d089aad
--- /dev/null
+++ b/main.c
@@ -0,0 +1,8 @@
+#include 
+
+int main(int argc, char *argv[])
+{
+    printf("hello, cmake 1.0\n");
+    return 0;
+}
+
--
2.7.4

brook@vista:~/oe-core$ cat meta/recipes-support/brook-cmake/brook-cmake-2.0/brook-cmake.patch
From 037c40faba39a11e54f282c3eab5e47a4cf1c7ca Mon Sep 17 00:00:00 2001
From: Brook <rene3210 at gmail.com>
Date: Tue, 27 Sep 2016 20:42:11 +0800
Subject: [PATCH] brook oe demo code

---
 CMakeLists.txt | 5 +++++
 LICENSE        | 1 +
 main.c         | 8 ++++++++
 3 files changed, 14 insertions(+)
 create mode 100644 CMakeLists.txt
 create mode 100644 LICENSE
 create mode 100644 main.c

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..ee4d6d9
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required (VERSION 2.6)
+project(brook-cmake-demo)
+add_executable(brook-cmake main.c)
+install(TARGETS brook-cmake DESTINATION bin)
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..0664320
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1 @@
+"GPLv2"
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..d089aad
--- /dev/null
+++ b/main.c
@@ -0,0 +1,8 @@
+#include 
+
+int main(int argc, char *argv[])
+{
+    printf("hello, cmake 2.0\n");
+    return 0;
+}
+
--
2.7.4


如果沒有特別指定版本的話,會使用最新的,可以透過設定PREFERRED_VERSION_package_name設定特定版本,如
brook@vista:~/oe-core$ grep -H PREFERRED_VERSION build/conf/local.conf
build/conf/local.conf:PREFERRED_VERSION_brook-cmake = "1.0"
相關資訊可以參考Bitbake User Manual/2.3. Preferences and Providers

    參考資料:
  1. CMake 入門




1 則留言:

  1. SRC_URI variable: Source code and patches
    file: for patches and additional files
    Supported options:
    patch
      Used as "patch=1" to define this file as a patch file. Patch files will be copied to ${S}/patches and then applied to source from within the source directory, ${S}.
    pnum
      By default patches are applied with the "-p 1" parameter, which strips off the first directory of the pathname in the patches. This option is used to explicitly control the value passed to "-p". The most typical use is when the patches are relative to the source directory already and need to be applied using "-p 0", in which case the "pnum=0" option is supplied.

    回覆刪除

熱門文章