Skip to content

Commit

Permalink
Merge branch 'main' into dr-embed
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Sep 30, 2024
2 parents f45b0e1 + 297c1ed commit 2810ace
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 2 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,34 @@ cmake ..
make
```

### Building on Windows

While most of RADAE is in Python, there is a `lpcnet_demo` application
that is required to be compiled. To do this for Windows, you can run
something like the following from a Linux machine:

```
wget https://github.com/mstorsjo/llvm-mingw/releases/download/20240619/llvm-mingw-20240619-ucrt-ubuntu-20.04-x86_64.tar.xz
tar xzf llvm-mingw-20240619-ucrt-ubuntu-20.04-x86_64.tar.xz
export PATH=`pwd`/llvm-mingw-20240619-ucrt-ubuntu-20.04-x86_64/bin:$PATH
export RADAE_PATH=`pwd`/radae
cd $RADAE_PATH
mkdir build_windows
cd build_windows
cmake -DCMAKE_TOOLCHAIN_FILE=$RADAE_PATH/cross-compile/mingw-llvm-x86_64.cmake ..
make
```

(Replace `x86_64` in `mingw-llvm-x86_64.cmake` with either `i686` or `aarch64` for 32-bit x86 or 64-bit ARM, respectively.)

Once done, `lpcnet_demo.exe` will be inside the `src` folder inside `build_windows`.

#### Limitations

* ctests are untested and likely do not work without additional changes.
* Visual Studio is not supported, only MinGW.
* Generating a Windows installer is currently not supported. `lpcnet_demo.exe` is intended to be included with other applications built with MinGW (such as freedv-gui).

# Automated Tests

The `cmake/ctest` framework is being used as a build and test framework. The command lines in `CmakeLists.txt` are a good source of examples, if you are interested in running the code in this repo. The ctests are a work in progress and may not pass on all systems (see Scope above).
Expand Down
12 changes: 10 additions & 2 deletions cmake/BuildOpus.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
message(STATUS "Will build opus with FARGAN")

set(CONFIGURE_COMMAND ./autogen.sh && ./configure --enable-dred --disable-shared)

if (CMAKE_CROSSCOMPILING)
set(CONFIGURE_COMMAND ${CONFIGURE_COMMAND} --host=${CMAKE_C_COMPILER_TARGET} --target=${CMAKE_C_COMPILER_TARGET})
endif (CMAKE_CROSSCOMPILING)

message(STATUS "${CONFIGURE_COMMAND}")

include(ExternalProject)
ExternalProject_Add(build_opus
URL https://gitlab.xiph.org/xiph/opus/-/archive/main/opus-main.tar.gz
DOWNLOAD_EXTRACT_TIMESTAMP NO
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ./autogen.sh && ./configure --enable-dred --disable-shared
CONFIGURE_COMMAND ${CONFIGURE_COMMAND}
BUILD_COMMAND $(MAKE)
INSTALL_COMMAND ""
)
Expand All @@ -17,7 +25,7 @@ add_dependencies(opus build_opus)

set_target_properties(opus PROPERTIES
IMPORTED_LOCATION "${BINARY_DIR}/.libs/libopus${CMAKE_STATIC_LIBRARY_SUFFIX}"
IMPORTED_IMPLIB "${BINARY_DIR}/.libs/libopus${CMAKE_IMPORT_LIBRARY_SUFFIX}"
IMPORTED_IMPLIB "${BINARY_DIR}/.libs/libopus${CMAKE_STATIC_LIBRARY_SUFFIX}"
)

include_directories(${SOURCE_DIR}/dnn ${SOURCE_DIR}/celt ${SOURCE_DIR}/include)
26 changes: 26 additions & 0 deletions cross-compile/mingw-llvm-aarch64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

set(triple ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32)

set(CMAKE_C_COMPILER ${triple}-clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER ${triple}-clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})
set(CMAKE_AR ${triple}-ar)
set(CMAKE_RANLIB ${triple}-ranlib)
set(CMAKE_RC_COMPILER ${triple}-windres)

set(CMAKE_C_FLAGS "-Wno-unused-command-line-argument -gcodeview")
set(CMAKE_CXX_FLAGS "-Wno-unused-command-line-argument -gcodeview")
set(CMAKE_EXE_LINKER_FLAGS -Wl,--pdb=)

# For make package use.
set(CMAKE_OBJDUMP ${triple}-objdump)
set(FREEDV_USING_LLVM_MINGW 1)

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
28 changes: 28 additions & 0 deletions cross-compile/mingw-llvm-i686.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR i686)

set(triple ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32)

set(CMAKE_C_COMPILER ${triple}-clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER ${triple}-clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})

set(CMAKE_AR ${triple}-ar)
set(CMAKE_RANLIB ${triple}-ranlib)
set(CMAKE_RC_COMPILER ${triple}-windres)

set(CMAKE_C_FLAGS "-Wno-unused-command-line-argument -gcodeview")
set(CMAKE_CXX_FLAGS "-Wno-unused-command-line-argument -gcodeview")
set(CMAKE_EXE_LINKER_FLAGS -Wl,--pdb=)

# For make package use.
set(CMAKE_OBJDUMP ${triple}-objdump)
set(FREEDV_USING_LLVM_MINGW 1)

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
28 changes: 28 additions & 0 deletions cross-compile/mingw-llvm-x86_64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

set(triple ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32)

set(CMAKE_C_COMPILER ${triple}-clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER ${triple}-clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})

set(CMAKE_AR ${triple}-ar)
set(CMAKE_RANLIB ${triple}-ranlib)
set(CMAKE_RC_COMPILER ${triple}-windres)

set(CMAKE_C_FLAGS "-Wno-unused-command-line-argument -gcodeview")
set(CMAKE_CXX_FLAGS "-Wno-unused-command-line-argument -gcodeview")
set(CMAKE_EXE_LINKER_FLAGS -Wl,--pdb=)

# For make package use.
set(CMAKE_OBJDUMP ${triple}-objdump)
set(FREEDV_USING_LLVM_MINGW 1)

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
20 changes: 20 additions & 0 deletions src/lpcnet_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
#include "fargan.h"
#include "cpu_support.h"

#ifdef _WIN32
// For _setmode().
#include <io.h>
#include <fcntl.h>
#endif // _WIN32

#ifdef USE_WEIGHTS_FILE
# if __unix__
# include <fcntl.h>
Expand Down Expand Up @@ -120,7 +126,14 @@ int main(int argc, char **argv) {
if (argc != 4) usage();

if (strcmp(argv[2], "-") == 0)
{
#ifdef _WIN32
// Note: freopen() returns NULL if filename is NULL, so
// we have to use setmode() to make it a binary stream instead.
_setmode(_fileno(stdin), O_BINARY);
#endif // _WIN32
fin = stdin;
}
else
fin = fopen(argv[2], "rb");
if (fin == NULL) {
Expand All @@ -129,7 +142,14 @@ int main(int argc, char **argv) {
}

if (strcmp(argv[3], "-") == 0)
{
#ifdef _WIN32
// Note: freopen() returns NULL if filename is NULL, so
// we have to use setmode() to make it a binary stream instead.
_setmode(_fileno(stdout), O_BINARY);
#endif // _WIN32
fout = stdout;
}
else
fout = fopen(argv[3], "wb");
if (fout == NULL) {
Expand Down

0 comments on commit 2810ace

Please sign in to comment.