xref: /openbmc/openbmc/poky/meta/lib/oeqa/sdk/cases/cmake.py (revision 8460358c3d24c71d9d38fd126c745854a6301564)
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7import os
8import subprocess
9import tempfile
10import unittest
11from oeqa.sdk.case import OESDKTestCase
12
13from oeqa.utils.subprocesstweak import errors_have_output
14errors_have_output()
15
16class CMakeTest(OESDKTestCase):
17    """
18    Test case to build a project using cmake.
19    """
20
21    def setUp(self):
22        libc = self.td.get("TCLIBC")
23        if libc in [ 'newlib' ]:
24            raise unittest.SkipTest("CMakeTest class: SDK doesn't contain a supported C library")
25
26        if not (self.tc.hasHostPackage("nativesdk-cmake") or
27                self.tc.hasHostPackage("cmake-native")):
28            raise unittest.SkipTest("CMakeTest: needs cmake")
29
30    def test_assimp(self):
31        with tempfile.TemporaryDirectory(prefix="assimp", dir=self.tc.sdk_dir) as testdir:
32            tarball = self.fetch(testdir, self.td["DL_DIR"], "https://github.com/assimp/assimp/archive/v5.4.1.tar.gz")
33
34            dirs = {}
35            dirs["source"] = os.path.join(testdir, "assimp-5.4.1")
36            dirs["build"] = os.path.join(testdir, "build")
37            dirs["install"] = os.path.join(testdir, "install")
38
39            subprocess.check_output(["tar", "xf", tarball, "-C", testdir], stderr=subprocess.STDOUT)
40            self.assertTrue(os.path.isdir(dirs["source"]))
41            # Apply the zlib patch https://github.com/madler/zlib/commit/a566e156b3fa07b566ddbf6801b517a9dba04fa3
42            # this sed wont be needed once assimp moves its zlib copy to v1.3.1+
43            self._run("sed -i '/#  ifdef _FILE_OFFSET_BITS/I,+2 d' {source}/contrib/zlib/gzguts.h".format(**dirs))
44            os.makedirs(dirs["build"])
45
46            self._run("cd {build} && cmake -DASSIMP_WARNINGS_AS_ERRORS=OFF -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DASSIMP_BUILD_ZLIB=ON {source}".format(**dirs))
47            self._run("cmake --build {build} -- -j".format(**dirs))
48            self._run("cmake --build {build} --target install -- DESTDIR={install}".format(**dirs))
49            self.check_elf(os.path.join(dirs["install"], "usr", "local", "lib", "libassimp.so.5.4.1"))
50