Skip to content

Commit

Permalink
Cleanup crossplatform/compiler builds using CMakePresets.json
Browse files Browse the repository at this point in the history
  • Loading branch information
williamyang98 committed Feb 14, 2024
1 parent af0e0b3 commit cfb081a
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 123 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/x86-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

env:
BUILD_TYPE: Release
BUILD_DIR: build

jobs:
skip_check:
Expand Down Expand Up @@ -36,23 +37,19 @@ jobs:
submodules: recursive

- name: Update packages
shell: bash
run: sudo apt-get update

- name: Install packages
shell: bash
run: ./toolchains/ubuntu/install_packages.sh

- name: Configure CMake
shell: bash
run: ./toolchains/ubuntu/cmake_configure.sh
run: cmake . -B ${{env.BUILD_DIR}} --preset gcc -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
shell: bash
run: ninja -C build-ubuntu
run: cmake --build ${{env.BUILD_DIR}} --config ${{env.BUILD_TYPE}}

- name: Upload files (Release)
uses: actions/upload-artifact@v3
with:
name: dab_radio_linux_x64
path: ${{github.workspace}}/build-ubuntu
path: ${{github.workspace}}/${{env.BUILD_DIR}}
7 changes: 4 additions & 3 deletions .github/workflows/x86-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

env:
BUILD_TYPE: Release
BUILD_DIR: build
OSX_TARGET: "12.0"

jobs:
Expand Down Expand Up @@ -43,13 +44,13 @@ jobs:
run: brew bundle install --file=./toolchains/macos/Brewfile

- name: Configure CMake
run: cmake . -B ${{github.workspace}}/build-macos -DCMAKE_OSX_DEPLOYMENT_TARGET=${{env.OSX_TARGET}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -G Ninja
run: cmake . -B ${{env.BUILD_DIR}} --preset clang -DCMAKE_OSX_DEPLOYMENT_TARGET=${{env.OSX_TARGET}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
run: cmake --build ${{github.workspace}}/build-macos --config ${{env.BUILD_TYPE}}
run: cmake --build ${{env.BUILD_DIR}} --config ${{env.BUILD_TYPE}}

- name: Upload files (Release)
uses: actions/upload-artifact@v3
with:
name: dab_radio_macos_x64
path: ${{github.workspace}}/build-macos
path: ${{github.workspace}}/${{env.BUILD_DIR}}
17 changes: 11 additions & 6 deletions .github/workflows/x86-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:

env:
BUILD_TYPE: Release
BUILD_DIR: build
PACKAGE_DIR: dab_radio_windows_x64

jobs:
skip_check:
Expand Down Expand Up @@ -46,19 +48,22 @@ jobs:
path: vcpkg

- name: Configure CMake
shell: bash
run: VCPKG_ROOT=./vcpkg ./toolchains/windows/cmake_configure.sh
run: cmake . -B ${{env.BUILD_DIR}} --preset windows-msvc -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/vcpkg/scripts/buildsystems/vcpkg.cmake

- name: Build
shell: bash
run: ninja -C build-windows
run: cmake --build ${{env.BUILD_DIR}} --config ${{env.BUILD_TYPE}}

- name: Copy files
shell: bash
run: ./toolchains/windows/create_package.sh
run: |
mkdir -p ${{env.PACKAGE_DIR}}
cp ${{env.BUILD_DIR}}/examples/*.exe ${{env.PACKAGE_DIR}}/
cp ${{env.BUILD_DIR}}/examples/*.dll ${{env.PACKAGE_DIR}}/
cp -rf res/ ${{env.PACKAGE_DIR}}/
cp README.md ${{env.PACKAGE_DIR}}/
- name: Upload files
uses: actions/upload-artifact@v3
with:
name: dab_radio_windows_x64
path: ${{github.workspace}}/dab_radio_windows_x64
path: ${{github.workspace}}/${{env.PACKAGE_DIR}}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ imgui.ini
logs.txt
dab_radio_windows_x64/
dab_radio_windows_x64.zip
.cache/
.cache/
CMakeUserPresets.json
36 changes: 7 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.10)
project(ofdm_demod)

# NOTE: Root cmake file is used to setup all project dependencies
project(dab_radio)

# Setup all subprojects' dependencies
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(faad2 REQUIRED)
find_package(easyloggingpp REQUIRED)
Expand All @@ -16,6 +15,7 @@ find_package(viterbi CONFIG REQUIRED)
set(ARGPARSE_INSTALL OFF CACHE BOOL "Include an install target" FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vendor/argparse)

# use prebuilt binaries for windows otherwise pkgconfig
if(WIN32)
set(rtlsdr_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/librtlsdr)
find_package(rtlsdr CONFIG REQUIRED)
Expand All @@ -26,6 +26,7 @@ else()
set(RTLSDR_LIBS PkgConfig::rtlsdr)
endif()

# use vcpkg for windows otherwise pkgconfig
if(WIN32)
find_package(portaudio CONFIG REQUIRED)
find_package(FFTW3f CONFIG REQUIRED)
Expand All @@ -39,41 +40,18 @@ else()
set(FFTW3_LIBS PkgConfig::fftw3f)
endif()

target_compile_definitions(easyloggingpp PRIVATE ELPP_THREAD_SAFE)

# for posix threads
if(NOT WIN32)
find_package(Threads REQUIRED)
add_compile_options(-pthread)
link_libraries(Threads::Threads)
endif()

# simd and math compile options
if(NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
if(MSVC)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
add_compile_definitions(_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING)
# for msvc multi processor compilation
add_compile_options(/MP)
# NOTE: The MSVC compiler assumes a conservative microarchitecture and optimises using SSE2 by default
# Since this is a performance sensitive application, we want to be aggressive with SIMD optimisations
add_compile_options(/fp:fast /arch:AVX2)
# add_compile_options(/fp:fast /arch:AVX)
# add_compile_options(/fp:fast)
# add_compile_options(/fsanitize=address)
# add_compile_definitions(_DISABLE_VECTOR_ANNOTATION)
# add_compile_definitions(_DISABLE_STRING_ANNOTATION)
else()
# NOTE: We are optimising specifically for your CPU's microarchitecture
# This is okay since we don't ship prebuilt binaries for linux distributions
add_compile_options(-march=native -ffast-math)
endif()
else()
add_compile_options(-ffast-math)
endif()

# setup easyloggingpp
target_compile_definitions(easyloggingpp PRIVATE ELPP_THREAD_SAFE)
set(DAB_CORE_USE_EASYLOGGING ON CACHE BOOL "Use easylogging for dab_core" FORCE)
set(BASIC_RADIO_USE_EASYLOGGING ON CACHE BOOL "Use easylogging for basic_radio" FORCE)
set(BASIC_SCRAPER_USE_EASYLOGGING ON CACHE BOOL "Use easylogging for basic_scraper" FORCE)

add_subdirectory(${CMAKE_SOURCE_DIR}/src)
add_subdirectory(${CMAKE_SOURCE_DIR}/examples)
56 changes: 56 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "windows-msvc",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_CXX_FLAGS_INIT": "/MP /fp:fast /arch:AVX2 /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING",
"CMAKE_C_FLAGS_INIT": "/MP /fp:fast /arch:AVX2 /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING"
}
},
{
"name": "windows-msvc-sanitize",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_CXX_FLAGS_INIT": "/MP /fp:fast /arch:AVX2 /fsanitize=address /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING /D_DISABLE_VECTOR_ANNOTATION /D_DISABLE_STRING_ANNOTATION",
"CMAKE_C_FLAGS_INIT": "/MP /fp:fast /arch:AVX2 /fsanitize=address /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING /D_DISABLE_VECTOR_ANNOTATION /D_DISABLE_STRING_ANNOTATION"
}
},
{
"name": "gcc",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_CXX_FLAGS_INIT": "-ffast-math -march=native",
"CMAKE_C_FLAGS_INIT": "-ffast-math -march=native"
}
},
{
"name": "clang",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_CXX_FLAGS_INIT": "-ffast-math -march=native",
"CMAKE_C_FLAGS_INIT": "-ffast-math -march=native"
}
},
{
"name": "clang-arm",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_CXX_FLAGS_INIT": "-ffast-math",
"CMAKE_C_FLAGS_INIT": "-ffast-math"
}
}
]
}
39 changes: 9 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,55 +27,34 @@ For those who are interested only in parts of the implementation refer to the fo
![OFDM Demodulator GUI](docs/gallery/ofdm_demodulator_gui.png)
![Simple Radio GUI](docs/gallery/simple_radio_gui.png)

# Download and run
# Download and run (Windows)
1. Download the ZIP archive from the releases page.
2. Setup rtlsdr radio drivers according to [here](https://www.rtl-sdr.com/rtl-sdr-quick-start-guide/)
3. Plug in your RTLSDR Blog v3 dongle
4. Run ```./radio_app.exe```
5. Go to the "Simple View" tab and select a service from the list.
6. Click "Run All" to listen to the channel and receive slideshows.

[Wohnort](http://www.wohnort.org/dab/) has an excellent website for viewing the list of DAB ensembles across the work. In Australia where I am, the blocks being used in Sydney are ```[9A,9B,9C]```.
- Refer to [Wohnort](http://www.wohnort.org/dab/) for DAB ensembles in your region.
- Read ```examples/README.md``` to use other applications.

Refer to ```src/examples/README.md``` for other example applications.

If you can't find any DAB ensembles in your area, then you can download binary files from the Releases page [here](https://github.com/williamyang98/DAB-Radio/releases/tag/raw-iq-data). These contain raw IQ values as well as pre-demodulated OFDM digital frames. You can read in these files with the applications described in <code>src/examples/README.md</code>
If you can't find any DAB ensembles in your area, then you can download binary files from the Releases page [here](https://github.com/williamyang98/DAB-Radio/releases/tag/raw-iq-data). These contain raw IQ values as well as pre-demodulated OFDM digital frames. You can read in these files with the applications described in ```examples/README.md```

# Building programs
Clone the repository using the command

```git clone https://github.com/williamyang98/DAB-Radio.git --recurse-submodules -j8```

Refer to ```./toolchains/*/README.md``` to build for your platform.

Dependencies are (refer to <code>vcpkg.json</code> or <code>toolchains/*/install_packages.sh</code>):
- glfw3
- opengl
- portaudio
- fftw3

The continuous integration (CI) scripts are in <code>.github/workflows</code> if you want to replicate the build on your system.

## Build notes (Read this if you get illegal instructions)
SIMD instructions are used for x86 and ARM cpus to speed up computation heavy code paths.

Refer to [this github issue](https://github.com/williamyang98/DAB-Radio/issues/2#issuecomment-1627787907) explaining how to modify the build for **older CPUs**.

```./toolchains/windows/README.md``` has steps for configuring the right files to build for older CPUs.
- Refer to ```toolchains/*/README.md``` to build for your platform.
- The continuous integration (CI) scripts are in ```.github/workflows``` if you want to replicate the build on your system.
- SIMD instructions are used for x86 and ARM cpus to speed up math heavy code paths. Modify ```CMakePresets.json``` to use correct compiler flags.

# Similar apps
- The welle.io open source radio has an excellent implementation of DAB radio. Their implementation is much more featureful and optimised than mine. Their repository can be found [here](https://github.com/albrechtl/welle.io). They also have a youtube video showcasing their wonderful software [here](https://www.youtube.com/watch?v=IJcgdmud-AI).

- The welle.io open source radio has an excellent implementation of DAB radio. Their repository can be found [here](https://github.com/albrechtl/welle.io). [Youtube Link](https://www.youtube.com/watch?v=IJcgdmud-AI).
- There is a large community of rtl-sdr projects which can be found at [rtl-sdr.com](https://www.rtl-sdr.com/tag/dab/). This link points to a webpage showcasing several open source community projects that aim to decode DAB signals.

# Important sources
- [ETSI](https://www.etsi.org/standards) the non-for-profit standardisation organisation for making all of the standards free to access and view. Without their detailed documentation and specifications it would not be possible to build a rtl-sdr DAB radio.
- [Phil Karn](https://github.com/ka9q) for his Reed Solomon and Viterbi decoding algorithms which can be found [here](https://github.com/ka9q/libfec)
- [tcbrindle](https://github.com/tcbrindle) for his C++ single header template library implementation of std::span which can be found [here](https://github.com/tcbrindle/span)
- [reyoung/avx_mathfun](https://github.com/reyoung/avx_mathfun) for their AVX/AVX2 implementations of _mm512_cos_pd
- [RJVB/sse_mathfun](https://github.com/RJVB/sse_mathfun) for their SSE2 implementations of _mm_cos_pd

# TODO
- For DAB+ determine how to perform error correction on the firecode CRC16 in the AAC super frame.
- Decode MPEG-II audio for DAB channels.
- For DAB+ determine how to perform error correction on the firecode CRC16 in the AAC super frame.
- Add TII (transmitter identificaton information) decoding
10 changes: 5 additions & 5 deletions toolchains/macos/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Instructions
1. brew update
2. brew bundle install --file=./toolchains/macos/Brewfile
3. cmake . -B build-macos -DCMAKE_BUILD_TYPE=Release -G Ninja
4. cmake --build build-macos --config Release
5. ./build-macos/examples/radio_app
1. Update brew: ```brew update```
2. Install dependencies: ```brew bundle install --file=./toolchains/macos/Brewfile```
3. Configure cmake: ```cmake . -B build --preset clang -DCMAKE_BUILD_TYPE=Release```
4. Build: ```cmake --build build --config Release```
5. Run: ```./build/examples/radio_app```
10 changes: 5 additions & 5 deletions toolchains/ubuntu/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Instructions
1. <code>./toolchains/ubuntu/install_packages.sh</code>
2. <code>./toolchains/ubuntu/cmake_configure.sh</code>
3. <code>ninja -C build-ubuntu</code>
4. <code>./build-ubuntu/\<program\></code>
# Instructions
1. Install dependencies: ```./toolchains/ubuntu/install_packages.sh```
2. Configure cmake: ```cmake . -B build --preset gcc -DCMAKE_BUILD_TYPE=Release```
3. Build: ```cmake --build build --config Release```
4. Run: ```./build/examples/radio_app```
2 changes: 0 additions & 2 deletions toolchains/ubuntu/cmake_configure.sh

This file was deleted.

2 changes: 0 additions & 2 deletions toolchains/ubuntu/linux-gnu-toolchain.cmake

This file was deleted.

30 changes: 18 additions & 12 deletions toolchains/windows/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
## Instructions
1. ```./toolchains/windows/cmake_configure.sh```
2. ```ninja -C build-windows```
3. ```./build-windows/\<program\>```
1. Install vcpkg and integrate install. Refer to instructions [here](https://github.com/microsoft/vcpkg#quick-start-windows)
2. Setup x64 developer environment for C++ for MSVC.
2. Configure cmake: ```cmake . -B build --preset windows-msvc -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=C:\tools\vcpkg\scripts\buildsystems\vcpkg.cmake```
- Change ```-DCMAKE_TOOLCHAIN_FILE``` to point to your vcpkg installation directory.
3. Build: ```cmake --build build --config Release```
4. Run: ```.\build\examples\*.exe```

## Compiling with clang-cl
Compiling with clang gives better performing binaries compared to MSVC cl.

1. Setup x64 developer environment for C++ for MSVC.
2. Make sure clang for C++ is installed through Visual Studio.
3. Enter a bash shell.
4. ```CC=clang CXX=clang++ ./toolchains/windows/cmake_configure.sh```
Compiling with clang gives better performing binaries compared to MSVC.
1. Make sure clang for C++ is installed through Visual Studio.
2. Configure cmake: ```cmake . -B build --preset clang -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=C:\tools\vcpkg\scripts\buildsystems\vcpkg.cmake```

## Compiling with different SIMD flags
The default windows build compiles with AVX2 instructions. If your CPU doesn't support these then you will have to modify the scripts.
The default windows build compiles with AVX2 instructions. If your CPU doesn't support these then you will have to modify the scripts.

```vcpkg.json``` contains ```fftw3f``` which uses the ```avx2``` feature. Change this to ```[avx, sse2, sse]```.
Modify ```CMakePresets.json``` so that configurePresets ```windows-msvc``` uses correct flags. [Link to docs](https://learn.microsoft.com/en-us/cpp/build/reference/arch-x64?view=msvc-170)
- ```/arch:AVX2```
- ```/arch:AVX```
- Remove the ```/arch:XXX``` flag entirely for SSE2 builds

```CMakeLists.txt``` contains ```/arch:AVX2```. Change this to ```/arch:AVX``` or remove this compiler option.
*(Optional)* FFTW3 is built by default with AVX2 instructions. Modify ```vcpkg.json``` so fftw3 uses the correct "features" for your CPU. This might not be necessary since it uses ```cpu_features``` to determine and dispatch calls at runtime.
- ```"features": ["avx"]```
- ```"features": ["sse2"]```
- ```"features": ["sse"]```
21 changes: 0 additions & 21 deletions toolchains/windows/cmake_configure.sh

This file was deleted.

0 comments on commit cfb081a

Please sign in to comment.