Skip to content

Commit

Permalink
Add CMake and code logic to allow compilation without LPCNet.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Apr 13, 2024
1 parent fc6c4c8 commit d8ee413
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 35 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ if(CODEC2_BUILD_DIR)
CONFIGS lpcnetfreedv.cmake
)
else()
message(FATAL_ERROR "Must use LPCNet from build directory if using codec2 from build directory.")
set(LPCNET_DISABLED YES)
add_definitions(-DLPCNET_DISABLED)
endif()
elseif(USE_INTERNAL_CODEC2)
message(STATUS "Will attempt internal build of codec2 and lpcnetfreedv.")
Expand Down
47 changes: 33 additions & 14 deletions build_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
set -x -e

UT_ENABLE=${UT_ENABLE:-0}
LPCNET_DISABLE=${LPCNET_DISABLE:-0}

# Allow building of either PulseAudio or PortAudio variants
FREEDV_VARIANT=${1:-pulseaudio}
Expand All @@ -26,27 +27,45 @@ LPCNET_BRANCH=v0.5

# OK, build and test LPCNet
cd $FREEDVGUIDIR
if [ ! -d LPCNet ]; then
git clone https://github.com/drowe67/LPCNet.git
if [ $LPCNET_DISABLE == 0 ]; then
if [ ! -d LPCNet ]; then
git clone https://github.com/drowe67/LPCNet.git
fi
cd $LPCNETDIR && git switch master && git pull && git checkout $LPCNET_BRANCH
mkdir -p build_linux && cd build_linux && rm -Rf *
cmake ..
if [ $? == 0 ]; then
make
if [ $? == 0 ]; then
# sanity check test
cd src && sox ../../wav/wia.wav -t raw -r 16000 - | ./lpcnet_enc -s | ./lpcnet_dec -s > /dev/null
else
echo "Warning: LPCNet build failed, disabling"
LPCNET_DISABLE=1
fi
else
echo "Warning: LPCNet build failed, disabling"
LPCNET_DISABLE=1
fi
fi

if [ $LPCNET_DISABLE == 0 ]; then
LPCNET_CMAKE_CMD="-DLPCNET_BUILD_DIR=$LPCNETDIR/build_linux"
fi
cd $LPCNETDIR && git switch master && git pull && git checkout $LPCNET_BRANCH
mkdir -p build_linux && cd build_linux && rm -Rf *
cmake ..
make
# sanity check test
cd src && sox ../../wav/wia.wav -t raw -r 16000 - | ./lpcnet_enc -s | ./lpcnet_dec -s > /dev/null

# First build and install vanilla codec2 as we need -lcodec2 to build LPCNet
cd $FREEDVGUIDIR
if [ ! -d codec2 ]; then
git clone https://github.com/drowe67/codec2.git
fi
cd codec2 && git switch main && git pull && git checkout $CODEC2_BRANCH
mkdir -p build_linux && cd build_linux && rm -Rf * && cmake -DLPCNET_BUILD_DIR=$LPCNETDIR/build_linux .. && make VERBOSE=1
# sanity check test
cd src
export LD_LIBRARY_PATH=$LPCNETDIR/build_linux/src
./freedv_tx 2020 $LPCNETDIR/wav/wia.wav - | ./freedv_rx 2020 - /dev/null
mkdir -p build_linux && cd build_linux && rm -Rf * && cmake $LPCNET_CMAKE_CMD .. && make VERBOSE=1
if [ $LPCNET_DISABLE == 0 ]; then
# sanity check test
cd src
export LD_LIBRARY_PATH=$LPCNETDIR/build_linux/src
./freedv_tx 2020 $LPCNETDIR/wav/wia.wav - | ./freedv_rx 2020 - /dev/null
fi

# Finally, build freedv-gui
cd $FREEDVGUIDIR
Expand All @@ -59,5 +78,5 @@ if [[ "$FREEDV_VARIANT" == "pulseaudio" ]]; then
else
PULSEAUDIO_PARAM="-DUSE_PULSEAUDIO=0"
fi
cmake $PULSEAUDIO_PARAM -DUNITTEST=$UT_ENABLE -DCMAKE_BUILD_TYPE=Debug -DCODEC2_BUILD_DIR=$CODEC2DIR/build_linux -DLPCNET_BUILD_DIR=$LPCNETDIR/build_linux ..
cmake $PULSEAUDIO_PARAM -DUNITTEST=$UT_ENABLE -DCMAKE_BUILD_TYPE=Debug -DCODEC2_BUILD_DIR=$CODEC2DIR/build_linux $LPCNET_CMAKE_CMD ..
make VERBOSE=1
36 changes: 26 additions & 10 deletions build_osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export HAMLIBDIR=$FREEDVGUIDIR/hamlib
export CODEC2_BRANCH=1.2.0
export LPCNET_BRANCH=v0.5
export UT_ENABLE=${UT_ENABLE:-0}
LPCNET_DISABLE=${LPCNET_DISABLE:-0}

# Prerequisite: build dylibbundler
if [ ! -d macdylibbundler ]; then
Expand All @@ -32,24 +33,39 @@ make install

# OK, build and test LPCNet
cd $FREEDVGUIDIR
if [ ! -d LPCNet ]; then
git clone https://github.com/drowe67/LPCNet.git
if [ $LPCNET_DISABLE == 0 ]; then
if [ ! -d LPCNet ]; then
git clone https://github.com/drowe67/LPCNet.git
fi
cd $LPCNETDIR && git checkout master && git pull && git checkout $LPCNET_BRANCH
mkdir -p build_osx && cd build_osx && rm -Rf *
cmake -DBUILD_OSX_UNIVERSAL=1 ..
if [ $? == 0 ]; then
make -j4
if [ $? == 0 ]; then
# sanity check test
cd src && sox ../../wav/wia.wav -t raw -r 16000 - | ./lpcnet_enc -s | ./lpcnet_dec -s > /dev/null
else
echo "Warning: LPCNet build failed, disabling"
LPCNET_DISABLE=1
fi
else
echo "Warning: LPCNet build failed, disabling"
LPCNET_DISABLE=1
fi
fi
cd $LPCNETDIR && git checkout master && git pull && git checkout $LPCNET_BRANCH
mkdir -p build_osx && cd build_osx && rm -Rf *
cmake -DBUILD_OSX_UNIVERSAL=1 ..
make -j4

# sanity check test
cd src && sox ../../wav/wia.wav -t raw -r 16000 - | ./lpcnet_enc -s | ./lpcnet_dec -s > /dev/null
if [ $LPCNET_DISABLE == 0 ]; then
LPCNET_CMAKE_CMD="-DLPCNET_BUILD_DIR=$LPCNETDIR/build_linux"
fi

# Build codec2 with LPCNet and test FreeDV 2020 support
cd $FREEDVGUIDIR
if [ ! -d codec2 ]; then
git clone https://github.com/drowe67/codec2-new.git codec2
fi
cd codec2 && git switch main && git pull && git checkout $CODEC2_BRANCH
mkdir -p build_osx && cd build_osx && rm -Rf * && cmake -DLPCNET_BUILD_DIR=$LPCNETDIR/build_osx -DBUILD_OSX_UNIVERSAL=1 .. && make VERBOSE=1 -j4
mkdir -p build_osx && cd build_osx && rm -Rf * && cmake ${LPCNET_CMAKE_CMD} -DBUILD_OSX_UNIVERSAL=1 .. && make VERBOSE=1 -j4

# sanity check test
cd src
Expand All @@ -62,5 +78,5 @@ if [ -d .git ]; then
git pull
fi
mkdir -p build_osx && cd build_osx && rm -Rf *
cmake -DUNITTEST=1 -DBUILD_OSX_UNIVERSAL=1 -DUNITTEST=$UT_ENABLE -DCMAKE_BUILD_TYPE=Debug -DBOOTSTRAP_WXWIDGETS=1 -DUSE_STATIC_SPEEXDSP=1 -DUSE_STATIC_PORTAUDIO=1 -DUSE_STATIC_SAMPLERATE=1 -DUSE_STATIC_SNDFILE=1 -DHAMLIB_INCLUDE_DIR=${HAMLIBDIR}/include -DHAMLIB_LIBRARY=${HAMLIBDIR}/lib/libhamlib.dylib -DCODEC2_BUILD_DIR=$CODEC2DIR/build_osx -DLPCNET_BUILD_DIR=$LPCNETDIR/build_osx ..
cmake -DUNITTEST=1 -DBUILD_OSX_UNIVERSAL=1 -DUNITTEST=$UT_ENABLE -DCMAKE_BUILD_TYPE=Debug -DBOOTSTRAP_WXWIDGETS=1 -DUSE_STATIC_SPEEXDSP=1 -DUSE_STATIC_PORTAUDIO=1 -DUSE_STATIC_SAMPLERATE=1 -DUSE_STATIC_SNDFILE=1 -DHAMLIB_INCLUDE_DIR=${HAMLIBDIR}/include -DHAMLIB_LIBRARY=${HAMLIBDIR}/lib/libhamlib.dylib -DCODEC2_BUILD_DIR=$CODEC2DIR/build_osx ${LPCNET_CMAKE_CMD} ..
make VERBOSE=1 -j8
2 changes: 1 addition & 1 deletion build_signed_windows_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ for arch in x86_64 i686 aarch64; do
cd $BUILD_ARCH_DIR

# Kick off new build with the given architecture
cmake -DSIGN_WINDOWS_BINARIES=1 -DPKCS11_CERTIFICATE_FILE=$CERT_URL_FILE -DPKCS11_KEY_FILE=$KEY_URL_FILE -DINTERMEDIATE_CERT_FILE=$INTERMEDIATE_CERT_FILE -DCMAKE_TOOLCHAIN_FILE=$SCRIPT_DIR/cross-compile/freedv-mingw-llvm-$arch.cmake $SCRIPT_DIR
cmake -DBOOTSTRAP_LPCNET=1 -DSIGN_WINDOWS_BINARIES=1 -DPKCS11_CERTIFICATE_FILE=$CERT_URL_FILE -DPKCS11_KEY_FILE=$KEY_URL_FILE -DINTERMEDIATE_CERT_FILE=$INTERMEDIATE_CERT_FILE -DCMAKE_TOOLCHAIN_FILE=$SCRIPT_DIR/cross-compile/freedv-mingw-llvm-$arch.cmake $SCRIPT_DIR
make -j6 package
cp FreeDV-*.exe $WIN_BUILD_DIR
cd $WIN_BUILD_DIR
Expand Down
9 changes: 7 additions & 2 deletions cmake/BuildCodec2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ if(BUILD_OSX_UNIVERSAL)
endif(BUILD_OSX_UNIVERSAL)

# Bootstrap lpcnetfreedv library
include(cmake/BuildLPCNet.cmake)
if(BOOTSTRAP_LPCNET)
include(cmake/BuildLPCNet.cmake)
set(CODEC2_CMAKE_ARGS ${CODEC2_CMAKE_ARGS} -DLPCNET_BUILD_DIR=${CMAKE_BINARY_DIR}/LPCNet_build)
else(BOOTSTRAP_LPCNET)
add_definitions(-DLPCNET_DISABLED)
set(LPCNET_DISABLED YES)
endif(BOOTSTRAP_LPCNET)

# Build codec2 library with lpcnetfreedv
set(CODEC2_CMAKE_ARGS ${CODEC2_CMAKE_ARGS} -DLPCNET_BUILD_DIR=${CMAKE_BINARY_DIR}/LPCNet_build)
include(ExternalProject)
ExternalProject_Add(build_codec2
SOURCE_DIR codec2_src
Expand Down
10 changes: 8 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ else()
endif(APPLE)

# Link imported or build tree targets.
if(NOT LPCNET_DISABLED)
set(LPCNET_LIB_NAME lpcnetfreedv)
else(NOT LPCNET_DISABLED)
set(LPCNET_LIB_NAME )
endif(NOT LPCNET_DISABLED)

if(APPLE)
target_link_libraries(FreeDV fdv_audio fdv_audio_pipeline fdv_config fdv_gui_controls fdv_gui_dialogs fdv_gui_util fdv_os_wrapper fdv_rig_control fdv_reporting fdv_sox fdv_util lpcnetfreedv codec2)
target_link_libraries(FreeDV fdv_audio fdv_audio_pipeline fdv_config fdv_gui_controls fdv_gui_dialogs fdv_gui_util fdv_os_wrapper fdv_rig_control fdv_reporting fdv_sox fdv_util ${LPCNET_LIB_NAME} codec2)
else(APPLE)
target_link_libraries(freedv fdv_audio fdv_audio_pipeline fdv_config fdv_gui_controls fdv_gui_dialogs fdv_gui_util fdv_os_wrapper fdv_rig_control fdv_reporting fdv_sox fdv_util lpcnetfreedv codec2)
target_link_libraries(freedv fdv_audio fdv_audio_pipeline fdv_config fdv_gui_controls fdv_gui_dialogs fdv_gui_util fdv_os_wrapper fdv_rig_control fdv_reporting fdv_sox fdv_util ${LPCNET_LIB_NAME} codec2)
endif(APPLE)

# Add build dependencies for internally built external libraries.
Expand Down
13 changes: 10 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ void MainFrame::test2020Mode_()
{
printf("Making sure your machine can handle 2020 mode:\n");

bool allowed = test2020HWAllowed_();
bool allowed = false;

#if !defined(LPCNET_DISABLED)
allowed = test2020HWAllowed_();
wxGetApp().appConfiguration.freedvAVXSupported = allowed;

if (!allowed)
Expand Down Expand Up @@ -363,6 +366,7 @@ void MainFrame::test2020Mode_()

std::cout << "One second of 2020 decoded in " << timeTaken.count() << " ms" << std::endl;
}
#endif // !defined(LPCNET_DISABLED)

std::cout << "2020 allowed: " << allowed << std::endl;

Expand Down Expand Up @@ -859,7 +863,7 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent, wxID_ANY, _("FreeDV ")
}
#endif

#if defined(FREEDV_MODE_2020)
#if defined(FREEDV_MODE_2020) && !defined(LPCNET_DISABLED)
// First time use: make sure 2020 mode will actually work on this machine.
if (wxGetApp().appConfiguration.firstTimeUse)
{
Expand All @@ -869,7 +873,10 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent, wxID_ANY, _("FreeDV ")
{
wxGetApp().appConfiguration.freedvAVXSupported = test2020HWAllowed_();
}
#endif // defined(FREEDV_MODE_2020)
#else
// Disable LPCNet if not compiled in.
wxGetApp().appConfiguration.freedv2020Allowed = false;
#endif // defined(FREEDV_MODE_2020) && !defined(LPCNET_DISABLED)

if(!wxGetApp().appConfiguration.freedv2020Allowed || !wxGetApp().appConfiguration.freedvAVXSupported)
{
Expand Down
12 changes: 10 additions & 2 deletions src/ongui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <locale>

#include "main.h"
#if !defined(LPCNET_DISABLED)
#include "lpcnet_freedv.h"
#endif // defined(LPCNET_DISABLED)

#include "gui/dialogs/dlg_easy_setup.h"
#include "gui/dialogs/dlg_filter.h"
Expand Down Expand Up @@ -351,8 +353,14 @@ void MainFrame::OnHelpAbout(wxCommandEvent& event)
wxT("freedv-gui version: %s\n")
wxT("freedv-gui git hash: %s\n")
wxT("codec2 git hash: %s\n")
wxT("lpcnet git hash: %s\n"),
FREEDV_VERSION, FREEDV_VERSION, GIT_HASH, freedv_get_hash(), lpcnet_get_hash());
#if !defined(LPCNET_DISABLED)
wxT("lpcnet git hash: %s\n")
#endif // !defined(LPCNET_DISABLED)
, FREEDV_VERSION, FREEDV_VERSION, GIT_HASH, freedv_get_hash()
#if !defined(LPCNET_DISABLED)
, lpcnet_get_hash()
#endif // !defined(LPCNET_DISABLED)
);

wxMessageBox(msg, wxT("About"), wxOK | wxICON_INFORMATION, this);
}
Expand Down

0 comments on commit d8ee413

Please sign in to comment.