diff options
author | Gyorgy Sarvari <skandigraun@gmail.com> | 2025-02-25 14:33:35 +0100 |
---|---|---|
committer | Khem Raj <raj.khem@gmail.com> | 2025-02-25 09:46:52 -0800 |
commit | e3c5b2dd0c5758da6396514c6c6ec413056b6fe0 (patch) | |
tree | e097b47aad3235d421e13fc69632ec6232a0d029 | |
parent | 996dfcbdd7bfd2933e053780f1761c06b4043e7f (diff) | |
download | meta-openembedded-e3c5b2dd0c5758da6396514c6c6ec413056b6fe0.tar.gz |
capnproto: only export binaries for native build
The base problem this is trying to solve: capnproto has two main
components: libraries that can be linked against, and binary files
that can generate c++ code from capnproto definitions. When cross-compiling
one needs to use the cross-compiled libraries, but with the native
definition-compilers.
When linking against capnproto from another recipe, cross-compilation
fails, because the cmake files generated by capnproto verify the
existence of binary files in $bindir. When using a cross-compiled
version of capnproto, these binary files do not exist in RECIPE_SYSROOT, so
the compilation fails.
The previous patch: the previous solution patched the CMakeLists.txt
file in a way that it didn't export nor install the generated binary files.
Accidentally this also happened with native build (and happened knowingly with
target builds).
The new patch: instead of not installing and not exporting the binaries,
just install them without exporting, when creating a target build.
During compilation check is CMAKE_CROSSCOMPILING is set (coming from
cmake.bbclass) - if it is set, only install the binaries, without
exporting. When it is not set, resort to the original behavior.
Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
3 files changed, 54 insertions, 44 deletions
diff --git a/meta-oe/recipes-devtools/capnproto/capnproto/0001-Don-t-check-usr-bin-content-from-cmake.patch b/meta-oe/recipes-devtools/capnproto/capnproto/0001-Don-t-check-usr-bin-content-from-cmake.patch deleted file mode 100644 index 6447fadcf9..0000000000 --- a/meta-oe/recipes-devtools/capnproto/capnproto/0001-Don-t-check-usr-bin-content-from-cmake.patch +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | From 43573472a62ff68ba6b1180d6551ef536471a99f Mon Sep 17 00:00:00 2001 | ||
2 | From: Gyorgy Sarvari <skandigraun@gmail.com> | ||
3 | Date: Mon, 3 Feb 2025 11:52:01 +0100 | ||
4 | Subject: [PATCH] Don't install files in bindir | ||
5 | |||
6 | This patch prevents the generated binary executables from being | ||
7 | installed into the /usr/bin folder. | ||
8 | |||
9 | By default, cmake installs these binaries into the /usr/bin folder, | ||
10 | (e.g. binaries used to generate C++ source from the capnproto definition | ||
11 | files) however with Yocto, when using the cross-compiled version of this | ||
12 | application, the /usr/bin folder is not populated in the sysroot. | ||
13 | The generated cmake file however tries to verify that these binaries | ||
14 | exist, and since it cannot find them, it fails the build. | ||
15 | |||
16 | But even in case these files would exist, they are not usable on the build | ||
17 | machine, as these are cross-compiled for the target machine. When another | ||
18 | recipe it built against the capnproto cmake package, the application can | ||
19 | link against the cross-compiled libraries as expected, but for code | ||
20 | generation the capnproto-native package's binaries need to be used. | ||
21 | |||
22 | This patch is only applicable on the cross-compiled version of capnproto. | ||
23 | |||
24 | Upstream-Status: Inappropriate [oe specific: see above message] | ||
25 | |||
26 | Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com> | ||
27 | --- | ||
28 | c++/src/capnp/CMakeLists.txt | 2 -- | ||
29 | 1 file changed, 2 deletions(-) | ||
30 | |||
31 | diff --git a/c++/src/capnp/CMakeLists.txt b/c++/src/capnp/CMakeLists.txt | ||
32 | index 9980fde6..101a7091 100644 | ||
33 | --- a/src/capnp/CMakeLists.txt | ||
34 | +++ b/src/capnp/CMakeLists.txt | ||
35 | @@ -210,8 +210,6 @@ if(NOT CAPNP_LITE) | ||
36 | target_link_libraries(capnpc_capnp capnp kj) | ||
37 | set_target_properties(capnpc_capnp PROPERTIES OUTPUT_NAME capnpc-capnp) | ||
38 | |||
39 | - install(TARGETS capnp_tool capnpc_cpp capnpc_capnp ${INSTALL_TARGETS_DEFAULT_ARGS}) | ||
40 | - | ||
41 | if(WIN32) | ||
42 | # On Windows platforms symlinks are not guaranteed to support. Also different version of CMake handle create_symlink in a different way. | ||
43 | # The most portable way in this case just copy the file. | ||
diff --git a/meta-oe/recipes-devtools/capnproto/capnproto/0001-Export-binaries-only-for-native-build.patch b/meta-oe/recipes-devtools/capnproto/capnproto/0001-Export-binaries-only-for-native-build.patch new file mode 100644 index 0000000000..7677d96b23 --- /dev/null +++ b/meta-oe/recipes-devtools/capnproto/capnproto/0001-Export-binaries-only-for-native-build.patch | |||
@@ -0,0 +1,53 @@ | |||
1 | From e654a7015f5e8f20bf7681681cc2b80082303007 Mon Sep 17 00:00:00 2001 | ||
2 | From: Gyorgy Sarvari <skandigraun@gmail.com> | ||
3 | Date: Tue, 25 Feb 2025 13:43:42 +0100 | ||
4 | Subject: [PATCH] Export binaries only for native build | ||
5 | |||
6 | By default, the cmake configuratione exports all generated files, | ||
7 | so when using the generated cmake file with a find_package command, | ||
8 | it verifies that these files actually exist. | ||
9 | |||
10 | When using the cross-compiled version of capnproto, the generated | ||
11 | binaries are not available in RECIPE_SYSROOT (since they can be | ||
12 | used as RDEPENDS only, but not usable as DEPENDS), and due to | ||
13 | this the compilation fails. | ||
14 | |||
15 | To avoid this, check during the compilation of capnproto if it is | ||
16 | being cross-compiled, or not. If is it cross-compiled, then only | ||
17 | install the generated binary files in their final location, but | ||
18 | don't export them. When not cross-compiling, do the same, but also | ||
19 | export the files (which is the default behavior). | ||
20 | |||
21 | Upstream-Status: Inappropriate [oe specific: see above message] | ||
22 | |||
23 | Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com> | ||
24 | --- | ||
25 | c++/src/capnp/CMakeLists.txt | 15 ++++++++++++++- | ||
26 | 1 file changed, 14 insertions(+), 1 deletion(-) | ||
27 | |||
28 | diff --git a/c++/src/capnp/CMakeLists.txt b/c++/src/capnp/CMakeLists.txt | ||
29 | index 9980fde6..8732db93 100644 | ||
30 | --- a/src/capnp/CMakeLists.txt | ||
31 | +++ b/src/capnp/CMakeLists.txt | ||
32 | @@ -210,7 +210,20 @@ if(NOT CAPNP_LITE) | ||
33 | target_link_libraries(capnpc_capnp capnp kj) | ||
34 | set_target_properties(capnpc_capnp PROPERTIES OUTPUT_NAME capnpc-capnp) | ||
35 | |||
36 | - install(TARGETS capnp_tool capnpc_cpp capnpc_capnp ${INSTALL_TARGETS_DEFAULT_ARGS}) | ||
37 | + if(NOT CMAKE_CROSSCOMPILING) | ||
38 | + install(TARGETS capnp_tool capnpc_cpp capnpc_capnp ${INSTALL_TARGETS_DEFAULT_ARGS}) | ||
39 | + else() | ||
40 | + # INSTALL_TARGETS_CROSS_COMPILED_BINARY_ARGS is identical to INSTALL_TARGETS_DEFAULT_ARGS, | ||
41 | + # except that the installed files are not exported, so when the generated cmake file | ||
42 | + # is used by a find_package command, it won't try to find these files. | ||
43 | + set(INSTALL_TARGETS_CROSS_COMPILED_BINARY_ARGS | ||
44 | + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
45 | + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
46 | + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" | ||
47 | + ) | ||
48 | + | ||
49 | + install(TARGETS capnp_tool capnpc_cpp capnpc_capnp ${INSTALL_TARGETS_CROSS_COMPILED_BINARY_ARGS}) | ||
50 | + endif() | ||
51 | |||
52 | if(WIN32) | ||
53 | # On Windows platforms symlinks are not guaranteed to support. Also different version of CMake handle create_symlink in a different way. | ||
diff --git a/meta-oe/recipes-devtools/capnproto/capnproto_1.0.2.bb b/meta-oe/recipes-devtools/capnproto/capnproto_1.0.2.bb index 6136ff20fb..77bde79217 100644 --- a/meta-oe/recipes-devtools/capnproto/capnproto_1.0.2.bb +++ b/meta-oe/recipes-devtools/capnproto/capnproto_1.0.2.bb | |||
@@ -6,7 +6,7 @@ LICENSE = "MIT" | |||
6 | LIC_FILES_CHKSUM = "file://../LICENSE;md5=a05663ae6cca874123bf667a60dca8c9" | 6 | LIC_FILES_CHKSUM = "file://../LICENSE;md5=a05663ae6cca874123bf667a60dca8c9" |
7 | 7 | ||
8 | SRC_URI = "git://github.com/sandstorm-io/capnproto.git;branch=release-${PV};protocol=https \ | 8 | SRC_URI = "git://github.com/sandstorm-io/capnproto.git;branch=release-${PV};protocol=https \ |
9 | file://0001-Don-t-check-usr-bin-content-from-cmake.patch" | 9 | file://0001-Export-binaries-only-for-native-build.patch" |
10 | SRCREV = "1a0e12c0a3ba1f0dbbad45ddfef555166e0a14fc" | 10 | SRCREV = "1a0e12c0a3ba1f0dbbad45ddfef555166e0a14fc" |
11 | 11 | ||
12 | S = "${WORKDIR}/git/c++" | 12 | S = "${WORKDIR}/git/c++" |