Skip to content

Commit

Permalink
Merge pull request #711 from drowe67/ms-disable-lpcnet
Browse files Browse the repository at this point in the history
Add CMake and code logic to allow compilation without LPCNet.
  • Loading branch information
tmiw committed Apr 13, 2024
2 parents fc6c4c8 + 9a9e95e commit d8ff7e8
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
export PATH=${{github.workspace}}/llvm-mingw-20230320-ucrt-ubuntu-18.04-x86_64/bin:$PATH
mkdir build_windows
cd build_windows
cmake -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/cross-compile/freedv-mingw-llvm-x86_64.cmake ..
cmake -DBOOTSTRAP_LPCNET=1 -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/cross-compile/freedv-mingw-llvm-x86_64.cmake ..
- name: Build freedv-gui
shell: bash
Expand Down
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ endif(APPLE)

# Adds a tag to the end of the version string. Leave empty
# for official release builds.
set(FREEDV_VERSION_TAG "devel")
set(FREEDV_VERSION_TAG "")

# Prevent in-source builds to protect automake/autoconf config.
# If an in-source build is attempted, you will still need to clean up a few
Expand Down Expand Up @@ -130,7 +130,9 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_VERBOSE_MAKEFILE TRUE CACHE BOOL "Verbose makefile.")
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE CACHE BOOL "Enable IDE features.")
set(USE_INTERNAL_CODEC2 FALSE CACHE BOOL
"Download and build codec2 and lpcnetfreedv instead of using the system library.")
"Download and build codec2 instead of using the system library.")
set(BOOTSTRAP_LPCNET FALSE CACHE BOOL
"Download and build LPCNet instead of using the system library.")
set(USE_STATIC_DEPS FALSE CACHE BOOL
"Download and build static libraries instead of system libraries.")
set(USE_STATIC_PORTAUDIO FALSE CACHE BOOL
Expand Down Expand Up @@ -254,7 +256,7 @@ if(MINGW)
# shared DLL doesn't work.
set(USE_STATIC_PORTAUDIO TRUE)
unset(USE_INTERNAL_CODEC2 CACHE)
set(USE_INTERNAL_CODEC2 TRUE CACHE BOOL "Perform nternal buils of codec2 and lpcnetfreedv")
set(USE_INTERNAL_CODEC2 TRUE CACHE BOOL "Perform internal builds of codec2")
# Setup HOST variables.
include(cmake/MinGW.cmake)
# This sets up the exe icon for windows under mingw.
Expand Down Expand Up @@ -349,7 +351,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
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,24 @@ This document describes how to build the FreeDV GUI program for various operatin
```
$ ./build_linux/src/freedv
```


## Building without LPCNet

In preparation for possible future deprecation of FreeDV 2020 and 2020B modes, it is
possible to build without requiring the [LPCNet](https://github.com/drowe67/LPCNet.git) library.
To do this, pass `LPCNET_DISABLE=1` as an environment variable to the build script, i.e.

```
$ LPCNET_DISABLE=1 ./build_linux.sh
```

or alternatively, do not pass in `LPCNET_BUILD_DIR` to `cmake` if manually executing the build.
This also has the side effect of disabling 2020 and 2020B in the user interface, preventing either
from being selected.

*Note: if you don't already have Codec2 installed on your machine, you will need to pass `-DBOOTSTRAP_LPCNET=1`
to `cmake` in order for LPCNet to also be built.*

## Installing on Linux

You need to install the codec2 and lpcnetfreedv shared libraries, and freedv-gui:
Expand Down
4 changes: 3 additions & 1 deletion USER_MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes

# Release Notes

## V1.9.9 TBD 2024
## V1.9.9 April 2024

1. Bugfixes:
* Cache PortAudio sound info to improve startup performance. (PR #689)
Expand All @@ -904,6 +904,8 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes
* Add context menu for copying messages to the clipboard. (PR #694)
3. Documentation:
* Remove broken links in README. (PR #709)
4. Build system:
* Add ability to build without LPCNet in preparation for potential future deprecation of 2020/2020B. (PR #711)

## V1.9.8 February 2024

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_osx"
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
11 changes: 9 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 All @@ -33,7 +38,9 @@ set_target_properties(codec2 PROPERTIES
IMPORTED_IMPLIB "${BINARY_DIR}/src/libcodec2${CMAKE_IMPORT_LIBRARY_SUFFIX}"
)

if(BOOTSTRAP_LPCNET)
add_dependencies(build_codec2 build_lpcnetfreedv)
endif(BOOTSTRAP_LPCNET)

set(CODEC2_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/codec2_src/src ${CMAKE_BINARY_DIR}/codec2_build)
include_directories(${CODEC2_INCLUDE_DIRS})
14 changes: 10 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,24 @@ 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.
if(USE_INTERNAL_CODEC2)
if(APPLE)
add_dependencies(FreeDV build_codec2 build_lpcnetfreedv)
add_dependencies(FreeDV build_codec2)
else(APPLE)
add_dependencies(freedv build_codec2 build_lpcnetfreedv)
add_dependencies(freedv build_codec2)
endif(APPLE)
endif()

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 d8ff7e8

Please sign in to comment.