Skip to contentSkip to conversation

cmake: fix linking in multilib SDKs

PATCH New Ross Burton 1 participant 4 messages Aug 3, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 cmake: fix linking in multilib SDKs

CMake, in it's infinite wisdom, when searching for libraries (using find_library) will look inside the libraries PREFIX/lib, PREFIX/lib32, and PREFIX/lib64. In a multilib SDK more than one of these will exist (potentially all three) and obviously for a given build configuration only one of those is valid. This search path is hard-coded deep inside CMake but by setting CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX we can bypass it and set an explicit lib<SUFFIX> to use.

Do this by writing ${baselib} into the environment file, and then stripping "lib" from this to obtain the suffix in the cmake-specific environment script, which is then read in the CMake toolchain.

---
 meta/classes/toolchain-scripts.bbclass                    | 1 +
 meta/recipes-devtools/cmake/cmake/OEToolchainConfig.cmake | 2 ++
 meta/recipes-devtools/cmake/cmake/environment.d-cmake.sh  | 1 +
 3 files changed, 4 insertions(+)
meta/classes/toolchain-scripts.bbclass +1 -0
index 0ff5301530b..63b07c802f4 100644
@@ -51,6 +51,7 @@ toolchain_create_sdk_env_script () {
 	echo "export OECORE_NATIVE_SYSROOT=\"$sdkpathnative\"" >> $script
 	echo 'export OECORE_TARGET_SYSROOT="$SDKTARGETSYSROOT"' >> $script
 	echo "export OECORE_ACLOCAL_OPTS=\"-I $sdkpathnative/usr/share/aclocal\"" >> $script
+	echo 'export OECORE_BASELIB="${baselib}"' >> $script
 	echo 'unset command_not_found_handle' >> $script
 
 	toolchain_shared_env_script
meta/recipes-devtools/cmake/cmake/OEToolchainConfig.cmake +2 -0
index dc8477ea345..d52c29e5a1c 100644
@@ -10,6 +10,8 @@ set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
 set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
 
+set(CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX "$ENV{OE_CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX}")
+
 # Set CMAKE_SYSTEM_PROCESSOR from the sysroot name (assuming processor-distro-os).
 if ($ENV{SDKTARGETSYSROOT} MATCHES "/sysroots/([a-zA-Z0-9_-]+)-.+-.+")
   set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_MATCH_1})
meta/recipes-devtools/cmake/cmake/environment.d-cmake.sh +1 -0
index 64b6cf3c6a3..7bdb19fb6ce 100644
@@ -1 +1,2 @@
 export OE_CMAKE_TOOLCHAIN_FILE="$OECORE_NATIVE_SYSROOT/usr/share/cmake/OEToolchainConfig.cmake"
+export OE_CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX="`echo $OECORE_BASELIB | sed -e s/lib//`"
Signature · 1 line
2.11.0
#1 lore raw

PATCH 2/4 toolchain-scripts: put TARGET_ARCH and TARGET_OS into environment

It's useful for the SDK to know exactly what TARGET_ARCH and TARGET_OS are, specifically for SDK QA.

---
 meta/classes/toolchain-scripts.bbclass | 3 +++
 1 file changed, 3 insertions(+)
meta/classes/toolchain-scripts.bbclass +3 -0
index 63b07c802f4..6d1ba69473a 100644
@@ -52,6 +52,9 @@ toolchain_create_sdk_env_script () {
 	echo 'export OECORE_TARGET_SYSROOT="$SDKTARGETSYSROOT"' >> $script
 	echo "export OECORE_ACLOCAL_OPTS=\"-I $sdkpathnative/usr/share/aclocal\"" >> $script
 	echo 'export OECORE_BASELIB="${baselib}"' >> $script
+	echo 'export OECORE_TARGET_ARCH="${TARGET_ARCH}"' >>$script
+	echo 'export OECORE_TARGET_OS="${TARGET_OS}"' >>$script
+
 	echo 'unset command_not_found_handle' >> $script
 
 	toolchain_shared_env_script
Signature · 1 line
2.11.0
#2 lore raw

PATCH 3/4 oeqa/sdk: add test that CMake works

In reply to Ross Burton

Add a new SDK testcase that builds assimp, a project that uses cmake.

Using TARGET_ARCH and TARGET_OS which is now exported into the environment, check that the generated binaries match the ELF headers we expect.

---
 meta/lib/oeqa/sdk/cases/assimp.py | 68 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 meta/lib/oeqa/sdk/cases/assimp.py
meta/lib/oeqa/sdk/cases/assimp.py new file +68 -0
new file mode 100644
index 00000000000..7251bdf34e7
@@ -0,0 +1,68 @@
+import os, subprocess, unittest
+import bb
+from oeqa.sdk.case import OESDKTestCase
+from oeqa.sdk.utils.sdkbuildproject import SDKBuildProject
+
+from oeqa.utils.subprocesstweak import errors_have_output
+errors_have_output()
+
+class BuildAssimp(OESDKTestCase):
+    """
+    Test case to build a project using cmake.
+    """
+
+    td_vars = ['DATETIME', 'TARGET_OS', 'TARGET_ARCH']
+
+    @classmethod
+    def setUpClass(self):
+        if not (self.tc.hasHostPackage("nativesdk-cmake") or
+                self.tc.hasHostPackage("cmake-native")):
+            raise unittest.SkipTest("Needs cmake")
+
+    def fetch(self, workdir, dl_dir, url, archive=None):
+        if not archive:
+            from urllib.parse import urlparse
+            archive = os.path.basename(urlparse(url).path)
+
+        if dl_dir:
+            tarball = os.path.join(dl_dir, archive)
+            if os.path.exists(tarball):
+                return tarball
+
+        tarball = os.path.join(workdir, archive)
+        subprocess.check_output(["wget", "-O", tarball, url])
+        return tarball
+
+    def test_assimp(self):
+        import tempfile
+        import oe.qa, oe.elf
+
+        with tempfile.TemporaryDirectory(prefix="assimp", dir=self.tc.sdk_dir) as testdir:
+            dl_dir = self.td.get('DL_DIR', None)
+            tarball = self.fetch(testdir, dl_dir, "https://github.com/assimp/assimp/archive/v4.1.0.tar.gz")
+            subprocess.check_output(["tar", "xf", tarball, "-C", testdir])
+
+            sourcedir = os.path.join(testdir, "assimp-4.1.0") 
+            builddir = os.path.join(testdir, "build")
+            installdir = os.path.join(testdir, "install")
+            bb.utils.mkdirhier(builddir)
+
+            self._run("cd %s && cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON %s " % (builddir, sourcedir))
+            self._run("cmake --build %s -- -j" % builddir)
+            self._run("cmake --build %s --target install -- DESTDIR=%s" % (builddir, installdir))
+
+            elf = oe.qa.ELFFile(os.path.join(installdir, "usr", "local", "lib", "libassimp.so.4.1.0"))
+            elf.open()
+
+            output = self._run("echo $OECORE_TARGET_OS:$OECORE_TARGET_ARCH")
+            target_os, target_arch = output.strip().split(":")
+            machine_data = oe.elf.machine_dict(None)[target_os][target_arch]
+            (machine, osabi, abiversion, endian, bits) = machine_data
+
+            self.assertEqual(machine, elf.machine())
+            self.assertEqual(bits, elf.abiSize())
+            self.assertEqual(endian, elf.isLittleEndian())
+
+    @classmethod
+    def tearDownClass(self):
+        self.project.clean()
Signature · 1 line
2.11.0
#3 lore raw

PATCH 4/4 desktop-file-utils: allow target/nativesdk build, not just native

In reply to Ross Burton

Also fix the license, as this is GPLv2+ not just v2.

---
 ...le-utils-native_0.23.bb => desktop-file-utils_0.23.bb} | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
 rename meta/recipes-devtools/desktop-file-utils/{desktop-file-utils-native_0.23.bb => desktop-file-utils_0.23.bb} (58%)
meta/recipes-devtools/desktop-file-utils/desktop-file-utils_0.23.bb renamed from meta/recipes-devtools/desktop-file-utils/desktop-file-utils-native_0.23.bb +8 -7
similarity index 58%
rename from meta/recipes-devtools/desktop-file-utils/desktop-file-utils-native_0.23.bb
rename to meta/recipes-devtools/desktop-file-utils/desktop-file-utils_0.23.bb
index 54daabef56c..6446f47189d 100644
@@ -1,18 +1,19 @@
 SECTION = "console/utils"
 SUMMARY = "Command line utilities for working with *.desktop files"
 HOMEPAGE = "http://www.freedesktop.org/wiki/Software/desktop-file-utils"
-LICENSE = "GPLv2"
+LICENSE = "GPLv2+"
 
-LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263"
-DEPENDS = "glib-2.0-native"
-
-SRC_URI = "http://freedesktop.org/software/desktop-file-utils/releases/desktop-file-utils-${PV}.tar.xz"
+LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
+                    file://src/validator.c;beginline=4;endline=27;md5=281e1114ee6c486a1a0a4295986b9416"
 
+SRC_URI = "http://freedesktop.org/software/${BPN}/releases/${BP}.tar.xz"
 SRC_URI[md5sum] = "599133d51cc9a41bfec186414906b6f1"
 SRC_URI[sha256sum] = "6c094031bdec46c9f621708f919084e1cb5294e2c5b1e4c883b3e70cb8903385"
 
-inherit autotools native
+DEPENDS = "glib-2.0"
 
-S = "${WORKDIR}/desktop-file-utils-${PV}"
+inherit autotools pkgconfig
 
 EXTRA_OECONF += "ac_cv_prog_EMACS=no"
+
+BBCLASSEXTEND = "native nativesdk"
Signature · 1 line
2.11.0