codec2: fix cross compilation

It uses cmake flags and environment variables in a way that interacts
poorly with stdenv's defaults. See code comments for details.
This commit is contained in:
Audrey Dutcher
2025-02-23 15:10:59 -07:00
parent 25fb2896ea
commit b290d10aef
+15 -1
View File
@@ -1,6 +1,7 @@
{
lib,
stdenv,
buildPackages,
fetchFromGitHub,
cmake,
freedvSupport ? false,
@@ -18,12 +19,23 @@ stdenv.mkDerivation rec {
hash = "sha256-69Mp4o3MgV98Fqfai4txv5jQw2WpoPuoWcwHsNAFPQM=";
};
nativeBuildInputs = [ cmake ];
nativeBuildInputs = [
cmake
buildPackages.stdenv.cc # needs to build a C program to run at build time
];
buildInputs = lib.optionals freedvSupport [
lpcnetfreedv
];
# we need to unset these variables from stdenv here and then set their equivalents in the cmake flags
# otherwise it will pass the same compiler to the native and cross phases and crash trying to execute
# host binaries (generate_codebook) on the build system.
preConfigure = ''
unset CC
unset CXX
'';
postInstall = ''
install -Dm0755 src/{c2enc,c2sim,freedv_rx,freedv_tx,cohpsk_*,fdmdv_*,fsk_*,ldpc_*,ofdm_*} -t $out/bin/
'';
@@ -37,6 +49,8 @@ stdenv.mkDerivation rec {
[
# RPATH of binary /nix/store/.../bin/freedv_rx contains a forbidden reference to /build/
"-DCMAKE_SKIP_BUILD_RPATH=ON"
"-DCMAKE_C_COMPILER=${stdenv.cc.targetPrefix}cc"
"-DCMAKE_CXX_COMPILER=${stdenv.cc.targetPrefix}c++"
]
++ lib.optionals freedvSupport [
"-DLPCNET=ON"